Cyber Robotics 101 Teacher's Guide
How do robots make decisions as a program is running?
This lesson introduces the conditional statement, a fundamental programming construct that allows computers to execute different commands based on conditions detected while the program is running. Students first investigate the if block and how it can be used to change what the program does based on whether the touch sensor is (or is not) triggered. They then learn how to use conditionals with color sensor data, and in conjunction with a repeat block, causing the program to continually check and respond to the current condition. These skills enable them to program the robot to follow a line drawn on the simulation floor, a classic task in robotics. Last, they use what they have learned to use the ultrasonic sensor to avoid moving obstacles.
Use an conditional statements to control the flow of a program
Combine conditionals and repeat loops to continually check a condition
Program a robot to follow a line on the ground
Use an conditional statements to control the flow of a program
Check for mission success in ‘Elliptical Troubles’ or ‘Incoming!’.
Combine conditionals and repeat loops to continually check a condition
Check for mission success in ‘Elliptical Troubles’. ‘Life on the Edge’ may be used as an alternate assessment. You may also use reflection question 2 to check student understanding of this programming construct.
Program a robot to follow a line on the ground
Check for mission success in ‘Elliptical Troubles’.
Slideshow: Decision Making
If block support article
Color sensor support article
Repeat Forever block support article
What’s one way that ‘Wait Until’ blocks are similar to ‘If’ blocks and one way that they are different?
Students should note that both ‘Wait Until’ blocks and ‘If’ blocks change the behavior of the program based on whether or not something is true. ‘Wait until’ blocks delay the execution of the next instruction until the condition is true, while ‘If’ blocks check only once, then execute an instruction ONLY if the condition is true (and sometimes execute a different instruction ONLY if it is false).
Why does the ‘If’ statement need to go inside a repeat loop in order to follow a line on the ground?
The ‘If’ statement only checks a condition once, so if the robot is to continually follow a line on the ground, it will need to check the condition inside the repeat loop that will repeat forever. This will cause the program to repeatedly check the condition as the robot moves through its environment.
Why might it be better to program a robot to follow a line rather than tell it exactly how to go somewhere?
Students should understand that line following allows robots to be more flexible in the types of environments that they can work. It is easier to program a robot to follow a line, then paint lines on the floors of its environments, than it is to individually program it to follow instructions for each environment in which it may find itself. Line following is a classic robotics task for this reason.
Description
Let students complete Missions: 1-5
Pack: Decision Making
Timing
15 minutes
Description
Go through slides 6-7
Timing
5 minutes
Description
Let students complete Missions: 6-9
Pack: Decision Making
Timing
20 minutes
Make sure students understand that If is not a loop, it runs only once - unless in a loop.
Remind students the ColorID values:
Q1. What does the If block require?
A1. A condition and an action to do for when the condition is met.
Q2. What is the Else for?
A2. Else can be used to determine the action (or actions) to perform when the condition is NOT met.
Q3. How can we check the condition repeatedly?
A3. We can place the If block inside a loop, like the Repeat Forever loop.