Programming – Using a Range Finder Intro to Robotics
Ultrasonic Rangefinder The Ultrasonic Rangefinder measures distances using sound. It sends out a pulse of sound, then waits to hear the sound’s echo off of a solid object in the environment. By measuring how long it takes for the sound to bounce back, the sensor can calculate the distance that the sound must have traveled, and hence, how far away the object was that reflected it back.
Ultrasonic Rangefinder The Ultrasonic Rangefinder will work in a very similar way to the Encoder program you wrote in the previous section, but instead of measuring the distance that the wheel has turned, it will use the Ultrasonic Rangefinder to measure the distance to the nearest object in front of the arm. Add an Ultrasonic Rangefinder to the front of the robot’s arm. The design shown below will be used as the reference for the remainder of the unit.
Create a New Program
Range Finder Setup
Range Finder Setup
Range Finder Code
Modifying the WHILE loop
Test the code
Setup the encoders
Save your program as SONAR CODE Save your program as SONAR CODE. COPY and PASTE your Movestraight () function and place it at the beginning of your code. Save.
Cut-off Values
Thresholds
Thresholds The threshold sets the point at which the robot’s behavior will change, because it marks the point at which the (condition) in the while loop (or if-statement) will change from true to false, or false to true, and thus change which lines of code will run. The robot is now set and ready to run for any object the Ultrasonic Rangefinder might see… but what happens when it doesn’t see anything at all?
Using the Debugger
Using the Debugger
Using the Debugger
Testing the sonar reading
Using the program
Using the program