Students will explore using the force sensor to control movement.
Questions to investigate
• How can a force sensor be used to help control movements and actions?
• Ensure SPIKE Prime hubs are charged, especially if connecting through Bluetooth.
(Group Discussion, 5 minutes)
Engage students in a discussion about how to stop a charging rhinoceros. Consider viewing videos that show a rhino when charging or running into an object. Discuss how the rhino moves and what it would take to stop it. Also consider discussing the senses that the rhino might use and how these might be similar to the sensors that are available for students to program.
(Small Groups, 20 minutes)
Students will build a Rhino model to investigate different ways to move with the force sensor.
Direct students to the BUILD section in the SPIKE App. Here students can access the building instructions for the Rhino model. Ask students to build the model. The building instructions are also available at https://education.lego.com/en-us/support/spike-prime/building-instructions.
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.
Challenge students to have their rhino run forward. Start students with this program.
from spike import MotorPair \# Initialize the motor motor_pair=MotorPair('A','B') \# Run motor motor_pair.start()
Ask students to stop the program. Discuss the fact that there is nothing in the program that tells the Rhino to stop. Eventually, the Rhino runs into something.
Discuss ideas for making the rhino stop. One way is to add a stop to the program or set the start for a certain time, distance, etc. Another way is to use the force sensor attached as the Rhino’s nose.
Prompt students to stop the charging Rhino when he runs into the wall using the force sensor. Students should position the Rhino facing the wall or another strong object a foot or more away. Share this sample program with students. Students will need to type this program into the programming canvas.
from spike import ForceSensor, MotorPair \# Initialize the Force Sensor and a motor force_sensor = ForceSensor('C') motor_pair=MotorPair('A','B') \# Run motor until button is pressed then stop program motor_pair.start(0, -50) force_sensor.wait_until_pressed() motor_pair.stop()
Note: Remind students to watch for errors in the console. Students can reference the line from the error message to pinpoint where a typing error might have occurred.
Ask students to run the program several more times. Each time, the students should move the Rhino model further away from the wall. Allow students to investigate how moving the model further back does not change the way the program runs.
(Whole Group, 5 minutes)
Discuss with students how the Rhino model moved and review the code as a group.
Ask students questions like:
• How did the program work?
• What do the 0 and -50 represent in the motor_pair.start line of code?
• How did the force sensor work?
• What happened when you moved the Rhino further from the wall? Did running the model at different distances change the way the program worked?
• What was difficult about this challenge?
Discuss the use of a negative number (-50) for speed with students. The negative is providing direction for the movement. Having students change to a positive 50 will cause the Rhino to move in the other direction (backwards).
(Small Groups, 10 minutes)
Challenge students to change their program to investigate how the Rhino stops when he is charging (moving fast) versus when he is moving slowly.
Ask students to run their program two more times. Once with a high speed (-100 for power) and a low speed (-20 for power).
from spike import ForceSensor, MotorPair \# Initialize the Force Sensor and a motor force_sensor = ForceSensor('C') motor_pair=MotorPair('A','B') \# Run motor until button is pressed then stop program motor_pair.start(0, -20) force_sensor.wait_until_pressed() motor_pair.stop()
Discuss what happens after each program is run. Students should note that the Rhino just stops, while the force sensor is still touching the object, when set at 20% power. However, when set to 100% power, the Rhino hits the object and bounces back. Discuss as a group why this happens.
Allow students to build a small wall from the additional LEGO elements in their set. Challenge students to program the Rhino to charge through the wall and then play an appropriate sound. Students can also put a message in the console using the print() function to add the Rhino saying something as he hits the wall (ouch!).
Allow students to share and discuss their final programs.
(Group Exercise, 5 minutes)
Discuss the program with students.
Ask students questions like:
• How did your force sensor work to control your Rhino?
• Why does the power of the motor affect the way the model reacts when stopping with the force sensor?
• How did the force sensor provide information to the program to tell the Rhino what to do?
Have students answer the following in their journals:
• What did you learn today about using the force sensor to control your Rhino?
• 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.
Hỗ trợ giáo viên
• Explore the force senor
• Understand effects of power on movement
• SPIKE Prime sets ready for student use
• Devices with the SPIKE App installed
• Student journals
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.