0
0
Drone Programmingprogramming~10 mins

Range finder for terrain following in Drone Programming - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Range finder for terrain following
Start
Read range finder sensor
Calculate altitude error
Adjust drone altitude
Check if mission complete
No Yes
Repeat
The drone reads the range finder sensor, calculates altitude error, adjusts altitude, and repeats until the mission is complete.
Execution Sample
Drone Programming
altitude_setpoint = 10
while mission_active:
    current_altitude = read_range_finder()
    error = altitude_setpoint - current_altitude
    adjust_altitude(error)
    if mission_complete():
        break
This code keeps the drone at a set altitude by reading the range finder and adjusting altitude until the mission ends.
Execution Table
StepActioncurrent_altitude (m)error (m)Altitude AdjustmentMission Complete?
1Read sensor8.510 - 8.5 = 1.5Increase altitude by 1.5No
2Read sensor9.210 - 9.2 = 0.8Increase altitude by 0.8No
3Read sensor9.910 - 9.9 = 0.1Increase altitude by 0.1No
4Read sensor10.010 - 10.0 = 0.0No adjustmentNo
5Read sensor10.110 - 10.1 = -0.1Decrease altitude by 0.1No
6Read sensor10.010 - 10.0 = 0.0No adjustmentYes
💡 Mission complete detected at step 6, loop exits.
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6
current_altitudeN/A8.59.29.910.010.110.0
errorN/A1.50.80.10.0-0.10.0
mission_activeTrueTrueTrueTrueTrueTrueFalse
Key Moments - 3 Insights
Why does the error become negative at step 5?
At step 5, current_altitude is 10.1 which is above the setpoint 10, so error = 10 - 10.1 = -0.1, indicating the drone is too high and needs to decrease altitude.
Why is there no altitude adjustment at step 4?
At step 4, error is zero (10 - 10.0 = 0), so the drone is at the desired altitude and no adjustment is needed, as shown in the execution_table row 4.
When does the loop stop running?
The loop stops when mission_complete() returns True, which happens at step 6, causing mission_active to become False and exiting the loop.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the error value at step 3?
A1.5
B0.8
C0.1
D-0.1
💡 Hint
Check the 'error (m)' column in row 3 of the execution_table.
At which step does the drone first stop increasing altitude?
AStep 2
BStep 4
CStep 5
DStep 6
💡 Hint
Look at the 'Altitude Adjustment' column to find when it says 'No adjustment' for the first time.
If the altitude_setpoint was changed to 12, how would the error at step 1 change?
AIt would be 3.5
BIt would be -1.5
CIt would stay 1.5
DIt would be 10
💡 Hint
Calculate error as altitude_setpoint - current_altitude using the new setpoint and step 1 altitude.
Concept Snapshot
Range finder terrain following:
- Read sensor for current altitude
- Calculate error = setpoint - current altitude
- Adjust altitude based on error
- Repeat until mission complete
- Keeps drone flying at desired height over terrain
Full Transcript
This visual execution shows how a drone uses a range finder sensor to maintain a set altitude for terrain following. The drone reads the current altitude, calculates the difference from the desired altitude (error), and adjusts its altitude accordingly. The process repeats until the mission is complete. The execution table traces each step's sensor reading, error calculation, altitude adjustment, and mission status. Key moments clarify why error can be negative, when no adjustment is needed, and when the loop stops. The quiz tests understanding of error values, adjustment timing, and effects of changing the setpoint.