You have created projects with repeating behaviors using Forever blocks previously, but what if you wanted to repeat behaviors for a finite number of times? In this lesson, you'll learn about the Repeat block, and how it can be used to repeat code a specific number of times. Then you'll apply what you learned to code your VEX AIM Coding Robot to react to four AprilTag IDs as well as four different cargo objects.
Watch the video below to learn about:
- How the Repeat block works in a project
- Why to use a Repeat block instead of a Forever block in a project
Now that you have watched the video, capture your thoughts in your journal. Answer these questions to guide your thinking and help you prepare for a whole-class discussion:
- Why is it useful to be able to easily repeat behaviors in a project?
- What evidence from the video supports your answer?
- Think about your previous projects – would a Repeat block have been useful? Why or why not?
- What questions do you have about coding with a Repeat block?
Guided Practice
Now that you have watched and discussed the video, it's your turn to practice!
Step 1: Set up the field. Use the image below as a guide. AprilTags can be randomly placed in the corners, and cargo objects (sports balls and barrels) can be randomly placed in the center of each wall.
Step 2: Plan your project to make the robot react differently depending on the object or AprilTag ID detected. Together with your group, choose how you want your robot to react to each of the AprilTag IDs and objects on your field. Document your plan in your journal, and be specific.
- Use this task card (Google / .docx / .pdf) to guide you as you complete the activity.
- Pro Tip: Look at the orientation of the cargo objects and the AprilTags in relation to one another. Use what you know about headings and angles to help you repeat turning movements effectively.
Step 3: Code your robot to complete the activity, making sure it reacts differently depending on the AprilTag ID or object detected. Continue to use your task card.
- Pro Tip: You can use your project from the previous lesson as the basis for this one. Be sure to adjust your comments to match the intent of this project.
Resources for Practice:
The articles linked here are available if you need additional support while completing the activity.
Wrap-Up
Now that you have practiced, it is time to share what you learned. Answer the following questions in your journal to help you reflect on your learning and prepare for a whole-class discussion:
- How would you explain the difference between a Repeat and a Forever block to someone new to our class?
- How did you repeat behaviors in your project? Explain your rationale for the blocks you chose.
- What was the most challenging part of this project for you? How did your group work together to solve the problem?
- How did your group collaborate to plan and code your project? What has helped your collaboration to improve since the start of the course?
Select Next > to move on to the next lesson.