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 apply state machine logic to control an autonomous flight.
  • I can program the drone to approach an object safely and with control using sensor data.
  • I can navigate the drone around a box using sensor data.
  • I can utilize the state estimator to track the drone's position.
  • I can utilize the state estimator data to estimate the dimensions of an object.
💡

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 5
  • 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
🧰

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)
🌍

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

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.y
Data from the drone that gives estimated position coordinates.
get_data(SENSORS, wait=False)Use a tuple of sensor names to retrieve data.
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 a function with a return value.
measured_sides = []Define an empty list.
measured_sides.clear()Clear any items from a list.
measured_sides.append(distance)Add an item to a list. In this example, measured_sides is the list and distance is the item (a tuple) being added to the list.
len(measured_sides)Returns the length of the list (how many items in the list).
📐

Standards

CSTA Standards - Grades 6–8

2-CS-02 2-DA-08 2-AP-11 2-AP-12 2-AP-13 2-AP-14 2-AP-16 2-AP-17

CSTA Standards - Grades 9–10

3A-CS-03 3A-DA-10 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
📝
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; a suitcase also works.
  • Charge all CodeAIR drones fully. Autonomous flight uses more battery than tethered exercises.
  • 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.

🧑‍🏫
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. A 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.

  • Introduce state estimators - stateEstimate.x and stateEstimate.y give the drone's estimated (x, y) position.
  • Demonstrate the sensor tuple pattern: SENSORS = ('range.front', 'stateEstimate.x', ...) and how it gets passed to get_data().
  • Review the Pythagorean Theorem and how it converts (x, y) coordinates into a side length.
  • Show how to build, clear, and append to a Python list, the data structure students will use to store the four side lengths.
  • Set expectations: this is a 45–60 minute mission with one capstone program, 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.
💻Coding Time

Students build the Survey program one capability at a time, layering detection, navigation, and measurement. As they work through the objectives, they should take notes and answer questions in their assignment doc.

  1. Set up the program (Objectives 1–2; quiz after Objective 2) - start from the provided code, define the SENSORS tuple, and add forward-ranger detection so the drone reacts when it sees an object.
  2. Detect a corner - extend the detection logic so the drone can find the edge of a wall, then fly just past the edge and rotate to face the object.
  3. Navigate around the box (Objective 3) - apply the corner-detection pattern repeatedly to fly all the way around the four sides.
  4. Track position with state estimators (Objective 4) - read stateEstimate.x and stateEstimate.y at each corner; use global variables to remember the start corner.
  5. Calculate side lengths (Objective 5; quiz after Objective 5) - use import math and the Pythagorean Theorem in a calculate_distance() function to convert coordinate pairs into distances.
  6. Save measurements in a list (Objective 6) - use measured_sides.append(distance) to store each side length, then use len() and the recorder to report results.
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.
🧑‍🤝‍🧑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: "What would change if the box had five sides instead of four?" - preview the Different Shapes extension.
Teaching tip: Have students compare their measured side lengths to the box's actual dimensions. Talk about why the estimates aren't perfect. Sensor drift, rotation accuracy, etc.
✏️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.