Create a robotic hand to move bricks using conditional statements
Questions to investigate
• How can we create conditional statement without using an if statement?
• Ensure SPIKE Prime hubs are charged, especially if connecting through Bluetooth.
(Group Discussion, 5 minutes)
Engage students in thinking about how robotic arms move. Share several images and videos of different types of robotics arms. Examples may include welding, manufacturing, shipping, picking, sorting.
Ignite a discussion with students on how the robotic arms move and work. Have students point out how the robotic arms are designed.
Shift the discussion to ask students if they have ever played the arcade game that uses a claw to grab a prize. Have students compare how this is similar and different to the robotic arms they studied. Discuss their ideas.
(Small Groups, 20 minutes)
Students will explore working with conditional statements to program a robotic hand to grab objects.
Direct students to the BUILD section in the SPIKE App. Here students can access the building instructions for Robotic Hand. Ask students to build the model. The building instructions are also available at https://education.lego.com/en-us/support/spike-prime/building-instructions listed as Pass the Brick.
Direct students to open a new project in the Python programming canvas. Ask students to erase any code that is already in the programming area. Students should connect their hub.
Use the Robotic Hand
Discuss ideas for making the Robotic Hand pick up objects like the claw machine. Think about ways to program the hand to open and close to pick up objects. Students should realize that they need to set a condition for what to do for the hand to be open or closed.
Share this sample program with students. Review the program as a group to ensure students understand how it will work. The program sets the condition to close the hand by pressing and holding the left button to close the hand. When released, the hand will open.
Students will need to type this program into the programming canvas. Students should run the program.
from spike import Motor, PrimeHub \# Initialize the Hub and motor hub = PrimeHub() motor = Motor('F') \# This will make the hand open once to start motor.run_for_seconds(1, 75) \# This will make the hand close when you press the Left Button on the Hub hub.left_button.wait_until_pressed() motor.set_stall_detection(False) motor.start(-75) \# This will make the hand open when you release the Left Button on the Hub hub.left_button.wait_until_released() motor.set_stall_detection(True) motor.start(75)
After students see how the program will work, ask students to remove all the 2x4 bricks from their set. Practice using the Robotic Hand as if it is the claw machine to pick up the bricks and move them. Note, the program is set to only work one time.
(Whole Group, 5 minutes)
Discuss with students how the program worked.
Ask students questions like:
• How does the program work?
• How is a conditional statement used in the program? What are the conditions?
• What is the line of code “motor.set_stall_detection()” used for?
• What are the true and false indicating in the program?
Point out to students that this is a conditional statement even though we do not use the if statement. Discuss why this is still considered a conditional statement. The program is using a condition to run the motor based on the button being pushed and released.
(Small Groups, 10 minutes)
Challenge students to play a relay game.
Have two groups work together to pass a brick from one Robot Hand to another. Group 1 should grab the brick, then turn to Group 2 and try to pass the brick to them. Then Group 2 can try to pass the brick back. Challenge students to see how many times they can pass the brick back and forth.
Discuss this challenge with students. Ask them if they need to change the program in any way. Students should recognize that they will need to be able to have the hand open and close more than one time. Prompt students to think about including a while loop in their program.
Allow students time to modify their program and run it. Remind students to watch the console for error messages.
from spike import Motor, PrimeHub \# Initialize the Hub and motor hub = PrimeHub() motor = Motor('F') \# This will make the hand open once to start motor.run_for_seconds(1, 75) while True: \# This will make the hand close when you press the Left Button on the Hub hub.left_button.wait_until_pressed() motor.set_stall_detection(False) motor.start(-75) \# This will make the hand open when you release the Left Button on the Hub hub.left_button.wait_until_released() motor.set_stall_detection(True) motor.start(75)
Allow students time to practice passing the bricks back and forth. Consider having the whole class try to pass one brick or a series of bricks through all groups as a final challenge.
Discuss the experience as a group. Ask students to define what a conditional statement is and different ways that you can create them. Students should recognize that a conditional statement is about setting condition in the program that can be true or false. In this example, the condition is set by “while True” indicating that the loop will continue as long as the condition is true. If the condition is not true, then the action will not happen.
(Group Exercise, 5 minutes)
Discuss the program with students.
Ask students questions like:
• How did the Robotic Hand react to the conditional statement?
• What are different ways to create conditional statements?
• How can you create a program that allows you to manually indicate if the condition is met or not?
Have students answer the following in their journals:
• What did you learn today about conditional statements and how to use them with loops?
• What characteristics of a good teammate did I display today?
• Ask students to rate themselves on a scale of 1-3, on their time management today.
• Ask student to rate themselves on a scale of 1-3, on their materials (parts) management today.
Soporte para el profesor
• Create a basic conditional statement.
• Program a grabber model based on set conditions.
• SPIKE Prime sets ready for student use
• Devices with the SPIKE App installed
• Student journals
2-CS-02 Design projects that combine hardware and software components to collect and exchange data.
2-AP-10 Use flowcharts and/or pseudocode to address complex problems as algorithms
2-AP-13 Decompose problems and subproblems into parts to facilitate the design, implementation, and review of programs.
2-AP-16 Incorporate existing code, media, and libraries into original programs, and give attribution.
2-AP-17 Systematically test and refine programs using a range of test cases.
2-AP-19 Document programs in order to make them easier to follow, test, and debug.