Skip to main content

Lesson 3: Turning the VR Robot

Now that you have knocked over the first castle in the Castle Crasher Playground, you will need the VR Robot to turn to knock over another. This Lesson will walk you through the steps to turn the VR Robot and knock over two buildings on the Castle Crasher Playground.

Learning Outcomes

  • Identify how to use the turn_for command to turn the VR Robot right or left.
  • Identify how to use the turn_to_heading command to turn the VR Robot to a given clockwise heading.

Rename the Project

  • If the previous lesson’s code is not already loaded, load the Unit2Lesson2 project.
  • Rename the project by selecting the project name box.
    The VEXcode VR Toolbar, the Project Name is highlighted with a red box and reads Unit 2 Lesson 2.
  • Enter the new project name Unit2Lesson3, and select “Save.”

The Project Name window in the VEXcode VR interface. The Project Name has been changed to say Unit2Lesson3 and the Save button is highlighted with a red box.

Turn Right or Left

The turn_for command rotates the VR Robot a given number of degrees. This example will have the VR Robot drive forward to knock over the center building, reverse back to the start, then turn and knock over the building in the bottom right corner on the Castle Crasher Playground.

Top down view of the Castle Crasher playground with the center castle and bottom right castle highlighted in a red boxes, indicating which structures will be knocked over in this lesson.

For Your Information

To make a VR Robot turn at different speeds, the turn velocity can be increased or decreased using the set_turn_velocity command. The set_turn_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_turn_velocity(50, PERCENT)
  • Drag in or type a turn_for command beneath the drive_for command. Set the parameters of the turn_for command to turn right 90 degrees.  This project has the set_drive_velocity and set_turn_velocity commands added and set to 100%. Your project should look like this:

    # Add project code in "main"
    def main():
        drivetrain.set_drive_velocity(100, PERCENT)
        drivetrain.set_turn_velocity(100, PERCENT)
        drivetrain.drive_for(FORWARD, 800, MM)
        drivetrain.drive_for(REVERSE, 800, MM)
        drivetrain.turn_for(RIGHT, 90, DEGREES)
  • Drag in or type the drive_for command below the turn_for command. Set the parameters of the drive_for command to drive forward 700 millimeters (mm). Your project should look like this:

    # Add project code in "main"
    def main():
        drivetrain.set_drive_velocity(100, PERCENT)
        drivetrain.set_turn_velocity(100, PERCENT)
        drivetrain.drive_for(FORWARD, 800, MM)
        drivetrain.drive_for(REVERSE, 800, MM)
        drivetrain.turn_for(RIGHT, 90, DEGREES)
        drivetrain.drive_for(FORWARD, 700, MM)
  • Select the “Open Playground” button to launch the Castle Crasher Playground if it is not already open.

Right side of the VEXcode VR Toolbar. The Open Playground button, the icon second from the left, is highlighted with a red box.

  • Select the “Start” button to test the project.

Right side of the VEXcode VR Toolbar. The Start button, the icon third from the left, is highlighted with a red box.

  • Watch the VR Robot drive forward and collide with the center building before reversing back to the start. The VR Robot will then turn right 90 degrees and drive forward to collide with the building at the bottom right corner of the Castle Crasher Playground.

    Top down view of the Castle Crasher Playground. The middle and bottom right castles have been toppled over. The VR robot iis now in the bottom right of the playground, facing the playground's right wall.

Select the Next button to continue with the rest of this Lesson.