Lesson 3: Drive to Number ‘31’
In this Lesson, the VR Robot will drive to the number ‘31’ and then back to number ‘1’ on the Number Grid Map Playground!
Notice that the VR Robot will be traveling along the Y axis to move to the number ‘31’ on the Number Grid Map Playground.
The VR Robot will drive to the location of the number ‘31’ on the Number Grid Map Playground. However, before the VR Robot can navigate to that number, the VR Robot has to be told where that number’s location is. The coordinates of number ‘31’ are (-900, -300).
-
Drag the [Drive] non-waiting block into the workspace.
-
Attach a [Wait until] block beneath the [Drive] block.
-
Drag the <Greater than> Boolean reporter block into the [Wait until] block.
-
Note that the <Greater than> block is used instead of the <Less than> block because the VR Robot is driving up from the bottom of the Playground. The VR Robot is starting at a Y-value of -900 millimeters (mm). As the VR Robot drives forward, the Y-values increase.
-
Drag the (Position of Robot) block into the <Greater than> block.
-
Set the parameter of the (Position of Robot) block to “Y” and the parameter of the <Greater than> block to -300.
-
Drag in a [Stop driving] block and add it to the project.
- Launch the Number Grid Map Playground if it is not already open and run the project.
-
Watch the VR Robot drive to number ‘31’ on the Number Grid Map Playground.
- In this project, the VR Robot drives to the number ‘31’ on the Number Grid Map Playground. Since the Y-values are increasing as the VR Robot drives to the number ‘31,’ the project uses a <Greater than> block.
- The VR Robot will stop once its Y-value is greater than the Y-value of the coordinate that the indicated number is on. Since the Y-value of the number ‘31’ is -300, the VR Robot will stop driving once the Y-value is greater than -300.
Using Switch Blocks
In this Lesson, you learned how to use the VEXcode [Wait until] block with a Boolean condition to command the robot to wait until the robot reaches a position of greater than -300 on the Y-axis before moving to the next behavior.
The image below shows the VEXcode block beside the Switch block containing the Python command for the same behaviors.
Within the Switch block, while not location.position(Y, MM) > -300: is the first Python command that checks whether the position of the robot along the X-axis is greater than -300.
The second indented command, wait (5, MSEC), pauses the execution of the conditional loop for 5 milliseconds.
In VEXcode VR, a wait command is always added with the conditional loop. The purpose of the wait command is to ensure that VEXcode VR can properly run the project as intended, due to the web-based nature of the VEXcode VR platform. The wait command should never be deleted when using a conditional loop, or your project may not run as intended.
In this example, the project checks whether or not the robot's position is greater than a Y value of -300 every 5 MSEC. This line of code is indented underneath the first line of code because this command is the behavior that will repeat until the condition (a Y coordinate value of greater than -300) is met.
Select the Next button to continue with the rest of this Lesson.