Skip to main content
Teacher Portal

Programming the Robot Arm - Python

Teacher Toolbox icon Teacher Toolbox - Activity Outline

  • This exploration will introduce students to basic programming of the V5 Clawbot's Arm Motor. 
  • Learning to program the Arm Motor enables students to properly control the V5 Clawbot's arm movements. For more information about the instructions used in a Python project, visit the help information for VEXcode V5 Python.

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 Python workspace with the start of a Drivetrain command typed, and the autocomplete window open showing the options for the rest of the command.

The V5 Clawbot is ready to reach!

This exploration will give you the tools to be able to start creating some cool projects that use the V5 Clawbot's arm.

  • VEXcode V5 Python instructions that will be used in this exploration:
    • arm_motor.spin_for(FORWARD, 90, DEGREES)
    • arm_motor.set_position(0, DEGREES)
    • wait(2, SECONDS)
  • To find out more information about the instruction, select the question mark icon next to a command to see more information. 

    VEXcode V5 shows a Drive for command typed in the workspace and the Help open to the right for that command. The help defines Drive for as moves the Drivetrain for a given distance, and explains how to use the command in a project.

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

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

1

VEXcode V5

1

Engineering Notebook

1

Clawbot and Advanced TrainingBot (Drivetrain 2-motor, No Gyro) example project

Step 1: Preparing for the Exploration

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

  • Are the motors plugged into the correct ports?

  • Are the smart cables fully inserted into all of the motors?

  • Is the Brain turned on?

  • Is the battery charged?

Teacher Tips icon Teacher Tips

Model each of the troubleshooting steps for the students.

Step 2:  Start a New Project

Before you begin your project, select the correct template project. The Clawbot and Advanced TrainingBot (Drivetrain 2-motor, No Gyro) example project contains the Clawbot's motors configuration. If the template is not used, your robot will not run the project correctly.

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.

Complete the following steps:

  • Open the File menu.
  • Select Open Examples.

Icon reading Clawbot and Advanced Training Bot with a gray robot above the text.

  • Select and open the Clawbot and Advanced TrainingBot (Drivetrain 2-motor, No Gyro) example project.
  • Since we will be programming to control the arm, rename your project ArmControl.
  • Save your project.
  • Check to make sure the project name ArmControl is now in the window in the center of the toolbar.

The project name dialog box in the VEXcode V5 Toolbar reads Arm Control and shows that Slot 1 is selected.

Teacher Tips icon Teacher Tips

  • Since this is a beginning activity with programming, the teacher should model the steps, and then ask the students to complete the same actions. The teacher should then monitor the students to ensure that they are following the steps correctly.
  • Make sure that the students have selected Open Examples from the File menu.
  • Make sure that the students have selected the Clawbot and Advanced TrainingBot (Drivetrain 2-motor, No Gyro) example project.

          You can point out to the students that there are several selections to pick from on the Examples page. As they build and use other robots, they will have a chance to use different templates.

  • You can ask students to add their initials or the name of their group to the project name. This will help differentiate the projects if you ask the students to submit them.

Teacher Toolbox icon Teacher Toolbox - Saving Projects

  • Point out that when they first opened VEXcode V5, the window was labeled VEXcode Project. VEXcode Project is the default project name when VEXcode V5 is first opened. Once the project was renamed and saved, the display was updated to show the new project name. Using this window in the toolbar, it is easy to check that the students are using the correct project.
  • Tell the students that they are now ready to begin their first project. Explain to the students that by just following a few simple steps, they will be able to create and run a project that will raise and lower the Clawbot's arm.
  • Remind students to save their projects as they work. The articles in the Python section of the VEX Library explains saving practices in VEXcode V5.

Teacher Toolbox icon Teacher Toolbox - Stop and Discuss

This is a good point to pause and have the student groups review the steps that were just completed on starting a new project in VEXcode V5.

Step 3:  Move the Arm Up

We are now going to begin by programming the arm to raise!

# Library imports
from vex import *

# Begin project code
arm_motor.set_position(0, DEGREES)
  • Write the arm_motor.set_position() command as shown above in the programming area to set the starting position for the arm.
arm_motor.set_position(0, DEGREES)
arm_motor.spin_for(FORWARD, 90, DEGREES)
  • Add the arm_motor.spin_for() command below the arm_motor.set_position() command as shown above to move the arm up.

VEXcode V5 Toolbar with the slot selection open beside the project name. Slot 1 is selected and highlighted with a red box and the project name reads Arm Control.

  • Select the Slot icon. You can download your project to one of the available slots in the Robot Brain. Select Slot 1.

Image of the Toolbar in VEXcode V5 with a red box around the green arm icon

  • Connect the robot to your computer or tablet. The Brain icon in the toolbar turns green after a successful connection has been made.

Toolbar in VEXcode V5 with a red box around the download button. The icons shown from left to right are Controller, Brain, Download, Run, and Stop.

  • Click the Download button on the toolbar to download the ArmControl project to the Robot Brain.

Teacher Toolbox icon Teacher Toolbox

