Activity 3.1.3 Basic Inputs Programming - VEX Clawbot Introduction Inputs are devices which provide a processor with environmental information to make decisions. These devices have the capacity to sense the environment in a variety of ways such as physical touch, rotation, and light. An engineer can design a system to respond to its environment through the use of input sensors. In this activity you will use ROBOTC and VEX robotics platform components to sense the environment. Equipment Procedure Computer with ROBOTC software POE Clawbot POE Clawbot ROBOTC template Part 1 - Bump Switch 1. Connect the POE Clawbot Cortex to the PC with the USB cable. Open your POE Clawbot ROBOTC template. Click File, Save As, select the folder that your teacher designated for you to save your ROBOTC programs in, then name the file A3.1.3_Part1. 2. In this activity you will use and program many of the Clawbot's inputs and outputs. For the next part, support your Clawbot on a box so that the wheels are not in contact with the table top. 3. Copy and paste or create the program below in the task main() section of the program between the curly braces. untilbump(bumpswitch); startmotor(rightmotor, 67); wait(5); 4. Power on the Cortex. 5. Compile and download the program. If you have any errors, check with your instructor to troubleshoot your program. 6. Press Start to run the program and observe the behaviors. 7. Document what this program would look like as pseudocode simple behaviors in the psuedocode section of the program. 8. Save the program to your saved files location. Bump Switch
Part 2 - Bump Switch II 9. Create a copy of your program file from above, then rename the it A3.1.3_Part2. 10. The wiring configuration, motors &sensors tabs should remain the same as before. 11. Write a program that performs the following simple behaviors. Use the natural language functions where appropriate as shown below. Add comments at the end of each command line to explain the purpose of each step. a. Wait for the bumper switch to be bumped. Note that bump means that a switch is pressed and released and not simply pressed and held. b. Both motors turn on at half power until the sensor is bumped again. c. Both motors should then move in reverse at half power for 3.5 seconds. d. Both motors will stop. Natural LanguageMovement Natural Language Special Natural LanguageUntil Natural LanguageWait 12. Test the program and troubleshoot if needed until the expected behavior has occurred.
Part 3 - Quadrature Encoders 13. Open the POE Clawbot ROBOTC template. Click File, Save As, select the folder that your teacher designated, then name the file A3.1.3_Part3. 14. The wiring configuration and motors and sensors tabs should be the same as in previous activities. 15. Copy and paste or create the program below in the task main() section of the program between the curly braces. startmotor(leftmotor, 63); startmotor(rightmotor, 63); untilencodercounts(480,leftencoder); untilencodercounts(480,rightencoder); stopmotor(leftmotor); 16. Download and run the program. Observe the behaviors and document what this program would look like as pseudocode simple behaviors in the pseudocode section of the programming file. 17. Modify your program to perform the pseudocode below. a. Turn on both motors 1/2 speed forward until the encoder has counted 480 degrees b. Stop both motors c. Wait 2 seconds d. Turn on both motors in reverse at 1/2 speed until another 3.5 rotations of the encoder have passed e. Turn off both motors Quad/Optical Encoder 18. Test the program and troubleshoot until the expected behavior has occurred. Save the program file. Part 4 - Line Followers 1. Open the POE Clawbot ROBOTC template. Click File, Save As, select the folder that your teacher designated, then name the file A3.1.3_Part4. 2. The wiring configuration and motors and sensors tabs should be the same as above. 3. Set the line follower threshold. Thresholds allow your robot to make decisions via Boolean Comparisons a. Calculate an appropriate Threshold with the aid of the Sensor Debug Window (see next page). Line Followers
b. Open the Sensor Debugger Window c. Verify that the Program Debug Window s Refresh Rate reads "Continuous". d. Place a white object (e.g., paper) within ¼ and 1/8 in. in front of the line follower sensors. Record the value for the sensors displayed in the Sensors Debug Window. Make sure that there is enough light to illuminate the white object or the sensors will register darkness. e. Place a dark object within ¼ and 1/8 in. in front of the line follower sensors. Record the value for the sensors displayed in the Sensors Debug Window. f. Add the two values and divide by 2. The result is the threshold for the sensors. 4. Copy and paste or create the program below in the task main() section of the program between the curly braces. Substitute your threshold number for "1000". wait1msec(2000); // The program waits for 2000 milliseconds before continuing. int threshold = 1000; /* found by taking a reading on both DARK and LIGHT */ /* surfaces, adding them together, then dividing by 2. */ while(true) // RIGHT sensor sees dark: if(sensorvalue(rightlinefollower) > threshold) // counter-steer right: motor[leftmotor] = 63; motor[rightmotor] = 0; // CENTER sensor sees dark: if(sensorvalue(centerlinefollower) > threshold) // go straight motor[leftmotor] = 63; motor[rightmotor] = 63; // LEFT sensor sees dark: if(sensorvalue(leftlinefollower) > threshold) // counter-steer left: motor[leftmotor] = 0; motor[rightmotor] = 63; 5. Test the program and troubleshoot until the expected behavior has occurred. Save the program file to your folder.
Part 5 - Ultrasonic (Sonar) Sensor 6. Open the POE Clawbot ROBOTC template. Click File, Save As, select the folder that your teacher designated, then name the file A3.1.3_Part5. 7. The wiring configuration and motors and sensors tabs should be the same as above. Ultrasonic (Sonar) Sensor 8. Copy and paste or create the program below in the task main() section of the program between the curly braces. startmotor(leftmotor, 63); startmotor(rightmotor, 63); untilsonarlessthan(20, sonar); stopmotor(leftmotor); turnledon(green); wait(6.25); turnledoff(green); 9. Download and run the program. Observe the behaviors and document what this program would look like as pseudocode simple behaviors in the pseudocode section of your program file. 10. Modify your program to perform the pseudocode below. a. Wait until an object is detected within 20 cm to turn both motors on. b. Wait for the object to move more than 25 cm away before turning the motors off. 11. Test the program and troubleshoot until the expected behavior has occurred. Save the program file. Conclusion 1. Describe any challenges that you encountered while developing the programs. 2. Describe three applications for the use of sensors below that you worked with in this activity. Bump Switch: Quad Encoder: Sonar: