Skip to main content

STEM Labs
Loop, There It Is! Student

The Clawbot V5 is ready to move!

This exploration will give you the tools to be able to start creating some cool projects that use loops.

  • VEXcode V5 instructions that will be used in this exploration:

    • Drivetrain.driveFor(forward, 300, mm);

    • Drivetrain.turnFor(right, 90, degrees);

    • ClawMotor.spinFor(reverse, 70, degrees);

    • ArmMotor.spinFor(forward, 360, degrees);

    • while (true) {}

    • repeat (4) {}

    • wait(5, seconds);

To access additional information, right click on a command name in your workspace to see help for that command.

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 (latest version, Windows, macOS)

1

Engineering Notebook

1

Clawbot Template (Drivetrain 2-motor, No Gyro) example project

Step 1:  Let's start programming with loops

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

     

  • Select File and Open Examples.

  • Scroll through the different Example projects. These projects demonstrate a variety of actions your Clawbot can perform. Select and open the Clawbot Template (Drivetrain 2-motor, No Gyro) example project.

     

  • Name the project RepeatingActions.

  • Type the following code:

Look over the project and then 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 project.

  • 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

Look at the Repeating Actions project (on the right) again. This project will repeat the forward and then turn behavior four times. A "repeat" loop structure is used when you want to use a set of behaviors a certain number of times.

If the repeat structure is replaced with a "while" loop structure, the robot will repeat the forward and then turn behaviors "while" the condition is true. You can also set the condition to "true" to have the "while" loop continue 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" statement is used together a "while" loop. In the project on left, the robot will turn right when the "BumperB" sensor is pressed, otherwise the robot will drive forward forever if the "BumperB" sensor is not pressed. To continually check the BumperB sensor's value, the "if" statement is within a "while true" loop.

The above project on the left is a practical use-case of a structure that repeats forever - using while loops and if statements 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!

  • 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 RepeatingActions project from above as a starting point but save it as SquaredLoops before making any changes.

In your engineering notebook, plan the following:

  • Plan out your solution and predict what each instruction 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.