Program ultrasonic range sensor in autonomous mode Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode Program ultrasonic range sensor in autonomous mode Performance Objective: Given the components of a VEX robotics design system program an ultrasonic range sensor in autonomous mode to have the robot travel forward until it is 12 inches from the wall. Enabling Objectives: explain the purpose of an ultrasonic range sensor explain how an ultrasonic range sensor operates draw a flow chart for using an ultrasonic range sensor program an ultrasonic range sensor Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode Ultrasonic range sensor An ultrasonic range sensor enables a robot to detect obstacles in its path by utilizing the propagation of high-frequency sound waves The sensor emits a sound wave, which bounces off a reflective surface and returns to the sensor Then, using the amount of time it takes for the wave to return to the sensor, the distance to the object can be computed The distance is returned as a distance in inches Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode Sound waves The beam pattern coming from the ultrasonic sensor looks like the images to the right Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode Sound waves The sensitivity of the sensor depends on the objects’ surfaces that are detected by the emitted sound waves For example, a reflective surface may produce a different reading than a nonreflective surface Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode Verifying the sensor Plug the sensor into two digital ports Vex Ultrasonic Sensors are labeled with reference to the sensor, so the input cable coming from the sensor should be connected as a digital output on the robot controller Open easyC and download the Ultrasonic test file Move the robot and notice the change in value of the sensor Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode Program the ultrasonic ranger sensor The Start command tells the ultrasonic sensor to start recording sound waves The Get command allows you to store the feedback from the sensor into a variable The Stop command tells the ultrasonic sensor to stop recording Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode Program the ultrasonic ranger sensor Program a VEX robot equipped with an ultrasonic range sensor to move forward until the robot is 12 inches from a wall Draw the flow chart of a program that can complete the above task Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode Program the ultrasonic ranger sensor Open a new competition project and configure the microcontroller for the ultrasonic ranger finder Add a variable for the ultrasonic range sensor Insert an appropriate driving mode block into the operator tab Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode Program the ultrasonic ranger sensor Insert a block to start the ultrasonic range sensor Insert a block to get the ultrasonic variable value NOTE: The wire from the sensor labeled output is the interrupt port in the program, and the wire labeled input on the sensor is the output port in the program Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode Program the ultrasonic ranger sensor Insert a while loop to run while the ultrasonic sensor is greater than 16 In the while loop get the ultrasonic variable value again Insert the appropriate motor blocks to make the robot move forward NOTE: Because of processing speed in the microcontroller, you must add four inches to the distance you want the robot to stop when the motors are running at full speed (to stop the robot at 12 inches, the sensor must read until 16 inches) Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode Program the ultrasonic ranger sensor After the while loop insert blocks to stop the motors, if you do not stop the motors they will continue to run even if the sensor is no longer greater than the value in the if statement Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode Test time Download your code and test it to see if the robot stops 12 inches from the wall If it does, show your instructor! If the robot does not stop correctly, go back through the lesson and double check your code For more technical information on the ultrasonic range sensor visit: http://www.vexforum.com/wiki/index.php/Ultrasonic _Range_Finder Available at: www.etcurr.com Lesson 3.4 – Program Ultrasonic Range Sensor in Autonomous Mode