If the students are using a computer, ask them now to disconnect the USB cable from the Robot Brain. Having the robot connected to a computer while running a project could cause the robot to pull on the connection cable.

V5 Brain Home Screen shows the Arm Control project in slot 1 in the bottom left corner. In the row above, the icons read Drive, Devices, Settings, and VEX.

  • Check that the ArmControl project has downloaded to the brain in the slot you chose.

Teacher Toolbox icon Teacher Toolbox - Model First

Model running the project in front of the class before having all of the students try at once. Gather the students in one area and leave enough room for the Clawbot to move its arm. Demonstrate how to end the project and have the Clawbot's arm lower back to its resting position.

Tell the students it is now their turn to run their projects. Make sure that they have adequate space to safely have the Clawbot's arm raised.
 

  • Run the project on the Clawbot by making sure the project is selected and then press the Run button. Congratulations on creating your first Claw Arm project!

Step 4:  Try This: Program the Arm Down

Now that you have programmed the arm to move up, you will now program the arm to lower or move down.

Sideview of the V5 Clawbot with its arm down

Image of the VEX V5 Clawbot with its arm down

  • Add a second arm_motor.spin_for() command to your ArmControl project so that the arm raises to 90 degrees, waits 2 seconds, and then back down.
    • Hint: You will need to change the direction within the command.
  • Notice that the arm holds its position while the wait command is running. The motor draws power from the battery to hold the arm up against the force of gravity. That's because the default setting for having the motor stop is the hold setting. There are two other settings for stopping - brake and coast. You will learn about those in another lab.

Teacher Toolbox icon Teacher Toolbox - Solution

The solution to the challenge is below. To lower the arm, students needed to change the “FORWARD” parameter to “REVERSE” in the arm_motor.spin_for() command that was added.

# Begin project code
arm_motor.set_position(0, DEGREES)
arm_motor.spin_for(FORWARD, 90, DEGREES)
wait(2, SECONDS)
arm_motor.spin_for(REVERSE, 90, DEGREES)

Step 5:  Complete the Flight Traffic Controller Challenge

Sideview of a V5 Clawbot with the arm raised up and arrows below it indicating up and down motion.

Image of the V5 Clawbot with its arm raised with red arrows pointing up and down, showing how the Clawbot can raise and lower its arm In the Flight Traffic Controller Challenge, the Clawbot must move its arm up and down once for 90 degrees, wait 3 seconds, move the arm up and down two times for 45 degrees, wait 5 seconds, and then move the arm up and down three times for 90 degrees.

Here is a list of the Clawbot's behaviors:

  • Move arm up and then down for 90 degrees.
  • Wait 3 seconds.
  • Move arm up and then down for 45 degrees.
  • Move arm up and then down for 45 degrees.
  • Wait 5 seconds.
  • Move arm up and then down for 90 degrees.
  • Move arm up and then down for 90 degrees.
  • Move arm up and then down for 90 degrees.

Teacher Toolbox icon Teacher Toolbox - Solution

Most of the commands within this challenge are arm_motor.spin_for(). After adding a command for moving the arm upward, and one for moving the arm downward, you can highlight the two commands, right-click, and then choose to copy and paste them as many times as needed. Then the parameters can be changed to meet the challenge and wait commands can be added between.VEXcode V5 Python project in the workspace with two spin for blocks highlighted and the context menu open to the right. The Copy option in the context menu is highlighted. Copy appears between Cut and Paste.

  • Review an example Flight Traffic Controller Challenge solution here: 
# Begin project code
arm_motor.set_position(0, DEGREES)
arm_motor.spin_for(FORWARD, 90, DEGREES)
arm_motor.spin_for(REVERSE, 90, DEGREES)
wait(3, SECONDS)
arm_motor.spin_for(FORWARD, 45, DEGREES)
arm_motor.spin_for(REVERSE, 45, DEGREES)
arm_motor.spin_for(FORWARD, 45, DEGREES)
arm_motor.spin_for(REVERSE, 45, DEGREES)
wait(5, SECONDS)
arm_motor.spin_for(FORWARD, 90, DEGREES)
arm_motor.spin_for(REVERSE, 90, DEGREES)
arm_motor.spin_for(FORWARD, 90, DEGREES)
arm_motor.spin_for(REVERSE, 90, DEGREES)
arm_motor.spin_for(FORWARD, 90, DEGREES)
arm_motor.spin_for(REVERSE, 90, DEGREES)

More advanced students might use loops to simplify the solution.

# Begin project code
arm_motor.set_position(0, DEGREES)
arm_motor.spin_for(FORWARD, 90, DEGREES)
arm_motor.spin_for(REVERSE, 90, DEGREES)
wait(3, SECONDS)
for repeat_count in range(2): 
    arm_motor.spin_for(FORWARD, 45, DEGREES)
    arm_motor.spin_for(REVERSE, 45, DEGREES)
wait(5, SECONDS)
for repeat_count in range(3):
    arm_motor.spin_for(FORWARD, 90, DEGREES)
    arm_motor.spin_for(REVERSE, 90, DEGREES)