Session 9: Bot Communication – Cooperative Tasks
Session Architect: Muhammad Bilal
Session Length: 50 - 60 minutes
Objective:
In this session, students will explore inter-robot communication through collaborative task sequencing, where two bots work together to pick up and transfer an object. This session introduces students to the concept of real-time interaction between robots using sensors and task synchronization. They’ll learn how to program their bots to respond to each other’s actions and coordinate tasks like object transfer and synchronized movement.
Equipment Required:
- Two M3D robots with line sensors and distance sensors
- Laptops with Arduino IDE
- USB/OTG cables for connecting the robots
- Dumper and forklift attachments for the robots
- Black tape to create a line for the path
- Small objects for pick-up and transfer tasks
1. Introduction to Cooperative Tasks and Communication (5 minutes)
Activity:
Begin with a discussion on teamwork and task-sharing, drawing parallels to how we collaborate by taking turns and handing off tasks. Then, connect this to how robots can communicate using sensor readings.
Instructions:
- Class Discussion
Ask students:
“Have you ever seen a relay race? How does the other person know it’s their turn in a to start running?”
- Guide them to recognize that in a relay, they wait for a signal (like the previous runner reaching them and handing them the object) to start their part.
- Encourage them to highlight the important elements in a relay race.
- Relating to Robots
Explain that robots can similarly work together and “wait” for signals from each other through sensor data.
- Introduce the concept of using distance sensors as a form of “communication” where one bot’s action depends on the position of the other.
- Ask them if they can think of ways the robots can communicate with each other or “sense” each other’s presence.
- Lead them to the answer that robots can use sensors to detect each other.
Teacher’s Role:
Lead students in understanding how teamwork can be programmed into robots, where each bot responds to another’s position or action. Highlight that by using distance sensors, the robots can detect each other and synchronize their tasks without human intervention.
2. Setting Up Robot Roles and Assigning Tasks (5 minutes)
Activity:
Students will assign specific roles to each robot, where one bot becomes the “carrier” (first robot) and the other the “transporter” (second robot).
Instructions:
- Defining Roles
- Explain that the first robot(carrier) will pick up the object, follow the line, and transfer it to the second robot(transporter).
- The second robot will detect the first robot’s arrival, take the object, and carry it to the drop-off point.
Since both ports of the robot will be occupied:
- The first one would have forklift and line sensor.
- The second one has dumper and range finder.
So, students can utilize remote.notify() to display different actions e.g. “I’m moving!”, “Line Ended”, “Dumping!” etc.
- Sensor Setup and Testing
- Have students set up the distance sensors on one and line sensor on the other robot.
- Ask them to test if their distance sensors can detect each other as the robots approach, reinforcing the idea of sensor-based communication.
Teacher’s Role:
Guide students in setting up the roles, ensuring they understand the task sequence and each robot’s responsibilities. Help them test the distance sensors to confirm detection accuracy.
3. Programming the First Robot: Object Pickup and Line Following (15 minutes)
Activity:
Students will program the first robot to pick up an object, follow the line path, and wait at the end for the second robot to arrive.
Instructions:
-
Line Following and Object Pickup
- Program the first robot to follow the line using the line sensor commands (
line.onTheLine(),line.leftOfLine(),line.rightOfLine()). - Attach the object using the forklift and code it to hold the object.
- Program the first robot to follow the line using the line sensor commands (
-
Stop and Transfer
- Use the distance sensor on the second robot to signal when the first robot has arrived.
- Program the first robot to raise its forklift attachment when the robot reaches the end of the line.
Example Code:
void setup() {
go.begin();
hingeA.close(); // Lower forklift to pick up object
}
void loop() {
if (line.onTheLine()) {
go.forward(50); // Move forward along the line
} else if (line.leftOfLine){
go.spinClockwise(30); // Adjust direction to the right to stay on the line
} else if (line.rightOfLine) {
go.spinCounterClockwise(30); // Adjust direction to the left to stay on the line
}
if (line.notOnLine()) { // When it reaches the end of the line
go.stop();
hingeA.open(); // Lift forklift to transfer object
}
}
Teacher’s Role:
Assist students in programming the line-following and object pick-up tasks. Reinforce how sensor feedback (distance detection) signals the robot to stop and transfer the object.
4. Programming the Second Robot: Object Pickup and Delivery (15 minutes)
Activity:
Students will program the second robot to detect the first robot, lower its dumper to receive the object, then carry it to the delivery point.
Instructions:
-
Waiting for Signal and Object Pickup
- Program the second robot to lower its dumper upon detecting the first robot’s arrival.
-
Moving to Drop-Off Point
- Once the first robot leaves, program the second robot to follow the line and deliver the object to a designated point.
- When the distance sensor detects the end (e.g., an obstacle), have the robot stop,turn around and dump the object.
Example Code:
void setup() {
go.begin();
hingeA.open(); // Prepare dumper to receive object
}
void loop() {
if (distance.get_cm() < 5) { // Detect first robot arrival
hingeA.open(); // Lower dumper to collect the object
}
if (distance.get_cm() > 10) { // First robot has left
hingeA.close(); // Raise the dumper to secure the object
go.forward(50); // Move to delivery point
}
if (distance.get_cm() < 5) { // Detect end point
go.stop();
go.spin(180);
hingeA.open(); // Dump the object
}
}
Teacher’s Role:
Guide students in understanding the second robot’s code logic and encourage them to test their program. Reinforce the concept of waiting for signals and using distance sensor data to control behavior.
5. Testing and Debugging (10 minutes)
Activity:
Teams will run their complete program to observe how each robot performs the assigned tasks. They’ll use this time to identify any issues in task sequencing or sensor response, making necessary adjustments to improve performance.
Instructions:
-
Run Initial Tests
- Allow students to test the robots together, paying close attention to how each robot behaves at each stage (e.g., line-following, object transfer, detecting arrival and departure).
- Encourage them to document any points where the robots struggle or stop responding correctly.
-
Debugging Tips
- If issues arise, suggest the students check specific areas, such as:
- Sensor Accuracy: Are the distance sensors consistently detecting the other robot at the correct points? Encourage them to use both
range.getcm()for distance sensor andline.getLeft()andline.getRightalong withremote.notify()to show the real-time values of the sensor on the screen. - Timing and Positioning: Are the robots positioned correctly to transfer the object smoothly?
- Task Order: Does each robot start and stop as expected, based on the sensor input?
- Sensor Accuracy: Are the distance sensors consistently detecting the other robot at the correct points? Encourage them to use both
- If issues arise, suggest the students check specific areas, such as:
-
Adjusting Code
- Encourage students to make small adjustments and re-test, refining their code to improve synchronization and task completion.
Teacher’s Role:
Guide students in observing each step of the process to pinpoint any issues. Provide troubleshooting tips, helping them refine their code for smoother inter-robot communication and task sequencing.
6. Reflection and Wrap-Up (5 minutes)
Activity:
After testing, students will gather to reflect on the experience of programming two robots to collaborate. They’ll discuss the challenges of inter-robot communication and how sensor data influences task execution.
Instructions:
-
Prompt Discussion Questions:
- “What did you find most challenging about making the robots work together?”
- “How did the distance sensors help each robot know when to perform its part of the task?”
- “What would you change or add to make the collaboration even smoother?”
-
Summarize Key Learnings:
- Recap the importance of sensor data in enabling robots to detect conditions in real-time.
- Highlight how sequencing actions based on other robots’ responses can make complex tasks possible.
Teacher’s Role:
Encourage students to share their experiences, insights, and any creative ideas they have for improving inter-robot communication. Reinforce the value of task sequencing and sensor-based decision-making in robotics.