Fly with Python - Mission 10: Survey
Survey
Students close out Unit 3 by programming an autonomous survey, flying CodeAIR around a box to detect corners, measure each side using state estimators and the Pythagorean Theorem, and capture the dimensions in a Python list.
Overview
Mission 10 is the capstone of Unit 3: a fully autonomous surveying program. Students bring together everything from the unit - the StateMachine, formal state handlers, sensor tuples, and the flight data recorder, to build Survey, a program that detects a box, navigates around it, and measures each side. Along the way they introduce state estimators (stateEstimate.x, stateEstimate.y), use the Pythagorean Theorem to compute side lengths from coordinate pairs, and store the measurements in a Python list, closing the unit with a real engineering workflow.
🎯 Mission Goal: Students will program the drone to survey an object by detecting corners and measuring the sides.
Learning Targets
- I can program CodeAIR to approach the box using sensor data, ensuring a safe and controlled approach.
- I can navigate CodeAIR around the box using sensor feedback to maintain a safe distance and avoid collisions.
- I can utilize the state estimator to track CodeAIR's position and estimate the dimensions of the box.
- I can apply my state machine skills to control CodeAIR's autonomous flight during the survey.
Key Concepts
-
A tuple of sensors can be defined, which enables the programmer to select which sensors to read. You decide the order of the data when defining the tuple. Then the name of the tuple can be used as the argument for
get_data(). - Data from the forward ranger can be used to detect a wall and also the end of a wall, or a corner.
- Data from the rangers is measured in mm. It can easily be converted to meters, which is used for flight velocity.
- The state estimators are data that gives an estimated position of the drone. The data is returned as an (x, y) coordinate. The coordinate can be used with the Pythagorean Theorem to calculate distance traveled.
Assessment Opportunities
- Quiz after Objective 2
- Quiz after Objective 4
- Complete the program Survey
- Mission 10 Assignment
- Mission 10 Review Questions
Success Criteria
- Use the forward ranger data to detect an object
- Use the forward ranger data to detect the edge of an object
- Fly the drone just past an edge and rotate to face the object
- Navigate the drone around a four-sided object
- Use state estimators to calculate the length of each side of the object
- Save the lengths of an object in a list and display the list on the console
Digital Resources
Classroom Materials
- ▸Laptop/computer with Chrome browser
- ▸CodeAIR drone and USB cable
- ▸A cardboard box, about the size of a milk crate or larger, for measuring (darker colors work best; a suitcase also works)
- ▸Meter stick for measuring the box sides
Real-World Applications
Extensions & Cross-Curricular
🔤
Vocabulary
▾
🐍
New Python Code
▾
gap.
measured_sides is the list and distance is the item being added to the list.
📐
Standards
▾
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
AI4K12 Standards - Grades 9-12
- Reserve a clear, well-lit flight space. The drone needs room to fly all the way around the box without obstacles.
- Set up a cardboard box (milk crate size or larger) in the flight space. Darker colors work best for the forward ranger; an upright suitcase also works.
- Charge all CodeAIR drones fully. Autonomous flight uses more battery than tethered exercises.
- Have meter sticks ready. Students measure the box sides by hand so they can compare their own numbers to the drone's estimates at the end.
- Pre-stage Objective 1's starter code if you'd like students to use it directly. Copy/paste from the instructions saves time and reduces typos. The code combines patterns from Missions 7 and 8.
- Preview the two quizzes so you know where the natural stopping points are. One follows Objective 2 (Measured Moves) and one follows Objective 4 (Corner 2).
- If you have a word wall, prepare the new terms. This mission adds tuple, list, mutable, and circumnavigation on top of state estimators and the Pythagorean Theorem, so plan a few minutes to contrast tuples (immutable) with lists (mutable).
- Print or assign the Mission 10 Assignment and Review Questions through your LMS ahead of class.
- You will need space for this mission. The drone will survey a box to measure its dimensions. The box needs to be in a well-lit area with no other obstacles around it. The space around the box needs to be clear. The box should be about the size of a milk crate or larger. Darker colors for the box work better. An upright suitcase also works well.
- Objective 1 has code in the instructions that can be copied and pasted into the mission's program file. Use the "copy" icon to the right of the code. This saves time and ensures students do not start with any typing errors. The program combines code from Missions 7 and 8. This is a good time to review!
- Don't forget to have students check their flight recorder after each flight.
- 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 10.
Lesson Outline
Students access prior knowledge by answering questions in the pre-mission section of the assignment doc.
Connect autonomous surveying to real-world examples through a brief discussion.
- Ask: "If you needed to measure the dimensions of a building without ever touching it, how could you do it?"
- Ask: "What sensors and skills from Missions 7, 8, and 9 do you think we'll need to make CodeAIR survey a box on its own?" - preview the integration.
Front-load the key new programming concepts before students start coding.
- Demonstrate the sensor tuple pattern:
SENSORS = ('range.front', 'range.up', ...). The programmer picks which sensors to read and what order the data comes back in, then unpacks it withfront, up, down, x, y = event_data. - Introduce state estimators -
stateEstimate.xandstateEstimate.ygive the drone's estimated (x, y) position in meters. - Point out that ranger data is in millimeters while flight velocity uses meters, so students will be converting units.
- Review the Pythagorean Theorem and how it converts two (x, y) coordinate pairs into a side length.
- Contrast tuple vs. list: the
SENSORStuple is immutable, butmeasured_sidesis a mutable list students will clear and append to. - Introduce circumnavigation as the goal: the drone travels all the way around the box, measuring as it goes.
- Set expectations: 45-60 minutes, five objectives, one capstone program called Survey that pulls together everything from Unit 3.
Students build the Survey program one capability at a time, layering detection, navigation, and measurement across five objectives. As they work, they should take notes and answer questions in their assignment doc. Each objective ends with a real flight, so plan for test-and-adjust time.
-
Objective 1 - Closer Look - paste in the starter state machine, add the
WALL_DISTANCEandALTITUDEconstants, and write anapproachstate that flies forward until the front ranger sees the box. Introduce the 5-second timeout as a runaway-drone safeguard. -
Objective 2 - Measured Moves - add a
side_endstate that slides right along the face of the box and detects the corner when the front reading jumps:if front > WALL_DISTANCE * 2.5. Quiz follows this objective. -
Objective 3 - Go Wide - because only the front of CodeAIR has rangers, the drone has to reorient at every corner. Students add a
gapstate for clearance and arotatestate that turns 90 degrees withfly.start_turn_left(90). -
Objective 4 - Corner 2 - add the mirror-image
side_startstate that waits for the box to come back into view after the turn:if front <= WALL_DISTANCE * 1.5. Quiz follows this objective. -
Objective 5 - Measurement - close the loop so the drone circumnavigates all four sides. Students
import math, writecalculate_distance()using the Pythagorean Theorem, useglobal start_cornerto remember each corner, append each side length tomeasured_sides, and land oncelen(measured_sides)reaches 4. The finished list prints to the console.
Bring the class together to consolidate the unit-spanning ideas this mission ties together.
- Ask: "How did the StateMachine, sensor tuples, and flight recorder all show up in this one program?"
- Ask: "Why was the Pythagorean Theorem necessary here? Could you survey the box without it?"
- Ask: "Why does SENSORS have to be a tuple while measured_sides has to be a list?" - reinforces mutable vs. immutable.
- Ask: "What would change if the box had five sides instead of four?" - preview the Different Shapes extension.
Students answer the reflection question in the assignment doc and then submit.
Use the Mission 10 Review Questions through a preferred method: class discussion, Kahoot!, or LMS quiz.