VR - Mission 12: King of the Hill

Mission 12 Lesson Plan

King of the Hill

Students use accelerometer data to monitor CodeBot's orientation, visualize it with formatted strings, and drive the 'bot up and down a hill by remote control and autonomously.

⏰ 2-4 hours 🎯 Grades 9-12+ πŸ’» CodeSpace πŸ€– Virtual CodeBot 🐍 Python
View Lesson Outline
πŸ“‹

Overview

In this mission, students put CodeBot's accelerometer to work. They print raw accelerometer data to the console three different ways, then convert that data into angles using trigonometry so CodeBot can "know" how it's tilted. From there, students build a live bar graph visualization using string formatting, drive the 'bot up a hill by remote control with button presses, and finish by programming CodeBot to climb the hill and dodge obstacles on its own.

🎯 Mission Goal: Students will use data from the accelerometer to "Master the Hill."

🎯

Learning Targets

  • I can print accelerometer data to the console in three different ways.
  • I can use internal sensors to monitor physical orientation by converting data to angles.
  • I can create a data visualization using string replacement fields, format specifiers and escape sequences.
  • I can control the 'bot using buttons for input.
  • I can program the 'bot to make decisions based on data.
πŸ’‘

Key Concepts

  • The accelerometer detects orientation in three dimensions.
  • Data can be printed as a string using formatting such as replacement fields indicated with { } and format specifiers.
  • Special characters can be displayed using escape sequences.
  • Data from the accelerometer can be converted to angles, either in radians or degrees. This data can then be used to make decisions.
  • The CodeBot can be programmed to act on conditions based on its orientation.
βœ…

Assessment Opportunities

  • Quiz after Objective 1
  • Quiz after Objective 5
  • Code Tracing Chart as a debugging tool
  • Use the Debugger to track variables
  • Give students code snippets from an objective and have them explain what it does
  • Give extra practice with string formatting
  • Submit CodeBot remote control program (Objective 4 or Objective 6)
  • Submit CodeBot autonomous program (Obj. 8)
  • Mission 12 Review Kahoot!
β˜‘οΈ

Success Criteria

  • Read and print data from the accelerometer.
  • Convert accelerometer data to an angle using trigonometry.
  • Use button presses as input to remote-control the CodeBot.
  • Display a bar graph visualization of the data.
  • Program CodeBot to drive autonomously up and down a hill with obstacles.
🧰

Classroom Materials

  • β–ΈComputer or Chromebook with internet access
🌍

Real-World Applications

🧭Accelerometer data can be converted into angles, used to compute pitch, roll and yaw. This data navigates ships, aircraft and robots, and is a key element of autonomous devices. Discuss devices that have an accelerometer and how it's used to make decisions.
πŸ“ŠThis mission showed how to visualize data with a type of bar chart. Data visualization is used in many devices, from cars, to video game displays, to battery indicators. Discuss data visualization in a variety of devices.
πŸš€

Extensions & Cross-Curricular

ExtensionUse the remote-control program on a physical CodeBot and a sloping surface.
ExtensionUse the autonomous program on a physical CodeBot and obstacle course.
ExtensionAdd LEDs and sounds to indicate CodeBot's progress. Count every obstacle encountered, or keep track of time or distance and indicate forward progress. Add beeps for obstacle detection or when backing up.
Lang ArtsHave students write a summary of their mission. Explain the purpose and function of the program, and who the intended users are.
MathThe mission uses trigonometry and angles. Discuss radians and degrees, and have a lesson on the Pythagorean theorem. There are many math applications with this lesson.
ScienceThe accelerometer measures gravity. Have a lesson on gravity, including gravity in space and on other planets.
πŸ”€

Vocabulary

β–Ύ
Accelerometer:A tiny chip that measures the force of acceleration in three directions: x, y and z.
MEMS:Micro-Electro-Mechanical System; a chip with tiny silicon structures inside that really move, with electronic components to sense them.
Vector:A mathematical or geometric representation of magnitude and direction. Examples of vectors in nature are velocity, momentum, force, and weight.
Math module:A scientific calculator for your code; a module that includes a set of mathematical functions and constants.
Replacement fields:A template for formatting a string by using { } to designate where and how to print the values of variables.
Format specifiers:Information added inside the replacement field that dictates how to display a number.
Escape sequences:A way to insert special characters in a string; begins with a backslash \.
Hexadecimal:Base 16. A single hex digit holds exactly 4 bits of information and ranges from 0 to 15. In an escape sequence, a hex value is designated with \x.
Autonomous:A device that can sense its environment and respond to change.
🐍

New Python Code

