Teacher Resources: Python with Robots MS Mission 7-3
Hot Pursuit Lesson 3: Chase and Catch
Students use proximity sensors to program CodeBot to track and chase a moving object, and apply abstraction by defining and calling functions.
Overview
In this final lesson of Mission 7, students combine motor control and proximity sensor data to program CodeBot to track and chase an object moving in front of it. They learn how to use a Boolean toggle variable and the not operator to add a safety feature, modify their code to make the 'bot chase instead of just track, and apply abstraction by defining and calling functions.
π― Mission Goal: Students will use proximity sensors to program the 'bot to track and chase an object.
Learning Targets
- I can apply previous knowledge of the motors to rotate and face an object moving in front of CodeBot.
- I can follow an algorithm to track an object.
- I can apply a safety feature by toggling a Boolean variable.
- I can follow an algorithm to chase an object.
- I can apply abstraction to the program by defining and calling functions.
Key Concepts
- Previous concepts of controlling CodeBot's motors apply directly with proximity sensors - including enabling motors and supplying power to the LEFT and RIGHT motors.
-
Both
prox.detect()andprox.range()return a tuple. Access the LEFT sensor withp[LEFT]and the RIGHT sensor withp[RIGHT]. -
The logical operator
nottakes one argument and can toggle a Boolean variable - useful for turning something on or off. - Functions are a form of procedural abstraction, a fundamental concept in programming and STEM.
Assessment Opportunities
- Mission 7 Lesson 3 Mission Log
- Submit completed program HotPursuit
- Mission 7 Obj. 8-11 Review Kahoot!
Success Criteria
- Access the LEFT and RIGHT proximity sensor detection reading
- Use motor controls in an if statement to track an object
-
Toggle the motors on and off using a Boolean variable and the logical operator
not - Modify the if statement to chase an object
- Define a function for driving the 'bot
- Define a function for toggling the motors
Digital Resources
Classroom Materials
- βΈCodeBot and USB cables
- βΈ4 AA batteries per CodeBot
- βΈSmall object for CodeBot to follow (paper cups work great - use paper, not plastic, about the width of the front of the 'bot)
- βΈVariety of objects - different shapes, sizes, and colors for testing
Real-World Applications
Review the real-world applications from Lesson 1. By the end of this mission, students can see how proximity sensors, auto-calibration, and movement are used in everyday electronic devices. Brainstorm more examples or discuss how these systems work together.
Extensions & Cross-Curricular
drive() function. Use a math operation with the variable for turning.
π€
Vocabulary
βΎ
π
New Python Code
βΎ
not logical operator to toggle the Boolean variable between True and False on each button press.
π
Standards
βΎ
CSTA Standards - Grades 6-8
- Look through the slides. Decide what materials you want to use for presenting the lesson. The slides can be projected on a large screen.
- Look over Objective 11 in CodeSpace and in the slide deck - they are different! You can skip Obj. 11 altogether, or decide which version you want students to complete.
- Be familiar with the mission log assignment and the questions students will answer. Prepare the assignment to give through your LMS.
- Have several objects of different shapes, sizes, and colors ready for the 'bot to follow. Paper cups (not plastic, about the width of the front of the 'bot) work well.
- If you have a word wall or another form of vocabulary presentation, prepare the new terms.
- Objective 11 in CodeSpace involves quite a bit of math and can be complicated. The slides introduce an alternative - discussing abstraction and having students write two functions from their current program. This is the only time when the coding in the slides will not match the CodeSpace objective. Since it's the last objective, after students finish you can unlock the Mission and they can continue with the mission pack.
- Movement is introduced in Objective 8, but the 'bot doesn't move forward until Objective 10. Students can test Obj. 8 and 9 on their desks or on the floor.
- In previous programs, a button press was used as a safety feature. Obj. 8 starts without one - but since the 'bot doesn't move forward yet, there's no danger. The safety feature is added in Objective 9.
- The slide deck version of Objective 11 introduces abstraction using a short Code.org video. You can find your own video or examples of abstraction as an alternative.
Lesson Outline
Students can write in their log first and then share, or discuss first and then write. These warm-up questions review CodeBot movement.
- Question: What code must be included before the motors of CodeBot will run?
- Question: What code will turn the 'bot to the left?
The Chrome browser works best, but other browsers also support CodeSpace. Each student will complete a Mission Log. Students can work in pairs or individually - continue with the same structure as the first two lessons.
prox.range() with sensed. An example is given. Students should answer the mission log questions.not and how to toggle a Boolean variable. They practice with problems in the mission log.global statement for its variable. The slide mentions this but doesn't show it - make sure students add that line.cal_power()). Extension 2: add button debouncing (sample code HotPursuit_ext3 includes both fixes). Extension 3: define a speed variable for the drive() function calls with a math relationship for turning (sample code HotPursuit_ext4 includes all three extensions).ποΈ Optional: Mission 7 Obj. 8-11 Kahoot! Review - a review Kahoot! is available for these four objectives.
The post-mission reflection asks students to review what they learned during this lesson. Answers can vary widely depending on each student's experience.
You can use a cross-curricular activity for a post-mission activity.
End by collecting the Mission 7 Lesson 3 Log.