wget http://osoyoo.com/driver/picar/picar-obstacle-avoid.py
The PiBot will first rotate the Ultrasonic Distance Sensor to the front for 3 seconds. If the sensor does not face the front of the PiBot during these three seconds then hold down the control + C keys to end the program. Then remove the M2x4mm screw that holds the Ultrasonic Distance Sensor to the Micro Servo Motor and re-position it so that it faces the front of the PiBot. Then reinstall the M2x4mm screw to hold the Ultrasonic Distance Sensor to the Micro Servo Motor, type the command again and press enter.
python3 picar-obstacle-avoid.py
If you don't remember what a variable is, review the description from Lesson 1
These variables set the PWM output that tells the micro servo motor what direction to point. If the ultrasonic distance sensor doesn't point straight ahead and you can't get it to point straight ahead by adjusting it, you can fine-tune where it points by changing these values. If you change the servo_ctr value, be sure to change the other two values so that there is the same difference between them and the servo_ctr value.
If you don't remember what the while statements do, review Lesson 2 for a refresher.
The datasheet for sensors on the robot tell you how to interface with them and get the data you need. If no one else has written software to use the sensor, you can always write your own using the datasheet to know what to do.
See the Electrical Description section on the previous page for a description of how the sensor works
The datasheet has a minimum amount of time required between measurements. Make sure that there will be enough time after your changes so that the measurements don't get messed up.
Stopping the PiBot while taking measurements ensures that it has enough time to make a decision which direction to go. When you make it drive continuously, you need to ensure that it can take the measurements and make a decision before it moves far enough to run into something.
python3 picar-obstacle-avoid.py
sudo shutdown -h now