β–Ύ
x, y, z = accel.read() Read the current axis values of the accelerometer.
accel.dump_axes() Print the 3-axis values to the debug console. The display: X=-1044, Y=4261, Z=-15786
pitch = math.asin(y/16384) Calculate the radians from accelerometer data.
pitch = pitch * 180 / math.pi Convert radians to degrees.
pitch = round(pitch) Round a value to the nearest integer.
bars_left = bars_right = '' Cascaded assignment; assigns two variables to the same value.
dash="[-90 {:>30}]".format(bars_left) Formatted string with replacement field and format specifier.
+90\xB0 Use escape sequence and hex to display degrees.
"\r" Escape sequence for carriage return.
πŸ“

Standards

β–Ύ

CSTA Standards - Grades 9-10

3A-CS-03 3A-DA-09 3A-DA-10 3A-DA-11 3A-DA-12 3A-AP-13 3A-AP-14 3A-AP-16 3A-AP-17 3A-AP-18 3A-AP-26

CSTA Standards - Grades 11-12

3B-CS-02 3B-DA-05 3B-DA-06 3B-DA-07 3B-AP-10 3B-AP-14 3B-AP-15 3B-AP-16 3B-AP-21 3B-AP-22 3B-AP-23

Certiport IT Specialist: Python Standards

1.1 1.2 1.3 1.4 2.1 2.2 3.2 4.1 4.2 6.2

PCEP: Certified Entry-Level Python Programmer

1.1 1.2 1.3 1.4 1.5 2.1 2.2 3.1 3.2 3.4 4.1 4.2
πŸ“
Preparing for the Lesson
  • This mission introduces the accelerometer, a new sensor for measuring orientation. Students start by printing raw accelerometer data to the console three different ways before converting it to an angle, so make sure students see all three methods before Objective 2.
  • This mission leans heavily on string formatting, replacement fields, format specifiers, and escape sequences, to build a bar graph visualization. This is a great mission to pause on and give students extra formatting practice.
  • Students will need the math module to convert accelerometer readings into angles with trigonometry. Review radians vs. degrees if it's been a while since students have seen trig.
  • The mission builds toward two separate deliverables: a remote-control program (Objective 4 or Objective 6) and an autonomous program (Objective 8). Plan a checkpoint for each submission.

πŸ§‘β€πŸ«
Teacher Notes
  • Students will drive the 'bot using the 0 and 1 number keys instead of pressing the 'bot's buttons. They can press both buttons at the same time to move forward, or press a single button to turn.
  • For Objective 8, just a slightly larger turn value for one wheel makes a big difference for reaching the goals.
  • This mission uses many string formatting techniques. This is a good time to do some practice and review.
  • Each objective builds on the last, adding code or making modifications. You might want to pause after every couple of objectives and review the new concepts before moving forward.
πŸ—ΊοΈ

Lesson Outline

πŸ—£οΈWarm-up / Hook

Ask students how a phone or game controller "knows" which way it's being tilted. Introduce the accelerometer as the sensor that makes this possible, and connect it to the mission: CodeBot has to "Master the Hill" by reading its own orientation and reacting to it.

1️⃣Objectives 1-2: Reading the Accelerometer and Converting to Angles
  • Print accelerometer data to the console three different ways, then use trigonometry (math.asin) to convert the raw x, y, z values into an angle in radians, then degrees.
  • Administer the Quiz after Objective 1.
  • Reference Mission 12 Obj 2 as needed.
Teaching tip:Use the Code Tracing Chart here, or give students printed code from an objective and have them explain what it does.
2️⃣Objectives 3-5: Building the Bar Graph Visualization
  • Use replacement fields, format specifiers, and escape sequences (including hex for the degree symbol and carriage return for a live-updating display) to turn the angle data into a bar graph visualization.
  • Administer the Quiz after Objective 5.
  • Give extra practice with string formatting before moving on.
Teaching tip:Use the Debugger to track variables through the formatting steps.
3️⃣Objectives 4 & 6: Remote-Controlling CodeBot with Buttons
  • Use button presses as input to remote-control CodeBot, pressing both buttons together to move forward or a single button to turn.
  • Reference Mission 12 Obj 4 and Mission 12 Obj 6 as needed.
  • Have students submit their CodeBot remote control program (Objective 4 or Objective 6).
Teaching tip:Give students code snippets from an objective and have them explain what it does before they submit.
4️⃣Objectives 7-8: Driving Autonomously Up and Down the Hill
  • Program CodeBot to make decisions based on its orientation data, then drive autonomously up and down the hill while dodging obstacles.
  • Reference the Mission 12 Final Code Solution as needed.
  • Have students submit their CodeBot autonomous program (Objective 8).
Teaching tip:For Objective 8, remind students that just a slightly larger turn value for one wheel makes a big difference for reaching the goals.
πŸŽ‰Wrap-up / Review

Close with the Level-1 Mission 12 Review Kahoot! to reinforce accelerometer data, angle conversion, and string formatting before moving on to Mission 13.