Session 8: Data-Driven Bot – Analyzing Performance through Data Logging
Duration: 50-60 minutes
Equipment Required:
- M3D Robotics kit (M3D Go)
- Laptops with Arduino IDE and Web BLE setup
- USB/OTG cables to connect the robot to the laptop
- Projector for live coding demonstration
Learning Objectives:
- Understand how to log real-time sensor data and interpret trends.
- Learn to store and use variables for capturing sensor readings.
- Visualize sensor data on the Web BLE client to observe performance trends and optimize bot behavior.
- Recognize how data analysis benefits scientific and real-world applications.
1. Introduction to Trend Observation with Clapping Graph Activity (10 minutes)
Activity:
The teacher will guide students through creating a real-time “Clapping Graph,” illustrating how changes over time are represented visually as trends. This hands-on activity introduces students to the concept of trend lines and plotting, making it both fun and intuitive.
Instructions for Activity:
- Setting Up the Graph:
-
Draw a large graph on the board with the x-axis labeled “Number of Groups Clapping” and the y-axis labeled “Claps Heard.”
-
Mark intervals of 5 on both axes to keep the scale consistent (e.g., 5, 10, 15…).
You may say:
“We’re going to create a graph together based on something simple and fun: clapping! As each group starts clapping, we’ll mark down the number of claps we hear. Each group will add more sound, and we’ll see how this builds up on our graph.”
- Grouping the Class:
-
Divide students into small groups of 5 and have them sit together as a team.
-
Explain that each group represents a “clapping unit” that will add to the sound level, allowing everyone to see how each additional group affects the overall sound.
You may say:
"Think of each group as a ‘clap contributor.’ When each group starts clapping, they make the sound louder. We’ll track that change on our graph to see what it looks like visually.”
- Starting the Clapping and Marking the Graph:
-
Begin with the first group. Ask them to clap while the rest of the class observes. Count the claps and mark the first point on the y-axis at “5 claps.”
-
Then, add a second group, so two groups are clapping together. Mark this increase by plotting the next point at “10 claps.”
-
Continue adding one group at a time, noting each increase by plotting the corresponding point on the graph. Progress up both axes in steps of 5 until all groups are clapping together.
You may say:
“With each new group, we’re adding more sound, just like in science where we observe change over time or as conditions shift. Each clap count on our graph shows how the sound level grows.”
- Connecting the Dots to Show the Trend:
- Once all the points are marked, connect the dots to create a line. Explain how this line represents a trend in the data, showing that as each group adds claps, the sound increases in a consistent pattern.
You may say:
“By connecting these points, we’re creating a line that shows a trend—a pattern that helps us see how the sound grew with each new group. If we had even more groups, this line shows us what we’d expect: the clapping sound would keep rising along the same path.”
- Explaining the Trend and Graph Interpretation:
- Conclude by discussing how this pattern, or trend, shows up in various real-life situations and why it’s useful for analyzing data over time.
You may say:
“Trends help us make sense of data by showing us patterns—like when studying the weather or tracking scores. Our clapping graph shows us that each group added sound, and that pattern can help us predict or understand what happens with more groups. This is why trends are helpful in science and math!”
Teacher’s Role:
- Lead students in observing the plotted points and help them understand how these points represent a consistent upward trend.
- Reinforce that recognizing trends in data helps us visualize changes, analyze information, and make predictions about real-life situations.
2. Introduction to Variables and Data Storage (10 minutes)
Activity:
Discuss the use of variables as containers for storing data that changes over time. Introduce key variables like distance, speed, and line sensor values, showing how these values help track and analyze bot movement.
Instructions:
- Define a simple variable in code, such as
int distance = range.get_cm();, and explain how it temporarily stores data. - Demonstrate how this value can be updated continuously, reflecting real-time changes during the bot’s movement.
Example Code:
#include <M3DGo.h>
int distance; // Variable to store distance value
void setup() {
go.begin();
remote.connect(); // Ensure remote client is connected
}
void loop() {
distance = range.get_cm(); // Store range finder value in variable named "distance"
int leftpath = line.getLeft(); // Store the value of Left IR sensor of the line sensor
int rightpath = line.getRight(); // Store the value of right IR sensor of the line sensor
go.delay(500);
}
Teacher’s Role:
- Explain that storing values in variables lets the bot “remember” information and share it with the user in real-time.
- Guide students in setting up variables for the distance, line sensor readings, or other parameters they’ll track.
3. Plotting Data on Web BLE Client (10 minutes)
Activity:
Introduce the plotting feature of the Web BLE client, showing students how to view changing data in real-time. Highlight the value of visualizing data to track trends, helping them understand changes as the robot moves or detects obstacles.
Example Code for Plotting:
#include <M3DGo.h>
int distance;
int leftpath;
int rightpath;
void setup() {
go.begin();
remote.connect();
}
void loop() {
distance = range.get_cm();
remote.indication1.plot("Distance (cm)", distance); // Plot distance
remote.indication2.plot("Left Line Sensor", leftpath); // Plot left line sensor value
remote.indication3.plot("Right Line Sensor", rightpath); // Plot left line sensor value
go.forward();
go.delay(500);
}
Teacher’s Role:
- Demonstrate how plotted data provides a visual story of the robot’s movement and sensor readings.
- Emphasize how trend analysis applies to multiple fields, like weather forecasting, stock market analysis, or biology.
- Show how the real-time data reflects the robot’s environment and actions, prompting curiosity about what might cause sudden changes in readings.
4. Hands-On Challenges: Logging and Observing Data Trends (20 minutes)
Challenge 1: Obstacle Avoidance Distance Plotting
- Task: Code the robot to move forward and stop whenever it detects an obstacle within 15 cm. Plot the obstacle distance each time the robot encounters one, helping students see trends in how often and where obstacles are encountered.
- Goal: Visualize how distances change as the robot navigates through obstacles.
Example Code:
#include <M3DGo.h>
void setup() {
go.begin();
}
void loop() {
if (range.get_cm() > 15) {
go.forward(50);
display.text("Moving...");
} else {
go.stop();
int distance = range.get_cm(); // Record obstacle distance
display.text("Obstacle at " + String(distance) + "cm"); // Show obstacle distance on the robot's screen
remote.indication1.plot("Obstacle Distance", distance); // Plot obstacle distance
delay(1000);
go.reverse(50); // Back up a little
delay(500);
go.spinClockwise(50); // Adjust direction
delay(500);
go.forward(50); // Start moving again
}
}
Challenge 2: Line Position Tracking
- Task: Program the robot to follow a line, plotting whether it’s on the line, left of it, or right of it every second. This will show the trend of adjustments the robot makes to stay on course.
- Goal: Observe how often the robot needs to correct its position to stay on the line.
Example Code:
cpp
Copy code
#include <M3DGo.h>
void setup() {
go.begin();
}
void loop() {
int position = 0;
if (line.onTheLine()) {
go.forward(50);
display.text("On the line");
position = 0; // 0 for on the line
} else if (line.leftOfLine()) {
go.spinClockwise(20);
display.text("Adjusting Right");
position = -1; // -1 for left of line
} else if (line.rightOfLine()) {
go.spinCounterClockwise(20);
display.text("Adjusting Left");
position = 1; // 1 for right of line
}
delay(1000); // Check every 3 seconds
remote.indication1.plot("Position Adjustment", position); // Plot position
}
Advanced Challenge: Gradual Speed Reduction Plot
Task:
Program the robot to start moving at 100% speed and gradually reduce its speed in increments of 10 every 2 seconds until it comes to a complete stop. Plot each speed level as it decreases to visualize the robot’s speed reduction over time.
Goal:
Observe the trend in the robot’s speed as it slows down, and understand how changing values over time are represented in a plot.
Example Code:
#include <M3DGo.h>
void setup() {
go.begin(); // Initialize the robot
}
void loop() {
// Start at 100% speed and decrease by 10% every 2 seconds
for (int speed = 100; speed >= 0; speed--) {
go.forward(speed); // Set the robot's speed
display.text("Speed: " + String(speed) + "%"); // Display current speed
remote.indication1.plot("Speed Reduction", speed); // Plot speed reduction
go.delay(2000); // Wait for 2 seconds before the next decrement
}
go.stop(); // Stop the robot once it reaches 0% speed
display.text("Stopped"); // Display stopped message
while (true); // Hold the robot at a stop
}
Questions to Explore:
- What trend do you see on the plot as the speed decreases?
- How does increasing or decreasing the delay time affect the speed reduction trend?
- What happens to the trend line if you reduce the speed in smaller increments, like 5%?
Teacher’s Role:
- Guide students in understanding how to set up the plot and observe changes.
- Encourage them to experiment with delay times and decrement values, discussing how these changes affect the plotted speed reduction trend.
- Reflection and Wrap-Up (5 minutes)
Discussion Questions:
You may ask:
- “What patterns did you see in the plots? Did anything surprise you?”
- “How could tracking data help make better decisions, not only for robots but in other situations?”
- “If you wanted to improve the robot’s performance, what data would you analyze and why?”
Teacher’s Role:
- Emphasize how trends help in both robotics and other areas, prompting students to think creatively about data’s role in decision-making.
- Reinforce the session’s concepts, encouraging students to consider data logging in scientific experiments or real-life projects.
Learning Outcome:
By the end of this session, students will understand how to log and analyze real-time data from their bot, gaining insight into sensor performance and trends. They will recognize the importance of data analysis for optimizing decisions in robotics and other scientific fields.