Skip to main content

Programming Turning Right and Left - Python

The Speedbot is ready to turn! 

This exploration will give you the tools to be able to start creating some cool projects for your Speedbot to follow.

  • VEXcode V5 Python instructions that will be used in this exploration:
    • drivetrain.turn_for(RIGHT, 90, DEGREES)
  • To find out more information about the instruction, select Help and then select the question mark icon next to a command to see more information.

    A user is typing a Drivetrain turn for command in the workspace on the far left, and the Help for the Turn for command is open on the far right. The Help shows the definition of the command and information about how it is used.

     

  • Make sure you have the hardware required, your engineering notebook, and VEXcode V5 downloaded and ready.
Materials Required:
Quantity Materials Needed
1

Speedbot Robot

1

Charged Robot Battery

1

VEXcode V5

1

USB Cable (if using a computer)

1

Engineering Notebook

Step 1:  Preparing for the Exploration

Before you begin the activity, do you have each of these items ready?

Step 2:  Start a New Project

Complete the following steps to begin the project:

  • Open the File menu and select Open Examples.

    VEXcode V5 Toolbar with the File menu open and Open Examples highlighted in a red box. Open Examples is the fourth menu item beneath New Blocks Project, New Text Project, and Open.

     

  • Select and open the Speedbot (Drivetrain 2-motor, No Gyro) template project. The template project contains the Speedbot's motor configuration. If the template is not used, your robot will not run the project correctly.

    Example Projects in VEXcode V5 with a red box around the Template filter at the top and the Clawbot (Drivetrain 2-Motor, No Gyro) Template Project, indicating which project to open.

  • Since you will be working on turning the Speedbot, you will name your project Turn.

    Project name dialog in VEXcode V5 with the name changed to Turn.

     

  • When finished, select Save.

    Project name reads Turn in the Toolbar and Slot 1 is selected.

Step 3:  Turn Right

You are now ready to begin programming the robot to turn right!

  • Add the instruction to the project, so your project looks like this:

    # Library imports
    from vex import *
    
    # Begin project code
    
    drivetrain.turn_for(RIGHT, 90, DEGREES)
  • Select the Slot icon to choose one of the eight available slots on the Robot Brain and select slot 1.
  • Connect the V5 Robot Brain to the computer using a micro USB cable and power on the V5 Robot Brain. The Brain icon in the toolbar turns green once a successful connection has been made.
  • When the V5 Robot Brain is connected to the computer, the Build icon changes to the Download icon. Select Download to download the project to the Brain.
  • Check to make sure your project has downloaded (Python) by looking at the Robot Brain’s screen. The project name Turn should be listed in Slot 1.

    V5 Brain Home screen shows the Turn project in Slot 1, the first icon in the bottom row, below the Drive icon.

  • Run the project (Python) on the Speedbot robot by making sure the project is selected and then press the Run button on the Robot Brain.

Step 4:  Turn Left

Now that you have programmed your robot to turn right, let us program it to turn left.

  • Change the parameter in the instruction to display LEFT instead of RIGHT, so your project looks like this:

    # Library imports
    from vex import *
    
    # Begin project code
    
    drivetrain.turn_for(LEFT, 90, DEGREES)
  • Select the Project Name to change it from Turn to TurnLeft.
  • Select the Slot icon to choose a new slot. Select slot 2.
  • Download (Python) the project.
  • Check to make sure your project has downloaded (Python) by looking at the Robot Brain’s screen. The project name TurnLeft should be listed in Slot 2.
  • Run (Python) the project on the robot by making sure the project is selected and then press the Run button.

Step 5:  Wait then Turn Left

Now that we have programmed the robot to turn left right then turn left, we can now add a wait instruction so that the robot waits a certain amount of time before turning left.

  • Add a wait instruction before the drive_for command. Be sure the wait is indented to match the drive_for command, and that all commands are below the “Begin project code” comment. This tells the robot to wait three seconds before driving in reverse.

    # Begin project code
    
    wait(3, SECONDS)
    
    drivetrain.turn_for(LEFT, 90, DEGREES)
  • Select the Project Name to change it from TurnLeft to WaitLeft.
  • Select the Slot icon to choose a new slot. Select slot 3.
  • Download (Python) the project.
  • Check to make sure your project has downloaded (Python) by looking at the Robot Brain’s screen. The project name WaitLeft should be listed in Slot 3.
  • Run (Python) the project on the robot by making sure the project is selected and then press the Run button.

Step 6:  Complete the Security Camera Challenge!

A SpeedBot with three circles drawn around it, indicating directions for turning. Three movements are shown and labeled, first turning to the right, then the left, then the right and repeating the left to right steps three times.
Security Camera Challenge Layout

In the Security Camera Challenge, the robot must start by turning to the right 90 degrees. The robot will then turn to the left 180 degrees then right 180 degrees “scanning” just like a security camera. The robot will then repeat turning 180 degrees to the left and 180 degrees to the right two more times. Thus, the robot will scan 180 degrees three times total.

Before programming the robot, plan out the robot's path and behaviors in your engineering notebook.

After completing the Security Camera Challenge, you will be able to combine forward and backwards movements with additional robot behaviors to complete even more advanced challenges.