Fly with Python - Mission 10: Survey

Mission 10: Survey | Fly with Python
Mission 10 Lesson Plan

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.

⏱ 45-60 min 🎯 Grades 6-12+ 💻 CodeSpace 🚁 CodeAIR 🐍 Python
View Lesson Outline
📋

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
🧰

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

🏗️Drone surveying is used by construction firms, surveyors, and archaeologists to map sites and measure structures. The same edge-detection and distance-tracking pattern students implement here.
🚜Autonomous farm equipment uses state estimators and sensor fusion to plant, water, and harvest crops along precise paths. The same Pythagorean distance math that drives this mission.
🤖Warehouse robots like those in Amazon fulfillment centers run state-machine programs that look very similar to Survey: detect, approach, navigate, measure, log.
📐The Pythagorean Theorem is more than 2,000 years old, yet still drives modern position systems, from GPS to robotics to game engines computing distances between points.
🚀

Extensions & Cross-Curricular

ExtensionObstacle Avoidance upgrade. Add code to the program where the drone can avoid other objects in the environment, navigating around them while completing the survey.
ExtensionDifferent Shapes upgrade. Have the drone survey different shapes, like a five-sided object or a cylinder.
ExtensionEnhance the Mapping. Store sensor data to create a more detailed 3D map of the box or small room. How tall is it?
MathThis mission uses the Pythagorean Theorem for measurement. Discuss other ways the theorem can be used. What are some other ways to calculate a measurement?
STEMThink about real-world situations where autonomous surveying could be beneficial. What kind of sensors or additional functionalities would be needed for those tasks?
Lang ArtsTake a stand on autonomous surveying. Is it good for humanity or not good? Write an opinion paper or persuasive paper on your position.
🔤

Vocabulary

Tuple -An immutable (unchangeable) sequence of items accessed with an index.
Circumnavigation -Traveling all the way around an object.
List -A sequence of items you access with an index, and you can add and remove items.
Mutable -An object, like a list, that can change its contents after creation. Mutable objects can be modified in place. Immutable objects are read-only once created.
State Estimators -Sensor data that gives the estimated position coordinates of the drone in real time.
Pythagorean Theorem -Used to find the distance between two points on a graph. For right triangles: a² + b² = c².
🐍

New Python Code

SENSORS = ('range.front', 'range.up', 'range.zrange', 'stateEstimate.x', 'stateEstimate.y')Define a tuple for the set of data you'll retrieve from the drone.
stateEstimate.x stateEstimate.yData from the drone that gives estimated position coordinates.
front, up, down, x, y = event_dataRanger and position data, unpacked from a tuple.
elif st_time >= 5.0: sm.next_state(land)Time out feature for aborting a state function if it takes too long.
fly.start_turn_left(90) sm.next_state(land, 1)Turns 90 degrees in one second.
if front <= WALL_DISTANCE * 1.5:Detect a new corner after turning.
if front > WALL_DISTANCE * 2.5: sm.next_state(land)Detect a corner and then land. The next state can be changed to gap.
import mathImport the math module.
global start_cornerHave the ability to modify a global variable in a local scope.
d = calculate_distance(x1, x, y1, y)Call the function that returns the distance in meters. The arguments are the previous (x, y) location and the current (x, y) location.
start_corner = NoneDefine a variable with no value.
measured_sides = []Define an empty list.
measured_sides.clear()Clear any items from a list.
if start_corner is not None:Run this block of code only after the first corner has been found.
measured_sides.append(distance)Add an item to a list. In this example, measured_sides is the list and distance is the item being added to the list.
len(measured_sides)Returns the length of the list (how many items in the list).
📐

Standards

CSTA Standards - Grades 9-10

3A-CS-03 3A-DA-10 3A-CS-13 3A-CS-14 3A-AP-16 3A-AP-17 3A-AP-18

CSTA Standards - Grades 11-12

3B-DA-06 3B-DA-07 3B-AP-10 3B-AP-12 3B-AP-14 3B-AP-15 3B-AP-16 3B-AP-21

AI4K12 Standards - Grades 9-12

1-A-ii 2-B-i
📝
Preparing for the Lesson
  • 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.

🧑‍🏫
Teacher Notes
  • 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

🗣️Warm-up / Hook

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.
Teaching tip: Show a quick clip of a drone surveying a construction site or archaeological dig. Frame this mission as a small version of that real engineering workflow.
📖Introduce the Mission

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 with front, up, down, x, y = event_data.
  • Introduce state estimators - stateEstimate.x and stateEstimate.y give 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 SENSORS tuple is immutable, but measured_sides is 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.
Teaching tip: Walk through the starter code in Objective 1 with students. It combines patterns from Missions 7 and 8 and is a great review opportunity. Use the "copy" icon to the right of the code so nobody starts with a typo.
💻Coding Time

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.

  1. Objective 1 - Closer Look - paste in the starter state machine, add the WALL_DISTANCE and ALTITUDE constants, and write an approach state that flies forward until the front ranger sees the box. Introduce the 5-second timeout as a runaway-drone safeguard.
  2. Objective 2 - Measured Moves - add a side_end state 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.
  3. Objective 3 - Go Wide - because only the front of CodeAIR has rangers, the drone has to reorient at every corner. Students add a gap state for clearance and a rotate state that turns 90 degrees with fly.start_turn_left(90).
  4. Objective 4 - Corner 2 - add the mirror-image side_start state that waits for the box to come back into view after the turn: if front <= WALL_DISTANCE * 1.5. Quiz follows this objective.
  5. Objective 5 - Measurement - close the loop so the drone circumnavigates all four sides. Students import math, write calculate_distance() using the Pythagorean Theorem, use global start_corner to remember each corner, append each side length to measured_sides, and land once len(measured_sides) reaches 4. The finished list prints to the console.
Teaching tip: Remind students to check the flight recorder after every flight. It's the only way to debug detection logic when the drone behaves unexpectedly.
Teaching tip: If the drone struggles to detect the box, try a darker-colored or larger box and make sure the lighting is even.
Teaching tip: Objectives 3 and 4 use timed transitions rather than sensor readings for the gap and the turn, so those numbers are the ones students will tune most. Expect a few flights before the rotation lines up.
🧑‍🤝‍🧑Class Debrief

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.
Teaching tip: Have students measure the box with a meter stick and compare those numbers to the list the drone printed to the console. Talk about why the estimates aren't perfect. Sensor drift, rotation accuracy, and the gap the drone leaves at each corner all add up.
✏️Wrap-up & Review

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.

Teaching tip: Mission 10 is the last mission of Unit 3. The Unit 3 Remix follows next. Encourage students to start sketching ideas for an autonomous flight program of their own.