Ultrasonic Rangefinder Forward till Near - ROBOTC.net
Ultrasonic Rangefinder Forward till Near - ROBOTC.net
Ultrasonic Rangefinder Forward till Near - ROBOTC.net
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Sensing<br />
<strong>Ultrasonic</strong> <strong>Rangefinder</strong> <strong>Forward</strong> <strong>till</strong> <strong>Near</strong> (cont.)<br />
<strong>Ultrasonic</strong> <strong>Rangefinder</strong> values above the threshold of 3 inches made the program continue<br />
looping and moving forward. Values below the threshold caused the robot to stop. The threshold<br />
sets the point at which the robot’s behavior will change, because it marks the point at which the<br />
(condition) in the while loop (or if-statement) will change from true to false, or false to true, and<br />
thus change which lines of code will run.<br />
26<br />
27<br />
28<br />
29<br />
30<br />
31<br />
32<br />
SensorValue[rightEncoder] = 0;<br />
while(SensorValue[sonarSensor] > 3)<br />
{<br />
moveStraight();<br />
}<br />
}<br />
The robot is now set and ready to run for any object the <strong>Ultrasonic</strong> <strong>Rangefinder</strong> might see…<br />
but what happens when it doesn’t see anything at all? The sound waves have a limited range<br />
before the echo is too soft for the sensor to pick up. In addition, some materials or surfaces can<br />
actually deflect the sound waves away from the sensor, preventing it from hearing the echo.<br />
What happens then?<br />
11. Making sure that your robot is turned on and plugged in, open the <strong>ROBOTC</strong><br />
Debugger and Devices windows. Run the program.<br />
© Carnegie Mellon Robotics Academy / For use with VEX ® Robotics Systems<br />
11a. Robot > Debugger<br />
Go to Robot > Debugger to open<br />
the Program Debug window.<br />
11b. Robot > Debug Windows > Devices<br />
Open the Devices window so that you can<br />
monitor the <strong>Ultrasonic</strong> <strong>Rangefinder</strong> values.<br />
<strong>ROBOTC</strong><br />
<strong>Ultrasonic</strong> <strong>Rangefinder</strong> • 12