Session: Object Handling and Task Sequencing with Servo Motors
Session Architect: Muhammad Bilal
Duration: 50-60 minutes
Objective:
In this session, students will learn to code the robot to autonomously navigate to a location, pick up an object using the dumper attachment, and deliver it to a designated spot. This will build on their knowledge of sensors, movement, conditional logic, and display usage while introducing servo motors to control attachments.
Equipment Required:
- M3D Robotics kit with dumper attachment
- Laptops with Arduino IDE pre-installed
- USB/OTG cables to connect the robot to the laptop
- Small objects for the robot to pick up and move
- Marked start, pickup, and delivery zones in the classroom
- Paper and pencils for students to plan and document their code
Learning Objectives:
- Understand the use of servo motors to control attachments.
- Program the robot to perform complex tasks by combining movement, conditionals, and sensor-based decision-making.
- Use the display to give feedback on the robot’s actions.
1. Introduction to Task Sequencing, Angles, and Object Handling (10 minutes)
Activity:
Begin with a discussion that combines their knowledge of angles and movement with the new concept of using angles in the dumper’s control to pick up and place objects. This sets the stage for understanding how they’ll be sequencing actions to complete complex tasks, like moving to a location, picking up an object, and delivering it.
Instructions:
- Review Previous Learning on Angles and Movement:
Begin with a question to recall their previous work with angles in movement:
“Last session, we learned how to control how much the robot turns by setting specific angles. Who remembers why angles helped us control movement more precisely?”
- Encourage students to share examples, such as turning accurately on paths or aligning to follow specific routes.
- Introduce Angle Control in Attachments:
Transition by asking:
“So, if angles helped us control how the robot turned, how do you think we might use angles to control the motor its attachments, like the dumper?”
- Explain that just as they set angles to steer the robot, they’ll use angles to control the motor’s movement to which will allow us to pick up and place objects using the attachments accurately.
- Link Angle Control to Object Handling:
Engage students with a scenario:
“Imagine the motor is set at 0 degrees when it’s closed tightly. If we want it to open slightly to pick up an object, what angle might we set?”
- Let students suggest possible angles, such as 30 or 45 degrees. Explain that this angle will allow the motor to open by a small amount, and returning it to 0 degrees will bring it back to it’s resting position.
- Task Sequencing with Movement and Object Handling:
Discuss the concept of a sequence in a task, such as moving to a spot, picking up an item, and delivering it. Ask:
“If you wanted the robot to move to a location, collect an object from you, and bring it somewhere else, what steps do you think we’d need to program?”
- Encourage students to outline a sequence: moving forward, adjusting the dumper’s angle to collect the object so that it’s doesn’t fall off, moving to a new location, and dropping it there.
- Introduce the Dumper Commands and Real-World Use Cases:
Explain that they’ll be using specific commands to set the dumper’s angle, similar to how they previously used commands for movement.
You may ask:
“Why do you think we might need different angles for collecting, holding, and releasing objects?”
- Encourage responses that consider how each action benefits from setting different angles for precision and control.
Teacher’s Role:
Guide students in combining their knowledge of angles with new applications for attachment control. Use questions to link the concepts of movement, turning, and precise object handling. Help students understand that task sequencing requires them to plan out each step, integrating movement and angle control to complete complex actions. This discussion will prepare them to use the dumper attachment with careful control over both movement and task order.
2. Introduction to Servo Motor Commands and Basic Display (10 minutes)
Activity:
The teacher will introduce students to the new servo motor commands for HingeA and HingeB. They’ll practice controlling the dumper to open, close, and adjust its angle.
Instructions:
- Introduce Servo Commands:
Explain each command and its purpose:
- **`hingeA.open();`** - Opens HingeA fully.
- **`hingeA.close();`** - Closes HingeA fully.
- **`hingeA.setAngle(45);`** - Sets HingeA to 45 degrees.
- Demonstrate how to use these commands in code, allowing students to experiment by lowering and raising the dumper attachment.
- Using Display to Track Actions:
- Explain that adding text to the display helps us know what the robot is doing at each step. For example:
display.text("Picking Up");shows on the screen when the dumper is lowered to pick up an object.
- Explain that adding text to the display helps us know what the robot is doing at each step. For example:
Ask the class:
“Why do you think showing messages on the display is helpful?”
- Encourage students to respond with ideas like “it helps track actions” or “it shows if the robot is doing what we expect.”
- Assist them in using the motor control commands so that they can get familiar with the syntax and how it works.
Teacher’s Role:
Demonstrate the commands, answer questions, and encourage students to try various angles and durations to see how these affect the dumper’s movement. Highlight the importance of combining display messages with actions for clear tracking.
3. Integrating Movement, Display, and Servo Control: Practice Challenges (20 minutes)
Activity:
Students will combine servo motor control with movement and display commands in a series of challenges. These tasks allow them to practice collecting, moving, and dropping off objects while displaying feedback.
Challenge 1: Moving to Pickup and Drop Off Spots with Display
Objective:
The robot will move to a designated pickup spot, lower the dumper to pick up an object, display “Picking Up” on the screen, then raise the dumper so that the object is secure, then move to the delivery spot, display “Dropping Off,” and lower the dumper to release the object.
Example Code:
void setup() {
go.begin(); // Initialize the robot
}
void loop() {
display.text("Moving to Pickup");
go.forward(50);
delay(2000); // Move forward for 2 seconds
go.stop();
display.text("Picking Up");
hingeA.setAngle(45); // Lower dumper to pick up
display.text("Moving to Delivery");
hingeA.close();. // Raise the dumper so that it's secure
go.forward(50);
delay(2000); // Move to delivery spot
go.stop();
display.text("Dropping Off");
hingeA.open(); // Open dumper to release
}
Teacher’s Role:
Encourage students to experiment with different delays, speeds, and display messages. Prompt them to observe if the display text matches each step.
Challenge 2: Detecting an Object and Displaying Status
Objective:
Use the distance sensor to detect an object. If an object is within 10 cm, the robot displays “Object Found,” lowers the dumper, and displays “Picking Up.” If no object is detected, it displays “Searching…” and keeps moving forward.
Example Code:
void setup() {
go.begin(); // Initialize the robot
}
void loop() {
if (range.get_cm() < 10) { // Check if an object is within 10 cm
display.text("Object Found");
go.stop();
hingeA.setAngle(45); // Lower dumper to pick up the object
display.text("Picking Up");
} else {
display.text("Searching...");
go.forward(50);
}
}
Teacher’s Role:
Guide students to test different distances and note how the display feedback changes based on proximity to the object. Encourage them to adjust the detection range and see the results.
Challenge 3: Sequential Pickup and Drop with Loop
Objective:
Use a for loop to repeat a sequence three times where the robot moves, picks up an object, displays each action, moves again, and drops the object.
Example Code:
void setup() {
go.begin(); // Initialize the robot
}
void loop() {
for (int i = 0; i < 3; i++) {
display.text("Moving to Pickup");
go.forward(50);
delay(2000);
go.stop();
display.text("Picking Up");
hingeA.setAngle(45);
display.text("Moving to Delivery");
go.forward(50);
delay(2000);
go.stop();
display.text("Dropping Off");
hingeA.open();
}
}
Teacher’s Role:
Assist students in setting up the loop and explaining that each loop repeats the entire sequence. Help them troubleshoot if the sequence does not run as expected.
Challenge 4: Conditional Pickup Based on Distance and Display Update
Objective:
If the robot detects an object within 15 cm, it displays “Object in Range,” picks up the object, and displays “Object Picked Up.” If not, it displays “No Object” and moves forward slowly.
Example Code:
void setup() {
go.begin(); // Initialize the robot
}
void loop() {
if (range.get_cm() < 15) { // Detect if an object is within 15 cm
display.text("Object in Range");
hingeA.setAngle(45); // Lower dumper to pick up object
display.text("Object Picked Up");
} else {
display.text("No Object");
go.forward(30); // Move slowly forward if no object
}
}
Teacher’s Role:
Encourage students to try different ranges and see how the display and dumper behavior change based on object detection.
Challenge 5: Line Following with Pickup and Delivery
Objective:
Students program the robot to follow a line to a pickup spot, close the dumper to pick up an object, display “On the Line” while following, and finally move to a delivery spot to drop off the object.
Example Code:
void setup() {
go.begin(); // Initialize the robot
}
void loop() {
if (go.onTheLine()) {
display.text("On the Line");
go.forward(50); // Move forward if on line
} else {
go.stop();
display.text("Picking Up");
hingeA.close(1); // Close dumper at pickup spot
display.text("Heading to Delivery");
go.forward(50);
delay(2000);
go.stop();
display.text("Dropping Off");
hingeA.open(1); // Open dumper to release object
}
}
Teacher’s Role:
Guide students through the line-following process and ensure they understand how to use the display and hinge commands in tandem with the line sensor.
4. Reflection and Wrap-Up (5 minutes)
Conclude the session with a group discussion:
- “What did you find challenging about using the servo motor commands?”
- “How did the display text help you track the robot’s actions?”
- “What other tasks can you imagine programming with this sequence of actions?”
Encourage students to share insights and discuss how combining sensors, motors, and display feedback enhances the robot’s capability to perform complex tasks autonomously.
Learning Outcome:
By the end of the session, students will have a strong understanding of how to use servo motors for precise actions with attachments, integrate sensor data and movement, and use display feedback for task tracking. They’ll also gain experience in task sequencing, applying their code in a more comprehensive and real-world setting.