The VEXcode VR Robot has two Bumper Sensors. The Bumper Sensor can be used with VEXcode VR to report if a Bumper Sensor is pressed on the VEXcode VR Robot.
What is a Bumper Sensor?
A Bumper Sensor is a switch. The Bumper Sensor reports if it is pressed or released.
- The Bumper Sensor will report a sensor value of 1 when the bumper sensor is being pressed.
- The Bumper Sensor will report a sensor value of 0 when the bumper sensor is released.
The Bumper Sensor’s value can be viewed in the Dashboard. For more information about the Dashboard, check out the VEXcode VR Dashboard Article.
Common Uses of a Bumper Sensor
The Bumper Sensor can be pressed by walls in the Wall Maze Playground.
The Bumper Sensor can also be pressed by walls surrounding different Playgrounds.
Using the Bumper Sensor in VEXcode VR Blocks
To begin programming the Bumper Sensor, you will need to first open VEXcode VR. For more information, check out the Launch - Get Started with VEXcode VR article.
Next, locate the Sensing category in the Tool box and find the <Pressing Bumper> block.
Change the Bumper Sensor
You can select the Left Bumper or Right Bumper from the drop-down menu.
Boolean blocks
The Boolean blocks report a condition as either true or false and fits inside any blocks with hexagonal (six-sided) inputs for other blocks.The Pressing Bumper Boolean block reports “true” if the bumper is pressed and “false” if the bumper is released or not pressed. For more information about Boolean blocks visit the Help or the Block Shapes and Meaning - VEXcode VR article.
The following is an example of a code that will cause the VR Robot to drive forward until it bumps into an object or wall.
C blocks
C blocks loop the block(s) within them or check if a condition is true or false. They are shaped to attach stack blocks above, below, or inside them. The Bumper Sensor control blocks are commonly used with conditionals (C blocks), such as the [If then] or [Wait until] blocks. For more information about conditional blocks found in the Control category, visit the Help or the Block Shapes and Meaning - VEXcode VR article.
In the following example, the code will cause the VR Robot to drive in a square forever.
Using the Bumper Sensor in VEXcode VR Python
To begin programming the Bumper Sensor with Python, you will need to first open a text project VEXcode VR. For more information, see this article.
Next, locate the Sensing category in the Toolbox and find left_bumper.pressed and right_bumper.pressed commands. These are functions that report a Boolean value about the sensor. Because there are two Bumper Sensors on the VR Robot, there are options for both the right and left bumper.
To add the command to your project, you can drag the command in from the Toolbox, or type out the command in the workspace using the Autocomplete function. To learn more about Autocomplete in VEXcode VR with Python, see this article.
def main(): |
A while loop can be used with sensors on your robot when you want your robot to do something like drive until the Bumper Switch is pressed, then stop or turn. In this project, the robot will drive forward while the Bumper Switch is not pressed, and will turn right 90 degrees when the Bumper Switch is pressed. |