Skip to main content
Teacher Portal

Teacher Toolbox icon Teacher Toolbox - The Purpose of this Section

Using the Tank Control example project enables the students to control the Clawbot using the Controller. Students will need to adjust the parameters in the left_motor.set_velocity(), right_motor.set_velocity(), left_motor.spin(), right_motor.spin(), left_motor_speed = controller_1.axis3.position(), and right_motor_speed = controller_1.axis2.position() instructions to control the velocity for each of the Clawbot’s motors and enable the Controller to control the motor functions.

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

The following is an outline of what the students will do in this activity:

  1. Explore the Tank Control example project.
  2. Understand the use of the while True infinite loop structure.
  3. Complete the Robo-Slalom challenge!

Teacher Tips icon Teacher Tips

If this is the student's first time using VEXcode V5, they can access many helpful articles in the VEX Library.

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

Teacher Tips icon Teacher Tips - Using Autocomplete

Autocomplete is a feature in VEXcode V5 that predicts the rest of the command you are typing. As students are working in VEXcode V5, encourage them to use the Autocomplete feature to help with the Python syntax. You may notice an autocomplete function as you start to type the instruction. Use your “Up” and “Down” keys to select the name you want, then press “Tab'' or (Enter/Return) on your keyboard to make the selection. For more information on this feature check out the Python article

VEXcode V5 with the start of a Drivetrain command typed to the left, and to the right, a scrollable list of autocomplete options for that command is shown.

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. 

Code example in Python using the VEX library. The script includes necessary imports and initializes the project code. The main loop continuously reads the positions of Controller 1s Axis 3 and Axis 2, setting the velocities of the left and right motors accordingly. The motors are then spun forward with a brief wait of 5 milliseconds between iterations to ensure smooth operation

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?

Teacher Toolbox icon Teacher Toolbox - Answers

  1. This project will utilize the while True infinite loop structure to continuously check where the left and right Joystick's positions are. When the left (or right) Joystick is pushed up, the velocity is set for how far forward the Joystick is pushed. 
  2. Thus, the farther forward the Joystick is pushed, the faster the velocity will be set and the faster the motors will move. The same idea works for pushing the Joystick back. The farther backward the Joystick is pushed, the faster the motors will move in reverse.
  • 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

Teacher Toolbox icon Teacher Toolbox - The while True Infinite Loop Structures

This step discusses the importance of the while True infinite loop structure. You should review the information as a class. You can model the behavior with your Clawbot and Controller, or if time permits, have the students run the program without the while True infinite loop structure.

If the students need further assistance with understanding the while True infinite loop, click here.

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

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

Python code example for controlling motors with a VEX robotics controller. The script begins by importing the necessary VEX library, then enters a continuous loop where it sets the velocity of the left and right motors based on the positions of Axis 3 and Axis 2 on Controller 1. The motors spin forward, and the loop waits for 5 milliseconds before repeating to ensure smooth operation


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

Teacher Toolbox icon Teacher Toolbox - Understanding the Structure

Without the while True infinite loop, the velocity’s value for each motor is set as soon as the project is run, and that value remains constant until the project is stopped. In other words, if you run the project without moving either Joystick, because the Joystick’s default position on its axis is 0, the velocity of both motors will remain at 0, even if you move the Joystick.

Likewise, let’s say you move the left Joystick up as far as it will go along axis 3 and hold it there. If you run the project above, the left motor will move at full speed and will remain at that velocity even if you move the Joystick down along axis 3. This is because Clawbot receives its initial instruction from the Controller as soon as the project is run; however, without a Loop, that initial value cannot update.

The while True infinite loop tells the Clawbot to constantly update the velocity and run for the duration of the project. In other words, the while True infinite loop, in this project, enables you to change the velocity of each motor by moving either Joystick along axis 2 or 3, and the Clawbot will respond accordingly until you stop the project or turn off the Clawbot.

While True project

Navigate a Slalom Course!

Teacher Toolbox icon Teacher Toolbox - Set up the Activity

Organize the students into small groups of 2 or 4 students. One student should be designated as the Driver - the person who will use the Controller to maneuver the Clawbot.

Have students complete this slalom by using the Controller to move the Clawbot along the outside of each “flag.” The Clawbot’s path must prevent it from touching any flag and allow it to cross the finish line. Flags can be any classroom material/object you have handy (eraser, roll of tape, tissue box) and can be set in place prior to operating the Clawbot.

If time permits, have students switch roles to give others the opportunity to drive the Clawbot. You could even turn this into a competition within groups or between groups by seeing how quickly each driver can navigate the slalom.

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?
     

Motivate Discussion icon Motivate Discussion - Reflecting on the Activity

Q: Did the Clawbot respond to the Controller as you expected it to?

A: Answers will vary; however, the goal of this question is to promote cognitive thinking. Students began by predicting behaviors before testing them, documenting their results, and reflecting.

Q: What is the biggest challenge in moving the Clawbot forward or reverse in a straight line?

A: While answers may vary, a common response should be that both Joysticks must move in sync with one another to ensure that the Clawbot’s motors are moving in the same direction and at the same velocity

Q: How does using the while True infinite loop loop enable you to continuously use the Controller to move the Clawbot?

A: Without the while True infinite loop, the Clawbot would only perform the behaviors as determined by the instructions in the project once. The while True infinite loop tells the Clawbot to constantly update the velocity and run for the duration of the project. In other words, the while True infinite loop enables you to use the Controller to move the Clawbot indefinitely, or until the battery dies.