Using PID to follow a wall
Driving along a wall using the PID algorithm requires a little more coordination. Let’s visualize the problem with a diagram:
Figure 10.12 – The robot following a wall
Figure 10.12 shows how our robot will follow a wall. First, the robot drives forward in the direction shown by the solid line with an arrow. We have turned the sensor out so that it can detect the wall in its cone (these distance sensors cover around 20 degrees). Based on the return of a close object (shown as a dashed line), the robot will adjust its heading to try and keep a constant distance. When the robot faces the wall, it will curve outward, and it may overshoot, but also, there is a step change in the wall, so the robot will adjust its path and straighten up.
We have a few issues. First, we have put the motors a little forward, and turning the sensor with the current placement would have the wheel in the path of the sensor, so we’ll need...