In this lesson, you will learn how to program a waitUntil command with conditions that use the Bumper Switch sensors. Follow the instructions below and then build on these skills in the "Try It" activities!
waitUntil Command
1. Open the “waitUntil1” project you started on the Robot Configuration page.
2. Write the following code in your project:
1
2
3
4
5
6
7
intmain(){// Initializing Robot Configuration. DO NOT REMOVE!vexcodeInit();waitUntil(rearBumper.pressing());
Drivetrain.driveFor(forward,500, mm,25, velocityUnits::pct);}
The waitUntil() command is used to keep the robot running at this spot until the code in parentheses is evaluated as true.
Attached to the waitUntil command is a condition (the code inside the parenthesis). Conditions are statements made for the robot to evaluate something as either true or false. The .pressing() command checks the specified Bumper Switch:
Has a value of true when pressed
Has a value of false when not pressed
.pressing( ) condition
3. Download and Run the program.
4. Observe.
As programmed, your robot waits for the Bumper Switch to be pressed before moving forward. To allow the robot to read past the waitUntil command, press on the rear Bumper Switch! Your robot will move the set amount duration once it is pressed.
Press the rear Bumper Switch to move
Try It: Modify Rear Bumper Switch
The red cap on the Bumper Switch can be replaced with other components or modified to serve a specific purpose. Modify your rear Bumper Switch by inserting a 0.375 OD x 0.500" Nylon Spacer with a #8-32 x 0.750" Star Drive Screw so that the red cap reaches out further than the arm’s red gear.
Use the same program. However, this time, place your robot at least 600mm away from the wall.
Robot placed 600mm away from object
Download and run the program.
What happens?
Did You Know? Bumper Switch Sensor
The Bumper Switch v2 reports to the Robot Brain is whether it is pressed in, versus released. The Bumper Switch v2 allows the robot to sense physical collisions. When the Bumper Switch is pressed, it closes an electrical circuit, allowing current to flow. If the Bumper Switch is released, the circuit is broken and no current flows.
The flow (or lack) of current is detected by the robot, allowing it to determine the Bumper Switch is pressed.
VEX V5 Bumper Switch
The V5 Robot Brain allows you to check the values of the Bumper Switches under the Devices menu. Choose Devices, then select the triangular icon.
The Devices menu does not automatically “know” what type of sensor is connected. Tap the box where the Bumper Switch is connected until it displays Digital Input. The Bumper Switch is a type of touch sensor, which is a Digital Sensor. When the Bumper Switch is released, it should have a value of High (1), and when pressed a value of Low (0).
Home ScreenDevices Menu3-Wire Ports
Which of the following commands checks if a Bumper Switch is pressed?