Skip to main content

Controller: Tank Drive Exploration - Python

Materials Required:
Quantity Materials Needed
1

VEX V5 Classroom Starter Kit (with up-to-date firmware)

1

VEXcode V5 (latest version, Windows, macOS)

1

Engineering Notebook

1

Tank Control Example Project

2 or more

Classroom objects to be used as obstacles

This activity will give you the tools to program your Controller. 

  • VEXcode V5 Python instructions that will be used in this exploration:
    • left_motor.set_velocity()
    • right_motor.set_velocity()
    • left_motor.spin()
    • right_motor.spin()
    • controller_1.axis2.position()
    • controller_1.axis3.position()
    • while True: 
    • wait(5, SECONDS)

For more information about any of the instructions, visit the Python help  sections in VEXcode V5. 

VEXcode V5 is shown with the Toolbox open on the far left, and the Help for the Drive command open on the far right. The Help shows the definition of the command and information about how it is used.

Step 1: Let's start programming the Controller.

  • Select File and 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.
  • Scroll through the different Example projects. Select the Tank Control example project.

Example projects in VEXcode V5 with a red box around the Sensing filter at the top and the Tank Control example project icon to the lower right.

  • Open the Tank Control example project. The example project configures the drivetrain and controller. The code will look like the following snippet:
# Library imports
from vex import *

# Begin project code
# Main Controller loop to set motors to controller axis postiions
while True:
    left_motor.set_velocity(controller_1.axis3.position(), PERCENT)
    right_motor.set_velocity(controller_1.axis2.position(), PERCENT)
    left_motor.spin(FORWARD)
    right_motor.spin(FORWARD)
    wait(5, MSEC)

Do the following in your engineering notebook:

  1. Predict what the project will have the Clawbot do. Explain more than the fact that the project utilizes the Controller.
  2. How do the joysticks move the robot? What is the Clawbot doing?
  • Name the project TankControl. Save, download, and run the Python TankControl project.

Project name dialog box in VEXcode V5 reads Tank Control, and shows that slot 1 is selected.

  • For more help information, watch the tutorial video in VEXcode V5 explaining how to Download and Run a project.

Toolbar in VEXcode V5 with a red box around the Tutorials icon. The toolbar shows, from left to right, the V5 logo, a globe icon, File, then Tutorials.

  • Check your explanations of the project in your engineering notebook and add notes to correct them as needed.

Step 2: Controller:  Tank Control

​What are the benefits of using the while True infinite loop structure?

Here is our project without the while True infinite loop structure:

# Library imports
from vex import *

# Begin project code
# Main Controller loop to set motors to controller axis postiions

left_motor.set_velocity(controller_1.axis3.position(), PERCENT)
right_motor.set_velocity(controller_1.axis2.position(), PERCENT)
left_motor.spin(FORWARD)
right_motor.spin(FORWARD)


What do you think would happen if this program were run? Discuss as a group. Write down your prediction in the engineering notebook.

Navigate a Slalom Course!

A snowboarder is racing downhill on a snow-covered slope, navigating through a series of red and blue gates positioned in a zigzag pattern

Slaloms are courses which the participant must navigate around the set flags, or markers. Ski slaloms are a popular winter sport and are included in the Winter Olympics.
Now that the Controller is paired and the Python project is downloaded, you are ready to move your Clawbot using the Controller!

  • Collect the four classroom items you will use as flags in your slalom from the teacher.
  • Collaborate to set the flags in place for the Driver to navigate the Clawbot around, according to the slalom diagram.
  • Download the Tank Control Example project. If there are any questions about how to download a project, check out the Download and Run a Project tutorial.

An illustration of a slalom course on snow, with a 'Start' label at the top, and a Finish line at the bottom. Between, a dotted zigzag path weaves between alternating blue and red flags.

Use the Controller to move your Clawbot along the outside of each “flag.” The robot’s path must prevent it from touching any flag, and allow it to cross the finish line.

  • Run the project and drive the Clawbot forward and reverse, and turn left and right using both Joysticks.
  • Time how long it takes for the Clawbot to complete the course. Document the times in the engineering notebook.
  • How fast can you get Clawbot through the Slalom course?