Loading…
Loading…

Level : Advanced
(Note : this lesson introduces the computer vision interface and is intended for students advanced in this specific area. It also assumes prior experience with FTC Sim. Students and teachers should have already completed the standard introductory lessons and be familiar with using the platform and programming robot movements.)
In this lesson, students will apply their knowledge of robot vision and AprilTag data to solve a real-world challenge. Unlike previous lessons where the robot responded to static data, students will now program their robot to continuously monitor AprilTag properties while it is in motion. Using the Vision Portal, they will track changes in position and orientation data, such as distance, angle, and heading, and use that data to make real-time decisions. This dynamic approach introduces students to more advanced autonomous behaviours, where the robot adapts its actions based on real-time data from its environment.
This lesson plan is structured around the 5E instructional model, a widely recognized teaching model that includes five phases: Engage, Explore, Explain, Elaborate, and Evaluate. The 5E instructional model consistently engages students in inquiry-based learning, encouraging active exploration and understanding of complex topics.
During the lesson, students will:
track AprilTag properties such as location and orientation while the robot is moving;
use real-time data from the Vision Portal to guide the robot's behaviour and solve a challenge;
apply functions and conditional logic to create responsive, efficient and adaptive robot code.
removable sticky notes or a collaborative brainstorming app such as Microsoft Whiteboard, FigJam or Apple Freeform
devices for your students (Windows computers, Mac computers, Chromebooks)
Google Chrome or Microsoft Edge (Chromium version) web browser
access to the FTC simulator website (https://ftcsim.org)
"student" account created for each of your students
projector or interactive whiteboard
To spark students' curiosity and show them how robots can react to visual data in real time, begin the lesson by showing them the video of a FIRST Robotics team demonstrating AprilTag tracking, available at the following address: https://youtu.be/XA15Qq2CXY0?si=DPBT4jvFr9Edxztc. In the video, a team member moves an AprilTag around a robot, and the robot actively follows the tag based on its position and orientation.
This demonstration shows how robots can monitor AprilTag properties such as distance, angle and orientation while they move and adapt their behaviour accordingly. It lets students explore how their own robot can use AprilTag data in real time to make decisions as it moves, leading to more advanced and adaptive autonomous behaviours.
After the video presentation, hand out removable sticky notes to your students and encourage them to take part in a brainstorming session on how robots can use real-time AprilTag data, such as changes in distance, angle and orientation as they move, to make smarter decisions. Ask students to write one idea per sticky note that answers the question: "How could a robot use real-time AprilTag data while moving to solve a real-world problem?" Assign them a designated area on the classroom wall where they can post their ideas. Once they have come up with several ideas, ask them to gather at the sharing space to post their removable sticky notes. If an idea has already been posted on the wall, they can place theirs on top of the existing one, whereas if the concept has not yet been posted, they must find an available spot to display it.
Here are some of the ideas they may come up with:
A robot that follows a person by detecting a tag placed on their backpack.
A warehouse robot that adjusts its path in real time to avoid obstacles while following a moving target.
A drone that keeps its camera focused on a moving object using the tag's orientation.
A robot that moves through a maze by continuously adjusting its direction based on data provided by the tag.
A delivery robot that lines up with a moving drop-off point.
A robotic arm that adjusts its grip when the object changes position.
Lead a discussion by asking thought-provoking questions:
How can a robot use real-time AprilTag data to adjust its movements while it is moving? (e.g., it can continuously update its direction, slow down or speed up, and stay aligned with a moving target.)
Why is it important for a robot to monitor both the location and orientation of a tag while it moves? (e.g., it helps the robot stay on course, avoid drifting and react accurately to changes in the tag's position.)
What types of challenges require a robot to react in real time to changes in tag data? (e.g., following a moving object, navigating dynamic environments or adapting to changing obstacles.)
How does using real-time AprilTag data improve a robot's ability to solve complex tasks compared to using static data? (e.g., it allows continuous feedback and adjustment, making the robot more adaptive and more accurate.)
What problems could arise if a robot did not update its tag data while moving? (e.g., it could lose track of the target, misalign its path or fail to complete the task accurately.)
In which real-world situations could this type of reactive robot behaviour be particularly useful? (e.g., delivery robots that follow moving delivery points, rescue robots that track survivors or drones that film moving subjects.)
Can you imagine creative or unexpected ways robots could use real-time AprilTag data while moving? (e.g., robots playing chase games, guiding people through crowded areas or adjusting lighting or camera angles during a show.)
Encourage students to begin their hands-on learning experience with the FTC Sim platform by going to the link provided, https://ftcsim.org/. Have them log in using their unique username and password. Once logged in, they will need to use the following link to load the workspace they will need for the lesson: https://ftcsim.org/puzzle/epdxxxaqbqa/

In this FTC Sim world, zoom in on the robot to clearly show students the mounted camera and the omni wheels.

How many AprilTags do you see? How many AprilTags do you think your robot sees right now? What could the robot do to detect more? (e.g., the robot probably sees only one tag because the other is out of its field of view. To detect the second tag, it would need to pivot or turn to change the angle of its camera.)
Have students create functions for each type of movement, as they did in the second lesson.
Move straight forward
Move straight backward
Turn left
Turn right
Slide right
Slide left
This approach lets students call a single function each time they want the robot to perform one of these movements, instead of rewriting the motor code every time. It is recommended to use slower speeds (50 % or less instead of 100 %) for greater precision. Here is an example of what their code might look like.

Remind students that simply creating the functions is not enough to run them. The functions must be called from the main code right after Simulator.waitForStart.

Next, your students need to create the initialization to activate the Vision Portal and AprilTag recognition. They will use the same blocks as in the first lesson. They must add them to the initialization section of the code, before the call to Simulator.waitForStart(). These blocks are found in the "Vision" section.

Depending on your students' grade level and coding experience, you may choose to explain the role of each line of code. If this seems too advanced for your group, you can simply provide the complete initialization sequence and focus the lesson on how the robot recognizes AprilTags in the next step. This lets students become familiar with the basic concept without being overwhelmed by the setup details.
Students should now test the code by pressing "Run." Have students click the small arrow in the bottom left corner of the screen. This opens the robot's camera view.

Then, have students add the "turn left" function to their code so that the robot begins to pivot in place. Once the code is updated, have them run the program and watch the camera preview window. As the robot turns, students should see it make a full 360 degree turn (and more), revealing its surroundings. This movement should allow the robot to see both AprilTags, which were previously out of view.

Ask students: "Why do you think these two AprilTags were placed in these specific locations?" (e.g., the first tag shows where the robot must pick up the purple block, and the second tag shows where it must drop it off. This helps the robot locate itself and position itself accurately for both actions.)
Students must now make sure the robot keeps running while the program is active. To do this, they will use a conditional statement that checks whether Simulator.OpModeIsActive is true. Inside this condition, they must place a loop that will keep running as long as OpModeIsActive is true.

Students must now create a variable that will store a list of all the AprilTags the robot can see through its camera. In this simulation, the robot should detect only one tag at a time, because the other tags are positioned behind the tower and out of view. The variable will be named AllDetections and will help the robot keep track of the AprilTags currently visible.

Students must now assign a value to the allDetections variable using AprilTagProcessor to get the list of detected tags. To do this, they must add blocks that call AprilTagProcessor and retrieve the current detections. The blocks they add to their code should look like the example below.

It is now time for students to determine how many AprilTags the robot is currently detecting. To do this, they must check the length of the list that contains all the detected tags. This list, named AllDetections, contains all the AprilTags the robot can see through its camera at that moment.
By using a block that measures the length of the list, students can determine how many tags are visible. This is a useful way to check whether the robot detects a single tag, several tags or no tags, especially when it moves and its field of view changes.

Students must press "Run," then click "Show Telemetry" to see the robot's sensor data. As the robot turns, they will notice that the number of visible AprilTags changes in the telemetry display. It may go from zero to one, then back to zero, then to one again, depending on which tag is currently in the robot's field of view. This helps students understand how the robot's orientation affects what it can detect.

Students can add the code to display the ID. They will need to retrieve each tag from the list using the "For each item in list AllDectections" loop, then use AprilTagDetection.id.

By running the code and examining the telemetry data, they should see the AprilTag ID displayed each time a tag is detected. Students should find that the ID of the AprilTag above the purple cube is 14 and that of the one above the target pad is 15.

Students will now begin to explore other data they can get from AprilTag detection, such as ftcPose.x, ftcPose.y, ftcPose.z, ftcPose.yaw, ftcPose.pitch, ftcPose.roll, ftcPose.range, ftcPose.bearing and ftcPose.elevation.

Here is how they can display the angle data:

Have students run the code and watch the telemetry display as the robot starts turning left. While it turns, they should pay close attention to the angle value shown. They will notice that the angle changes gradually, generally varying between about 30 degrees and -30 degrees depending on the robot's orientation. Help them understand that when the angle value is close to zero, the robot is probably facing the AprilTags directly. This observation helps students understand how angle data can be used to align the robot with a target while moving.

Students must now add a conditional statement to their code that checks whether the robot's angle is less than or equal to zero. If this condition is met, the robot must stop moving. To do this, students will need to create a custom stop function that sets the power of all four motors to zero, effectively stopping the robot's movement. This step helps students understand how to use sensor data to control the robot's behaviour in real time and reinforces the importance of using functions to keep their code organized and efficient.

Students will observe that the robot stops when the AprilTag is positioned directly in the centre of the camera's field of view. At that moment, the Telemetry display should show an angle value very close to zero degrees, which means the robot is correctly aligned with the tag. Students may notice that the angle value shown in Telemetry is slightly below zero when the robot stops. This is explained by a slight delay between the moment the robot detects that the orientation has reached zero and the moment it applies the brake. To improve accuracy and bring the robot closer to the target angle, students can modify the code so that the robot turns more slowly. This would give it more control and reduce overshooting.

Invite students to add comments to their code to explain the different coding blocks they used. Comment blocks are blue and are found in the "Miscellaneous" section. Explain that computer engineers work in teams and must document their code with comments to make sure their colleagues can understand what their code means. Here is an example of the second version of the code for the second challenge with comments added.

Have students share their solutions to the challenges by asking them reflection questions, such as:
What does your robot need to know to line up with an AprilTag?
How do the robot's movements affect what it can see through the camera?
What happens to the angle value when the robot turns? How can you use this data?
Why is it useful to monitor the AprilTag data while the robot is moving rather than just once at the start?
How did you decide when the robot should stop turning?
What does an angle value close to zero tell you about the robot's position?
How did you use conditional logic to make the robot react to the sensor data?
What challenges did you run into when you tried to stop the robot?
How did adjusting the robot's speed affect its accuracy?
What does the length of the AllDetections list tell you while the robot is turning?
How did you use the AprilTag ID to decide what the robot should do?
What other tag properties could you use to improve the robot's performance?
Encourage students to take on the challenge by adding the final steps to their code. First, they must program the robot to move closer to the purple cube using the "range" property, which indicates the straight-line distance between the robot's camera and the AprilTag. Once the robot is close enough, they must use the gripper mechanism (servo motors introduced in the first lesson) to grab the cube.
Next, students must use the second AprilTag (ID 15) to guide the robot to the target zone and place the cube there, completing the challenge. To do this efficiently, students will need to monitor and respond to certain AprilTag properties that provide valuable data about positioning and orientation:
range: straight-line distance between the camera and the centre of the tag, usually measured in centimetres. It is ideal for controlling forward and backward movements.
bearing: angle between the robot's current direction and the tag. A positive value means the tag is to the right; a negative value means it is to the left. It is useful for controlling side-to-side movements.
yaw: rotation of the tag itself, similar to turning your head to the left or to the right. This helps the robot line up perfectly in front of the tag for precise positioning.
Assess
Assessment of the lesson should be done through observations and conversations with students while they code. To evaluate the effectiveness of the lesson, observe how students interact with the FTC simulator, how they apply the Vision Portal and AprilTag recognition concepts, and how they use the different properties.
Engage students in a constructive dialogue about their thought processes, challenges and strategies. This will help you better understand their perception of how camera vision and AI influence robot decision-making. These interactions will also allow you to provide targeted feedback and adapt your teaching to support learning.
Here is a list of "benchmarks" to guide your observations and assessment:
Engagement and curiosity: Are students actively experimenting with live AprilTag data while the robot moves? Are they curious about how changes in distance, angle and orientation affect the robot's behaviour?
Understanding of real-time AprilTag data: Can students explain how properties such as range, bearing and yaw influence the robot's movement and alignment? Do they understand how these values change as the robot moves?
Use of conditional logic and functions: Are students using conditional structures to allow the robot to react to sensor data in real time? Are they applying functions to organize and reuse movement and control code efficiently?
Problem solving and adaptation: Are students adjusting their code based on what they observe in the telemetry? Are they refining the speed, direction or movement logic to improve accuracy and responsiveness?
Use of telemetry for live feedback: Are students monitoring the telemetry display to track AprilTag properties, and are they using this data to guide the robot's decisions? Are they interpreting the values correctly during movement?
Movement precision and control: Do students demonstrate mastery of the robot's movements by using slower speeds and refined logic to align with tags and meet the challenge?
Code documentation and communication: Are students adding clear, relevant comments to explain their code? Are they able to explain how their robot uses AprilTag data to make decisions?
Resilience and iteration: How do students react when the robot overshoots the target, becomes misaligned or fails to detect a tag? Do they persevere in testing, debugging and improving their solution?
This approach ensures that assessment is based not only on the final result, but also on the learning process, experimentation and the thoughtful application of new concepts.
C3.1 solve problems and create representations of mathematical situations using computational thinking by writing and executing code, including code that involves conditional statements and other control structures.
C3.2 read and alter existing code, including code that involves conditional statements and other control structures, and describe how changes to the code affect the outcomes.
C3.1 solve problems and create representations of mathematical situations using computational thinking by writing and executing efficient code, including code that involves conditional statements and other control structures.
C3.2 read and alter existing code, including code that involves conditional statements and other control structures, and describe how changes to the code affect the outcomes and efficiency.
C3.1 solve problems and create representations of mathematical situations using computational thinking by writing and executing efficient code, including code that involves events influenced by a defined count and/or sub-program and other control structures.
C3.2 read and alter existing code, including code that involves events influenced by a defined count and/or sub-program and other control structures, and describe how changes to the code affect the outcomes and efficiency.
C3.1 solve problems and create representations of mathematical situations using computational thinking by writing and executing code, including code that involves analysing data in order to make and communicate informed decisions.
C3.2 read and alter existing code that involves analysing data in order to make and communicate informed decisions, and describe how changes to the code affect the outcomes and efficiency.
C2.1 use coding to demonstrate an understanding of algebraic concepts, including variables, parameters, equations, and inequalities.
C2.2 create code to decompose situations into computational steps to represent mathematical concepts and relationships, and to solve problems.
C2.3 read code to predict its outcome, and alter code to adjust constraints, parameters, and outcomes for a similar situation or for a new situation.
C2.1 use variables, constants, expressions, and assignment statements to store and manipulate numbers and letters in a program.
C2.2 develop programs that use and generate data in various formats and from various sources.
C2.3 develop programs that include simple and nested conditional statements.
C2.4 develop programs that include sequential, selected, and repeated events efficiently.
C2.5 develop programs that include the use of Boolean operators, comparison operators, text operators and arithmetic operators.
C2.6 interpret programming errors, and implement strategies to correct them.
C2.7 write clear internal documentation and use coding standards to improve the readability of code.