Skip to main content

Programming Loops - Blocks-based

The V5 Clawbot is ready to move!

You can use the Help information inside of VEXcode V5  to learn about the blocks. For guidance in using the Help feature, see the Using Help tutorial.

Materials Required:
Quantity Materials Needed
1

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

1

VEXcode V5 (latest version, Windows, MacOS, Chromebook)

1

Engineering Notebook

1

Using Loops (Tutorial)
 

1

Repeating Actions (No Gyro) example project
 

Step 1:  Let's start programming with loops.

  • Start by watching the Using Loops tutorial video.

  • Open the Repeating Actions (No Gyro) example project.

    Repeating Actions (No Gyro) template icon, illustrating which template project to select for this activity.

  • View the opened example project.

    Example project in the VEXcode V5 Workspace. To the left, the project has a When Started block with a Repeat block attached, set to repeat 4 times. Within the loop is a Drive For block set to forward for 300mm, and a Turn For block set to right for 90 degrees. To the right a note reads 'This program drives a robot in a 300x300mm square by repeating the drive forward and turn commands 4 times'.

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 repeats.

    What is it repeating? What is the Clawbot doing?

  2. Write your prediction, but do not break the short project into more than two parts.
  • Save, download, and run the Repeating Actions (No Gyro) example project.

    VEXcode V5 Toolbar displaying the project name 'Repeating Actions (No Gyro)'.

  • For help, see the tutorial in VEXcode V5 that explains how to Download and Run a Project.

    VEX V5 Toolbar with a red arrow calling out the Tutorials button to the right of the File button.

     

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

Step 2: Run the project and observe the robot.

Two code snippets side by side showing the difference in use case between a forever loop (to the left) and a repeat loop (to the right). To the left there is a Comment that reads 'Using sensor input to determine when to turn' with a forever block with an if then block inside. If the Bumper is pressed the robot will turn right 90 degrees, else it will drive forward. To the right the comment reads 'Using a fixed distance to determine when to turn' with a repeat loop set to 4 to drive the robot in a 300mm square.

Look at the Repeating Actions (No Gyro) project (on the right) again. This project will repeat the forward and then turn behavior four times. A repeat block is used when you want to use a set of behaviors for a certain number of times. If the repeat block is replaced with a forever block, the robot would repeat the forward and then turn behaviors forever.

In the project on the left, a sensor's input is used to determine when to begin turning. The project on the right uses a fixed Drivetrain distance to determine when to begin turning.

In order to continually check a sensor's input, an if/else block is used together with a forever block. In the project on left, the robot will turn right when the BumperH sensor is pressed, otherwise the robot will drive forward forever if the BumperH sensor is not pressed. To continually check the BumperH sensor's value, the if/then block is within a forever block.

The above project on the left is a practical use-case of a structure that repeats forever - using forever blocks and if/then blocks together. Imagine a self-driving sweeper that continues to drive forward until it runs into a wall or object, then turns before continuing to drive.

Step 3: The Squared Loops Challenge!

Sketched path of the movement of the robot showing a green square with arrows indicating moving counterclockwise in a square. At each corner there is a doublesided orange arrow indicating a motion at this point in the path.

  • Have your Clawbot drive in a square.
  • Before each turn, the claw must be opened and closed, and the arm must be raised and lowered.
  • The Clawbot cannot drive along a side of the square more than once.
  • You can use the Repeating Actions (No Gyro) example project as a starting point but save it as SquaredLoops before making any changes.

Project name dialog box in the VEXcode IQ Toolbar. Slot 1 is selected and the project name reads Squared Loops.

In your engineering notebook, plan the following:

  • Plan out your solution and predict what each block in your project will have the Clawbot do.
  • Download and run your project to test it before submitting it.
  • Make changes to the project as needed and take notes about what was changed during testing.