Session 7: Adaptive Navigation with Interactive Commands
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
- Black tape for line path, markers for checkpoints, and small movable obstacles
Learning Objectives:
- Understand and apply conditional logic to respond to dynamic obstacles.
- Use the Web BLE remote client to gather real-time user input for decision-making.
- Program the bot to navigate checkpoints while responding to and reporting obstacles.
Session Outline
1. Introduction to Dynamic Navigation and User Inputs (10 minutes)
Activity:
Begin with a discussion on dynamic navigation and the challenges robots face with unpredictable obstacles. Explain how user inputs can help guide the robot when it encounters these situations.
Discussion Points:
You may say:
“Imagine you’re navigating through a crowded space, like a hallway with moving people. Sometimes you adjust your path to go around people, other times you might pause and wait to think what to do next. Today, we’ll code the robot to navigate checkpoints and handle obstacles, just like you would. But here’s the twist—you get to decide how it reacts! You’ll be the robot’s brains.”
- Introduce the Web BLE remote client, explaining how it allows for communication with the bot and sends it instructions, such as “Checkpoint reached” notifications. Introduce the new command
remote.askNumberto let the bot ask the user for specific directions when it encounters obstacles.
Teacher’s Role:
- Guide students to understand the concept of remote inputs and real-time decision-making.
- Help them grasp how conditional statements in programming allow for flexible responses to different situations.
2. Setting Up the Checkpoint Path and Connecting Web BLE (10 minutes)
Activity:
Demonstrate setting up a simple line path on the floor with marked checkpoints using tape and place movable objects as obstacles.
Instructions:
- Show students how to connect their bots to the Web BLE remote client.
- Guide them in testing basic commands, such as
remote.notifyto broadcast a “Connected” message to the client. - Explain that each time the robot reaches a checkpoint, it will use line sensor input to detect the marked spot and
remote.notifyto send a “Checkpoint Reached” message.
Teacher’s Role:
- Help students set up their line path with checkpoints and obstacles.
- Ensure they successfully connect their bots to the Web BLE client and practice using basic notifications.
3. Coding Checkpoint Navigation and Obstacle Detection (15 minutes)
Activity:
Walk students through writing code that enables their bot to follow the line, detect checkpoints, and recognize obstacles. This code will allow the bot to broadcast checkpoints and, when an obstacle is detected, stop and prompt the user for a decision.
Example Code:
#include <M3DGo.h>
void setup() {
go.begin(); // Initialize the robot
}
void loop() {
// Check if robot is on the line
if (line.onTheLine()) {
go.forward(50); // Move forward at 50% speed
display.text("Following line");
}
// Obstacle detection
if (range.get_cm() < 10) { // If obstacle is within 10 cm
go.stop(); // Stop the bot
display.text("Obstacle detected!");
remote.notify("Obstacle detected. Press 1, 2, or 3 to choose action.");
// Prompt user for action
float action = remote.askNumber("Choose action: 1-Turn Left, 2-Turn Right, 3-Turn Around");
// Execute based on user’s choice
if (action == 1) {
go.spinCounterClockwise(50); // Turn left
go.delay(1000);
} else if (action == 2) {
go.spinClockwise(50); // Turn right
go.delay(1000);
} else if (action == 3) {
go.spinClockwise(180); // Turn around
go.forward(50); // Continue forward
}
// Resume line following after adjustment
display.text("Resuming path");
}
}
Explanation:
You may say:
“This code allows the bot to follow a path, detect, and pause to take user input if it encounters an obstacle. By pressing a button, you can control whether it turns left, right, or turns around.”
Teacher’s Role:
- Help students understand each segment of the code, especially how the conditional statements manage the bot’s response.
- Encourage students to change values, such as the delay or distance threshold, to see how the bot’s behavior changes.
4. Interactive Challenges: Dynamic Navigation Practice (15 minutes)
Once students understand the code structure, encourage them to complete the following challenges to reinforce their learning:
Challenge 1: Obstacle Avoidance with Notifications
- Task: Program the bot to follow the line and pause to ask for user input if it encounters an obstacle. Notify each checkpoint reached and broadcast the response to the obstacle.
- Goal: Test user’s control over the bot’s reaction to dynamic challenges.
void loop() {
if (line.onTheLine()) {
go.forward(50);
display.text("Following line");
} else if (line.notOnLine()) {
remote.notify("Checkpoint Reached!");
go.delay(1000);
}
if (range.get_cm() < 10) {
go.stop();
float action = remote.askNumber("Choose: 1-Turn L, 2-Turn R, 3-Go Around");
if (action == 1) { go.spinCounterClockwise(50); }
else if (action == 2) { go.spinClockwise(50); }
else if (action == 3) { go.spinClockwise(180); }
go.delay(1000);
}
}
Challenge 2: Multi-Checkpoint Relay
- Task: Set up a path with multiple checkpoints and ask the bot to pause and notify each checkpoint reached.
- Goal: Observe how consistent navigation with user input helps manage long paths with obstacles.
void loop() {
if (line.onTheLine()) { go.forward(50); }
else if (line.notOnLine()) {
remote.notify("Checkpoint Reached!");
go.delay(1000);
float action = remote.askNumber("Choose action: 1-Turn L, 2-Turn R");
if (action == 1) { go.spinCounterClockwise(50); }
else if (action == 2) {
go.spinClockwise(50); }
go.delay(1000);
go.stop();
}
}
}
Challenge 3: Custom Directions
- Task: Program the bot to ask the user to enter a custom number when it reaches each checkpoint, using
remote.askNumber, then display the custom number on the bot. - Goal: Test user-bot communication and data handling in real-time.
void loop() {
if (range.get_cm() < 10) {
go.stop();
remote.notify("Obstacle - input required.");
float action = remote.askNumber("1-Turn L, 2-Turn R, 3-Go Around");
if (action == 1) { go.spinCounterClockwise(50); }
else if (action == 2) { go.spinClockwise(50); }
else if (action == 3) { go.spinClockwise(180); }
go.forward(50);
}
}
Teacher’s Role:
- Guide students in coding each challenge, helping them troubleshoot and fine-tune the robot’s response to each obstacle.
- Encourage creativity by suggesting different commands and conditions students can experiment with.
5. Reflection and Wrap-Up (5 minutes)
Discussion Questions:
- You may ask:
“How did user inputs help your bot navigate around obstacles?”
“What strategies did you find most effective for checkpoint navigation?”
“What would happen if we removed the user input and made all decisions automatically?”
Teacher’s Role:
- Conclude by reinforcing how real-time communication and decision-making play a role in robotics.
- Encourage students to share what they found challenging and how they overcame
it.
Learning Outcome:
By the end of this session, students will understand how to program a bot to navigate through dynamic obstacles with user input, apply conditional logic for interactive decision-making, and use the Web BLE remote client to enhance robot communication.