Fly with Python - Mission 6: Navigate
Navigate
Students program CodeAIR to fly autonomously - using the flow sensor for position tracking, sensor fusion for accuracy, binary LED patterns for a custom UI, and try/except blocks to handle errors gracefully.
Overview
Mission 6 wraps up Unit 2 by giving CodeAIR full autonomous navigation. Students explore the flow sensor for x/y position tracking, fly precise square routes to test accuracy, and learn how multiple sensors combine for stable flight. Along the way they pick up f-strings for clean console output, binary patterns for a custom LED user interface, and try / except blocks for graceful error handling. The mission culminates in RouteSelect, a selectable-operations program that lets the user choose a flight pattern at runtime.
🎯 Mission Goal: Students will program CodeAIR to fly autonomously using sensor data.
Learning Targets
- I can explore positioning systems with the flow sensor for x, y tracking.
- I can observe and analyze flow sensor accuracy by flying CodeAIR in a square.
- I can conduct a battery check to ensure safe and sustained flight.
- I can customize selectable operations to control code behavior during runtime.
- I can experiment with flight parameters including height, distance, and velocity.
Key Concepts
- The flow sensor is an optical device that can discern patterns on the ground and report movement in two directions.
- The sensor tracks motion by summing up the changes in x and y over time.
- You can use an f-string to determine how information is printed.
- Data from multiple sensors is needed for accurate flight control.
- CodeAIR's battery is charging whenever it is plugged in.
- The 8 LEDs can use binary patterns to display integers between 0 and 255.
-
Handle exceptions in code using a
tryblock.
Assessment Opportunities
- Quiz after Objective 2
- Quiz after Objective 4
- Quiz after Objective 6
- Complete the programs FlowTracker, SquareUp, SquareTurns, BattTest, utility.py, and RouteSelect
- Mission 6 Assignment
- Mission 6 Review Questions
Success Criteria
- Use flow sensor data to track position
- Fly CodeAIR in a square
- Perform a battery check
- Create a user interface using binary patterns
-
Handle exceptions using a
tryblock - RouteSelect works correctly and runs without errors or bugs
- Complete Mission 6 Assignment
Digital Resources
- ▸CodeAIR Mission 6 Assignment
- ▸CodeAIR Mission 6 Assignment Answers
- ▸CodeAIR Mission 6 Review Questions
- ▸Optional: Mission 6 Flight Data (spreadsheet)
- ▸FlowTracker Code Solution
- ▸SquareUp Code Solution
- ▸SquareTurns Code Solution
- ▸BattTest Code Solution
- ▸utility Code Solution
- ▸RouteSelect Code Solution
Classroom Materials
- ▸Laptop/computer with Chrome browser
- ▸CodeAIR drone and USB cable
- ▸Metric tape measure or ruler (for measuring flight accuracy)
- ▸Open floor space with even lighting and a slight ground pattern (helps the flow sensor)
Real-World Applications
try / except is required in any production software - banks, hospitals, and aviation systems all rely on graceful error handling so a single bug doesn't crash the entire system.
Extensions & Cross-Curricular
🔤
Vocabulary
▾
🐍
New Python Code
▾
📐
Standards
▾
CSTA Standards — Grades 6–8
CSTA Standards — Grades 9–10
CSTA Standards — Grades 11–12
- Reserve a flight space with plenty of unobstructed room - clear furniture or use a hallway. Flooring with a slight pattern works best for the flow sensor.
- Charge all CodeAIR batteries fully. The flight tests in this mission are longer than previous missions.
- Have a metric tape measure or ruler available so students can compare commanded flight distances with measured actual distances.
- Decide whether students will log Objective 7 flight data on the printed chart in the assignment doc, or in the optional spreadsheet (linked in Digital Resources) for deeper analysis.
- Plan for multiple class periods - this mission can easily span a class period per objective if students experiment with parameters.
- The last objective requires students to create a chart and log the results of several test flights. The assignment document has a chart they can use. Alternatively, students can use a spreadsheet (one is provided) and use the spreadsheet for more extensive data analysis.
- This mission involves several programs, and each one can be used for experimentation. Don't rush, and give students plenty of time to try their code with different values and in different environments. You could easily spend a class period on almost every single objective.
- Objective 4 has some important instructions after the goal is met. Students need to add their battery check to safety.py and then run the code to reinstall it on CodeAIR. Don't let students skip this part!
- The test flights during the Objectives will need plenty of unobstructed room. Clear out as much furniture as you can, or use hallways. Also check the flooring. Use flooring with a pattern for best results.
- Review questions can be used as a class review, made into a Kahoot!, or used to create an exam in your learning management system.
- Extensions and cross-curricular projects are included to enhance the concepts in the mission. You can use the extensions to extend students' programming experience. A remix is planned after Mission 6.
Lesson Outline
Students access prior knowledge by answering questions in the pre-mission section of the assignment doc.
Connect autonomous navigation to real-world examples through a brief discussion.
- Ask: "How does a self-driving car know where it is in the world? What about a robot vacuum?"
- Ask: "What's the difference between knowing your absolute location (like GPS) and tracking your motion from a starting point?" - preview dead reckoning vs. external positioning.
Front-load the key new programming concepts and lay out the mission's scope.
- Introduce the flow sensor - explain that it sums up changes in x and y over time to estimate position.
- Demonstrate f-strings - show how curly-brace replacement fields make console output cleaner than concatenating strings.
- Preview binary numbers and how an 8-bit byte maps directly onto the 8 LEDs.
- Introduce
try/exceptwith a simple example - what happens if the user enters bad input? - Set expectations: this is a 120-180 minute mission with six programs and is designed to span several class periods.
Students work through six programs that progress from sensor exploration to a full selectable-operations program. As they work through the objectives, they should take notes and answer questions in their assignment doc.
- FlowTracker - read flow sensor data and use f-strings to print x/y position to the console (Objectives 1-2; quiz after Objective 2).
- SquareUp & SquareTurns - fly precise square routes to test sensor accuracy and observe the effects of distance and velocity parameters (Objective 3).
-
BattTest - perform a battery check using
power.battery_voltage(), then add the check to safety.py and reinstall it on CodeAIR (Objective 4; quiz after Objective 4). -
Binary LED UI - use
leds.set_mask()with binary literals (0b10101010) to display patterns on the 8 LEDs (Objective 5). -
utility.py - build a selectable-operations user interface with
try/excepterror handling (Objective 6; quiz after Objective 6). - RouteSelect - combine everything into an autonomous flight program where the user chooses a route at runtime; log test data in a chart for analysis (Objective 7).
Bring the class together to consolidate the big programming ideas from this mission and prepare for the Unit 2 Remix.
- Ask: "What is sensor fusion? Why does CodeAIR need more than one sensor to fly accurately?"
- Ask: "Why is
try/exceptbetter than just letting a program crash?" - Ask: "How could you redesign RouteSelect to fly your own custom route?" - preview the Unit 2 Remix.