Distance controller
In this section, we will program the robot to gradually come to a stop using a proportional algorithm. In Chapter 4, Sensors and Control, we wrote a program where the robot would stop a set distance from a barrier using feedback from the distance sensors. These programs used a discrete reading where the robot would run at full speed until the sensor feedback triggered the robot to abruptly stop. In a proportional algorithm, the robot will gradually slow down as it approaches the desired stopping point.
Before we begin, we need to attach a distance sensor to our robot. If you have the Home Edition, you will be using the IR sensor, whereas if you have the Educational Edition, you will use the Ultrasonic Sensor. Because these sensors use reflected beams (infrared light or sound), they need to be placed unobstructed by the other parts of the robot. You could either place the sensor high above the robot or well out in front of many parts of the robot.
The design I have shown...