Teacher Resources: Python with Robots MS Mission 9-3

Mission 9-3 Lesson Plan

All Systems Go! Lesson 3: Orientation & Motion

Students use the accelerometer to monitor physical orientation and detect motion, then build a GuardBot that triggers an alarm on any movement.

⏰ 45-50 min 🎯 Grades 6-8 💻 CodeSpace 🥇 CodeBot 🐍 Python
View Lesson Outline
📋

Overview

In this final lesson of Mission 9, students explore the accelerometer - a tiny chip that measures force in three dimensions. They write programs that read axis values, use orientation data to keep CodeBot pointed up on an incline, and apply proportional rotation speed for smoother control. They also build a GuardBot that detects any motion and sounds an alarm.

🎯 Mission Goal: Students will use input sensors to monitor physical orientation and detect motion.

🎯

Learning Targets

  • I can use system sensors to monitor physical orientation.
  • I can use physical orientation to detect motion.
💡

Key Concepts

  • The accelerometer detects orientation in three dimensions. CodeBot can be programmed to act on conditions based on its orientation.
  • The accelerometer can also detect motion. Any slight movement can be detected and used to trigger an alarm.

Assessment Opportunities

☑️

Success Criteria

  • Print the 3-axis values from the accelerometer
  • Write basic code that keeps CodeBot pointed up
  • Improve the basic code for better control using proportional rotation speed
  • Detect motion on the X-axis
  • Detect motion on all 3 axes
🧰

Classroom Materials

  • CodeBot and USB cable
  • 4 AA batteries per CodeBot
  • Sturdy surface on an incline - a yearbook, shoebox, cardboard box, or textbook works great
🌍

Real-World Applications

Many electronic devices use an accelerometer for orientation and navigation, including:

📱Cell phones and smart watches
🎮Game controllers
🚘Vehicles and navigation systems
🚀

Extensions & Cross-Curricular

ExtensionFall Detector. Use the accelerometer to detect if the 'bot is falling.
ExtensionBump Bot. Move the 'bot forward until it detects an impact, then rotate a random amount and go again.
ScienceResearch the accelerometer - its parts, how it works, and what devices use it.
ScienceHave a lesson on gravity - its measurement and how it relates to the accelerometer.
MathThis lesson uses delta (Δ) to find the difference between two readings. Explore how delta is used in math.
Lang ArtsSupports reading through instructions, guided notes, and reflection writing.
🔤

Vocabulary

Orientation - The relative position of something.
Accelerometer - A tiny chip that measures the force of acceleration in 3 directions: x, y, and z.
Navigation - Knowing where you are and planning and following a route for where you want to be.
Oscillate - Move or swing back and forth at a steady speed.
Proportional - Change at the same rate.
Incline - Sloping upward.
🐍

New Python Code

accel.dump_axes Prints the 3-axis values to the console.
x, y, z = accel.read() Reads the current axis values and returns a tuple of integers, ranging from -32767 to +32768.
now = accel.read() Read the accelerometer and assign all three values to a tuple.
now[0] Access the X value of the accelerometer reading.
before = now Assign the same tuple (now) to a new variable (before).
dx = now[0] - before[0] Calculate the difference between the current reading and the previous reading.
if abs(dx) > SENS: alarm() If the difference between readings is greater than the sensitivity threshold, sound an alarm.
📐

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-19
📝
Preparing for the Lesson
  • Look through the slides. Decide what materials you want to use for presenting the lesson. The slides can be converted to Google Slides and projected on a large screen.
  • Be familiar with the mission log assignment and the questions students will answer. Prepare the assignment to give through your LMS.
  • This lesson requires a sturdy surface on an incline. A large book (like a yearbook), a shoebox, or a piece of cardboard propped up works well. The surface doesn't need to be big - CodeBot isn't moving up it, just trying to stay pointed up.
  • If you have a word wall or another form of vocabulary presentation, prepare the new terms.

