../vl53l4cd-positioning

Positioning a Mouse with Trigonometry

I've been trying to figure out what logic I need to determine the pose of my robot entirely from its distance sensors. Using the power of CAD, I was able to figure out what variables I knew and what I needed to solve for. Because the beams always shot out from the same place, I always know where they intersect. Fusion360 tells me that the forward-facing beam travels 25.00 mm before intersecting with the 45° beam that traveled 24.04 mm.

I've labeled the sides a, b, and c. Then the angles are α, β, and γ.

screenshot showing line of sight of two ToF sensors labeling angles and sides

I can find c from knowing a, b and γ: c = \sqrt{a^2 + b^2 − 2ab \cos⁡(γ)} I optimized this from knowing that \gamma is always 45° so \cos(γ) will always be \frac{\sqrt{2}}{2}. Therefore, I can simplify - 2ab\cos(\gamma) with a compile-time constant into -ab*core::f32::SQRT_2. This should definitely save several CPU cycles.

c can then be substituted into this equation to get \alpha: α = \cos^{-1}(\frac{b^2+c^2−a^2}{2bc}) Then, if I wanted β, the angles add up to 180: β + α + γ = 180°

BTW: my actual script does everything in radians, but it is definitely easier to visualize things with angles in degrees.

Next steps: create logic for mapping straightaways and diagonals. Maybe even creating a serial program to watch the map it creates.