Skip to main content

Lesson 2: Change Parameters in the Drive for Command

The VR Robot did not touch the center castle in the last project. It needs to travel farther. Adjust the parameters, test it, and watch the VR Robot knock over the center castle!

  • Set the distance the VR Robot will move by entering the value "800" as the second parameter in the drive_for command. Your project should now look like this:
     

    # Add project code in "main"
    def main():
        drivetrain.drive_for(FORWARD, 800, MM)

For Your Information

The drive_for command can accept both whole numbers (integers) and decimals (floats). The units can also be changed from millimeters (mm) to inches.

Two drivetain.drive_for commands. One command is using MM in its units parameter and the other is using INCHES. Both units are highlighted with a red box.

  • Start the project.
    The top of the VEXcode VR interface. The Start button is highlighted with a red box.
  • The VR Robot will collide with the center castle and knock parts of it over.

    Top down view of the Castle Crasher playground. The robot has moved from its starting position on the bottom the field and is now in the middle of the playground. The castle in the middle of the playground has been toppled over.
  • Select the “Reset” button to reset the Playground.
    Top down view of the Castle Crasher playground with the VEXcode VR Playground interface. The robot has moved from its starting position on the bottom the field and is now in the middle of the playground. The blocks in the middle of the playground have been toppled over. The Reset button in the bottom right of the playground is highlighted with a red box.
    The VR Robot now needs to return to the starting position. Use an additional drive_for command and change the parameters to make it drive in reverse to return to the starting position.
  • Add a second drive_for command to the VEXcode VR project, and change the direction from “FORWARD” to “REVERSE.” Your project should now look like this:
     

    # Add project code in "main"
    def main():
        drivetrain.drive_for(FORWARD, 800, MM)
        drivetrain.drive_for(REVERSE, 200, MM)
  • Make sure the distance value is the same as the first drive_for command, 800 millimeters (mm), in order for it to return to the starting position. Your project should now look like this:
     

    # Add project code in "main"
    def main():
        drivetrain.drive_for(FORWARD, 800, MM)
        drivetrain.drive_for(REVERSE, 800, MM)
  • Select the “Start” button and run the project.
    The VEXcode VR Toolbar. The Start button is highlighted in red on the right of the toolbar.
  • The VR Robot will move forward and backward for 800 millimeters (mm), returning to the starting position.
    Top down view of the Castle Crasher Playground showing the castle in the middle of the Playground has been toppled over and the VR robot is back in its starting position at the bottom of the Playground.

Note: You have successfully completed the first part of the Castle Crasher Challenge! Even if all four parts of the center castle are not completely knocked over, if they are slightly displaced, that is acceptable.

For Your Information

To make a VR Robot drive forward and reverse at different speeds, the drive velocity can be increased or decreased using the set_drive_velocity command. The set_drive_velocity command accepts a range from 0 - 100 for the velocity parameter. The default velocity is 50%. Changing velocity will apply to any subsequent Drivetrain commands.

drivetrain.set_drive_velocity(50, PERCENT)

Save Your Project

To save your project, select “Save As" in the “File” drop-down menu.

The VEXcode VR Python coding interface. The File menu is shown and the Save As button is highlighted with a red box.

Once saved, the project will appear in the Downloads folder of your device as a .vrpython file.

Questions

Please select a link below to access the lesson quiz.

Google Doc / .docx / .pdf