Rescuer Learn 3: Following a Wall

5. Correcting for “Drift”

If your robot is drifting away from the box you can make a minor adjustment to the code to correct for this and ensure that it continues to run parallel to the box.

There is a template notebook function called align_with_left_wall() . To use it, add the code highlighted below in the image in bold red font to the Main Code cell just below the while left_values[-1] < large_distance_cm:line.

The code is provided here for readability.


Pay attention to proper indentation (either 4 spaces or 1 tab, don't mix them)

For the curious among you, the align_with_left_wall() function uses trigonometry to correct the angle of orientation of the robot. Correction angles are based on the change in distance to the left wall between the last two sample measurements and the straight line distance the robot is known to have travelled between these two sample points (sampling_distance_cm).