[RL87] Grade 8 - Session 7

Grade 8 - Session 7: Follow the Leader – Reactive Robotics

Session Length: 60 minutes


Learning Objectives:

In this session, students will:

  1. Use Platform IDE to program their robot to follow a “leader” robot, reacting based on distance sensor readings.
  2. Explore how delay settings affect the robot’s responsiveness, adjusting delays in code to optimize performance.
  3. Experiment with distance-based conditions for different actions, such as moving closer, stopping, and moving backward.
  4. Display distance readings and express various emojis on the robot display based on distance thresholds.
  5. Learn about response time in sensors and how real-time robotics applications face challenges with sensor and communication delays.
  6. Design the robots so any one of them can become the leader based on position in the queue.

Equipment Required:

  • M3D Robotics kits with distance sensors and displays
  • Laptops with Platform IDE and Web BLE setup
  • Projector (optional, to demonstrate live coding or display sensor values)
  • Stopwatch for reaction time activity
  • Worksheet for recording observations, testing delays, and exploring response times

1. Introduction to Reaction Time and Robotics Delay (10 minutes)

Activity – Reaction Time Test:
Start the session with a quick reaction time activity:

You may ask:

“Have you ever tried to react as quickly as possible to a signal? Let’s see how fast we can respond to sudden signals.”

Use a stopwatch to call out a signal like “Go!” and measure students’ reaction times. Record their times on the board.

Discuss Robotics and Sensor Response Time:

You may explain the recorded measurements as follows:

“Just like we have a reaction time, our robots also have a delay in processing sensor readings and responding to them. Today, we’ll explore how reducing this delay affects the robot’s ability to react in real time.”

Engagement Question:

“How quickly do you think our robots can respond to a command? What happens if the delay is too long or too short?”

Encourage students to think about the impact of delay on the robot’s performance, especially in following a leader.


2. Initial Programming: Distance-Based Movement and Displaying Sensor Values (15 minutes)

Activity – Displaying Sensor Values and Basic Movement:
Students will start by coding the robot to:

  1. Display the current distance sensor reading on the robot display.
  2. Use this reading to determine movement, as follows:
    • If distance > 25 cm: Move closer (forward).
    • If distance between 10-15 cm: Stop.
    • If distance < 10 cm: Move back slightly.

Programming Steps:

  1. Setting Up Distance Sensor Display:

    #include <M3DGo.h>
    
    void setup() {
        go.begin();
        display.begin();
        range.begin();
    }
    
    void loop() {
        int distance = range.get_cm();  // Get distance in cm
        display.print(distance);         // Display distance on screen
        delay(1000);                     // Initial delay of 1000ms
    }
    
  2. Adding Conditional Movement Based on Distance:
    After displaying distance, students will add movement commands:

    void loop() {
        int distance = range.get_cm();
        display.print(distance);
        
        if (distance > 25) {
            go.forward(50);      // Move forward if distance > 25 cm
        } else if (distance >= 10 && distance <= 15) {
            go.stop();           // Stop if distance between 10-15 cm
        } else if (distance < 10) {
            go.backward(30);     // Move backward if distance < 10 cm
        }
        
        delay(1000);  // Initial delay of 1000ms, to be reduced in later steps
    }
    

Teacher Prompt:
Encourage students to observe the response time of the robot as it changes direction based on the distance, noting any delays in the movement response.


3. Adjusting Delay and Observing Responsiveness (15 minutes)

Activity – Reducing Delay in Steps:
Students will gradually decrease the delay in increments (1000ms → 100ms → 50ms → 10ms) and observe changes in responsiveness.

Questions for Students During Each Delay Change:

  • At 1000ms Delay:
    “How long does it take for the robot to respond to a change in distance? Does it seem slow or fast?”

  • At 500ms Delay:
    “Does the robot respond more quickly now? What happens if you decrease it even further?”

  • At 100ms Delay:
    “With only a 100ms delay, how does the movement of the robot change? Is it more accurate in following the target?”

Final Step – Removing Delay Completely:
Students will remove the delay altogether to test real-time response:

   void loop() {
       int distance = range.get_cm();
       display.print(distance);

       if (distance > 25) {
           go.forward(50);
       } else if (distance >= 10 && distance <= 15) {
           go.stop();
       } else if (distance < 10) {
           go.backward(30);
       }
   }

Teacher Explanation:

You may explain:

“Without any delay, the robot can read sensor values continuously, making it respond almost instantly. However, even without delay, there’s still a small lag because the robot’s microcontroller takes a tiny amount of time to read the sensor and send commands.”

Real-World Connection:

“This is similar to automated systems in cars that brake when a vehicle is too close. These systems also have to minimize delay to keep passengers safe.”


4. Coding Follow-the-Leader and Emoji Expressions (15 minutes)

Activity – Implementing “Follow-the-Leader” and Adding Emojis:
Students will code the robot to follow another “leader” robot, expressing different emojis based on proximity.

New Movement and Emoji Expressions:

  1. Moving Closer: If distance > 25, move closer and display “Joy” Emoji.
  2. Stopping: If distance is between 10-15, stop and display “Confused” Emoji.
  3. Moving Back: If distance < 10, move back slightly and display “Frustrated” Emoji.

Code Example:

void loop() {
    int distance = range.get_cm();
    display.print(distance);

    if (distance > 25) {
        go.forward(50);
        display.show("Joy");  // Happy emoji when moving closer
    } else if (distance >= 10 && distance <= 15) {
        go.stop();
        display.show("Confused");  // Neutral emoji when stopping
    } else if (distance < 10) {
        go.backward(30);
        display.show("Frustrated");  // Worried emoji when too close
    }
}

Making Any Robot the Leader

Encourage students to code their robots so that any robot can become the leader simply by positioning it at the front of the line.

Teacher Discussion Prompt:

  • “Why do you think it’s useful for any robot to be able to take on the role of leader?”
  • “How could this flexibility be beneficial in a warehouse or factory with multiple automated robots?”

Students can test this by moving their robots around to try different configurations, noting that whichever robot is in front becomes the leader by proximity.


5. Wrap-Up and Reflection (5 minutes)

Teacher Question:

“What changes did you notice in the robot’s response as we reduced the delay? How does the robot’s reaction time compare to your own?”

Real-World Examples:

“Think of this in terms of real-life situations, like self-driving cars. Why do you think it’s important to minimize delay in those scenarios?”

“Can you think of other places where robots might need to follow one another or respond quickly to changes in distance?”

Conclusion:
Wrap up by emphasizing that response time is crucial in robotics for applications where timing and accuracy matter, such as safety systems in vehicles or automated factories. Highlight how students have built foundational skills in real-time sensing and response programming using loops and conditional logic, preparing them for advanced robotics projects.


Learning Outcomes:

By the end of this session, students will have:

  • Gained experience in using for loops and conditional statements to optimize robot responsiveness.
  • Learned how sensor delays impact real-time robotic applications.
  • Understood the importance of adjusting sensor reading intervals in automated systems to improve reaction time.
  • Programmed their robot to interact using conditions, movement, and expressive emojis, making coding both functional and fun.