Teacher Resources: Python with Robots MS Mission 7-3

Mission 7-3 Lesson Plan

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.

⏰ 45-50 min 🎯 Grades 6-8 πŸ’» CodeSpace πŸ€– CodeBot 🐍 Python
View Lesson Outline
πŸ“‹

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() and prox.range() return a tuple. Access the LEFT sensor with p[LEFT] and the RIGHT sensor with p[RIGHT].
  • The logical operator not takes 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

β˜‘οΈ

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
🧰

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.

πŸ›•Touchless faucets, soap dispensers, and hand dryers
πŸšͺAutomatic doors
πŸš—Vehicle navigation and safety systems
🏭Factory automation systems
πŸš€

Extensions & Cross-Curricular

ExtensionAfter Obj. 7, the code can still throw an error if the 'bot is not under a surface. Fix the bug using an if statement.
ExtensionAdd code to debounce button presses.
ExtensionDefine a variable for speed and use it when calling the drive() function. Use a math operation with the variable for turning.
STEMHave a class lesson on abstraction. Let students come up with and present their own examples of abstraction in the real world.
Lang ArtsHave students write a story about an electronic device that uses proximity sensors and moves - either how helpful it is, or how things might go wrong.
Lang ArtsHave students write an opinion piece about technology and its effects on society.
Lang ArtsSupports language arts through reading instructions, guided notes, and reflection writing.
πŸ”€

Vocabulary

β–Ύ
Toggle - Flip from True to False, or False to True; on to off or off to on.
Not - A logical operator used to toggle a Boolean variable.
Abstraction - The process of removing unnecessary details from something to reduce it to a set of essential characteristics.
🐍

New Python Code

β–Ύ
if p[LEFT] and p[RIGHT]: motors.run(LEFT, 40) motors.run(RIGHT, 40) elif p[LEFT]: motors.run(LEFT, 0) motors.run(RIGHT, 20) elif p[RIGHT]: motors.run(LEFT, 20) motors.run(RIGHT, 0) Control the motors based on which proximity sensors detect an object - move forward if both detect, or turn toward the side that detects.
go_motors = False Define a Boolean variable to toggle the motors enabled on/off.
if buttons.was_pressed(0): go_motors = not go_motors Use the not logical operator to toggle the Boolean variable between True and False on each button press.
motors.enable(go_motors) leds.user_num(go_motors) Use the Boolean toggle variable to turn the motors and a user LED on or off.
πŸ“

Standards

β–Ύ

CSTA Standards - Grades 6-8

2-DA-08 2-DA-09 2-AP-10 2-AP-11 2-AP-12 2-AP-13 2-AP-14 2-AP-16 2-AP-17 2-AP-18 2-AP-19
πŸ“
Preparing for the Lesson
  • 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.

πŸ§‘β€πŸ«
Teacher Notes
  • 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

πŸ’‘Lesson Tips and Tricks
πŸ’‘ Teaching tip: You can use a variety of discussion strategies for maximum engagement. For example, have students write their answers before anyone shares aloud, or use a think-pair-share method. Having students compare answers with a peer before sharing with the class works well for this lesson.
πŸ—£οΈWarm-up / Hook - Slide 2

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?
πŸ’»Mission 7 Lesson 3 Activities

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.

πŸ’‘ Teaching tip: Mission Introduction - Slides 3-6. This lesson completes the last two goals of the mission. Students answer one question in their mission log.
πŸ’‘ Teaching tip: Objective 8 - Slides 7-10. These slides show how to access LEFT and RIGHT proximity sensor readings, similar to prox.range() with sensed. An example is given. Students should answer the mission log questions.
πŸ’‘ Teaching tip: Objective 8 Algorithm - Slides 11-12. These slides go over the tracking algorithm and show the code for each step. It's fairly straightforward.
πŸ’‘ Teaching tip: Objective 8 Activity - Slides 13-17. Students open HotPursuit and add code. The full algorithm code is provided. Slide 17 suggests experimenting with different tracking speeds - this is optional. Note: students don't include a safety feature yet, but since the 'bot doesn't move forward here, there's no danger.
πŸ’‘ Teaching tip: Objective 9 - Slides 18-20. Students learn about not and how to toggle a Boolean variable. They practice with problems in the mission log.
πŸ’‘ Teaching tip: Objective 9 Algorithm - Slides 21-22. These slides go over the algorithm for toggling a Boolean variable and show the matching code. Straightforward.
πŸ’‘ Teaching tip: Objective 9 Activity - Slides 23-27. Students modify their code to add a button-press toggle as a safety feature. The slides walk through the coding and testing process.
πŸ’‘ Teaching tip: Objective 10 - Slide 28. Students modify the program to chase instead of just track.
πŸ’‘ Teaching tip: Objective 10 Activity - Slides 29-31. Students modify the if statement for moving forward. They also test with objects of different shapes, sizes, and colors and record results in the mission log. This is a great time to try a paper cup on its side to see if the 'bot follows it as it rolls.
πŸ’‘ Teaching tip: Objective 11 Introduction - Slide 32. Introduces the modified Objective 11 used in the slides. Note: If you are following the CodeSpace instructions for Objective 11, do not use the slides from here on.
πŸ’‘ Teaching tip: Objective 11 Abstraction - Slides 33-36. These slides cover abstraction with a short video and examples. You can skip ahead to the code, or take time to discuss and explore abstraction with students.
πŸ’‘ Teaching tip: Objective 11 Activity - Slides 37-43. Students define two functions using pre-existing code. Important: The function on slide 42 requires a global statement for its variable. The slide mentions this but doesn't show it - make sure students add that line.
πŸ’‘ Teaching tip: Extensions - Slides 44-47. Three extensions are available. Extension 1: fix the bug from Lesson 2 (add an if statement to 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.

πŸ§‘β€πŸ§‘Post-Mission Reflection

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.

U