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 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
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)
Real-World Applications
Extensions & Cross-Curricular
🔤
Vocabulary
▾
🐍
New Python Code
▾
stateEstimate.yData from the drone that gives estimated position coordinates.
measured_sides is the list and distance is the item (a tuple) being added to the list.
📐
Standards
▾
CSTA Standards - Grades 6–8
CSTA Standards - Grades 9–10
CSTA Standards - Grades 11–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; 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.
- 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
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.
- Introduce state estimators -
stateEstimate.xandstateEstimate.ygive the drone's estimated (x, y) position. - Demonstrate the sensor tuple pattern:
SENSORS = ('range.front', 'stateEstimate.x', ...)and how it gets passed toget_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.
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.
- 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.
- 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.
- Navigate around the box (Objective 3) - apply the corner-detection pattern repeatedly to fly all the way around the four sides.
-
Track position with state estimators (Objective 4) - read
stateEstimate.xandstateEstimate.yat each corner; useglobalvariables to remember the start corner. -
Calculate side lengths (Objective 5; quiz after Objective 5) - use
import mathand the Pythagorean Theorem in acalculate_distance()function to convert coordinate pairs into distances. -
Save measurements in a list (Objective 6) - use
measured_sides.append(distance)to store each side length, then uselen()and the recorder to report results.
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.
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.