🧑‍🏫
Teacher Notes
  • This lesson follows the instructions in CodeSpace fairly closely. It is chunked into smaller bits of information and simplified for clarity.
  • The code in this lesson is similar to CodeTrek, simplified a little for ease of typing and organized similarly to previous missions. All goals will be met.
  • Objectives 9 and 10 require an inclined surface. A yearbook, shoebox, cardboard box, or textbook all work. Recommend a small surface that can be picked up and tilted for Obj. 10.
🗺️

Lesson Outline

💡Lesson Tips and Tricks
Teaching tip: You can use a variety of discussion strategies to get the most engagement from your students. For example, have students write their answers before anyone shares. Use think-pair-share, or have students compare answers with a peer before discussing as a class.
🗣️Warm-up / Hook - slide 2

Students can write in their log first and then share, or discuss first and then write. The warm-up previews the lesson content.

  • Question: What do you know about gravity?
  • Question: What are the three dimensions in our world?
💻Mission 9 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.

Teaching tip: Mission Introduction - slides 3-4. This mission is divided into three lessons. This lesson completes the last two goals. Students answer one question in their mission log.
Teaching tip: Objective #8 - slides 5-7. The accelerometer is introduced.
Teaching tip: Objective #8 - slides 8-10. Discussion on gravity and its measurement, and how this relates to the accelerometer. Look over the slides and decide if you need to add anything.
Teaching tip: Objective #8 Activity - slides 11-14. Students write a simple program that prints the 3-axis values to the console. They try CodeBot in different orientations and record the readings in the mission log.
Teaching tip: Objective #9 - slides 15-18. Students learn how CodeBot is oriented and how to use accelerometer readings to point the 'bot up.
Teaching tip: Objective #9 Activity - slides 19-24. Students modify the program to use CodeBot's orientation to keep the nose pointed up. They need a sturdy surface on an incline. The 'bot will wiggle and end up at the bottom, but no forward movement is made. Students answer one question in the mission log. Note: Students add the safety feature from Mission 4 (wait for a button press before enabling the motors) - review as needed.
Teaching tip: Objective #10 - slides 25-27. Students learn how to improve their program with proportional rotation speed. This section has some math. If the math looks too difficult, you can skip the slides and just do the program, or skip the objective and move on. Decide what works best for your students.
Teaching tip: Objective #10 Activity - slides 28-31. Students modify the program to include proportional rotation speed. Speed needs to be around 50 or higher to see significant change. If the surface is small enough, students can pick it up and tilt it in several directions - the 'bot should always work to maintain its nose pointed up. They answer one question in the mission log.
Teaching tip: Quiz - slide 32. The quiz has four questions about reading the accelerometer.
Teaching tip: Objective #11 - slide 33. Students are given an application for using the accelerometer: the GuardBot.
Teaching tip: Objective #11 Algorithm - slides 34-38. The algorithm for the program is given. The program involves a couple of new concepts, so each step is discussed and exact code is provided on the slides.
Teaching tip: Objective #11 Activity - slides 39-42. Students start a new GuardBot program and define a function for sounding the alarm. They can make the alarm any way they want. Sample code is provided, but they don't have to follow it exactly.
Teaching tip: Objective #12 - slide 43. The program is expanded to include all three dimensions. This is a very short objective.
Teaching tip: Objective #12 Activity - slides 44-48. Students improve their program to include all three dimensions and add parameters to the alarm() function to display the differences in each axis.
Teaching tip: Extensions - slides 49-50. Two extension ideas are given (medium and spicy difficulty). They are optional. Solutions for the extensions are not available.
Teaching tip: Post-Mission - slides 51-52. These slides sum up the mission by applying it to the real world.

🗝️ Optional: Mission 9 Obj. 8-12 Kahoot! Review is available for these four objectives.

🧑‍🤝‍🧑Post-Mission Reflection

The post-mission reflection asks students two reflection questions. Answers can vary widely.

You can use a cross-curricular activity as a post-mission activity.

End by collecting the Mission 9 Lesson 3 Log.