Skip to main content

STEM Labs
Loop, There It Is! Teacher

Teacher Portal

Teacher Tips - Purpose of this Activity

Programming repetitive behaviors can be accomplished by using repeat or forever loops. In short, repeat blocks allow the programmer to set a specific number of times for the blocks within its loop to repeat. The forever block repeats the blocks within its loop forever, or until the project is stopped. In this activity, students learn about both.

For more information about programming with repeat or forever loops, visit the help information within VEXcode V5.

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

• Watch the Using Loops tutorial video.

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

• Compare and contrast between forever and repeat blocks.

• Complete the Squared Loops Challenge that asks students to move the Clawbot in a square and to action the claw and arm before each turn.

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.

Teacher Tips

If this is the student's first time using VEXcode V5, they can also see the Tutorials in the toolbar to learn other basic skills.

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.

• View the opened example project.

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.

Teacher Toolbox - Answers

1. This project will have the robot drive forward for 300 millimeters and then turn right 90 degrees 4 times to complete a square. Instead of using the same 2 blocks 4 times, the repeat block reduces the same actions that 8 blocks would - into 3 blocks. The repeat block repeats the actions of driving forward and then turning.

2. The prediction might simply be "The Clawbot moves in a square." This would be a succinct way to capture the repeated movements of the Clawbot while lacking any context.

Students' engineering notebooks can be maintained and scored individually (Google Doc / .docx / .pdf) or as a team (Google Doc / .docx / .pdf). The previous links provide a different rubric for each approach. Whenever a rubric is included in educational planning, it is good practice to explain the rubric or at least give copies to students before the activity begins.

• Save, download, and run the Repeating Actions (No Gyro) example project.

• For help, see the tutorial in VEXcode V5 that explains how to Download and Run a 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 (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.

Extend Your Learning

To further explore how using loops with conditionals, build the Floor Sweeper example project in VEXcode V5.

• Begin by having the students mount and wire the bumper switches.

• Ask students to open the Clawbot (Drivetrain 2-motor, No Gyro) example project.

• Ask students to build the project above.

• Have the students save the project as Floor Sweeper.

• If students need help saving the project, refer to the Naming and Saving tutorial.

If the students need help with any of the blocks, refer them to the Help information or tutorial.

Ask the students to download and run the project to observe how the robot moves. Then, begin a class discussion and ask the students to explain why the forever block was used instead of a repeat block.

The students should note that a forever block is used because this project continuously checks to see if the bumper switch is being pressed.

### 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 Repeating Actions (No Gyro) example project 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 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.

Teacher Toolbox - Solution

The following is a potential solution to the Squared Loops Challenge:

You can provide students with a programming rubric for scoring their projects. Click one of the following links (Google Doc / .docx / .pdf)
Students' engineering notebooks can be maintained and scored individually (Google Doc / .docx / .pdf) or as a team (Google Doc / .docx / .pdf).