0
0
Drone Programmingprogramming~10 mins

Barometer for altitude in Drone Programming - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Barometer for altitude
Start
Read Pressure
Calculate Altitude
Use Altitude for Control
Repeat Reading
The drone reads air pressure from the barometer, calculates altitude from it, then uses that altitude to control flight, repeating this process continuously.
Execution Sample
Drone Programming
pressure = read_barometer()
altitude = 44330 * (1 - (pressure / 101325) ** 0.1903)
print(f"Altitude: {altitude:.2f} meters")
Reads pressure from barometer, calculates altitude in meters, and prints it.
Execution Table
StepActionPressure (Pa)CalculationAltitude (m)Output
1Read pressure from barometer9000044330 * (1 - (90000 / 101325)^0.1903)1113.57None
2Calculate altitude9000044330 * (1 - 0.8877^0.1903)1113.57None
3Print altitude90000Same as step 21113.57Altitude: 1113.57 meters
4Repeat readingNext pressure readRepeat calculationNew altitudeOutput updated
5StopN/AN/AN/AEnd of program
💡 Program stops when no more pressure readings are taken or drone is turned off.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
pressureNone90000900009000090000
altitudeNoneNone1113.571113.571113.57
Key Moments - 3 Insights
Why does altitude change when pressure changes?
Because altitude is calculated from pressure using a formula (see execution_table step 2). Lower pressure means higher altitude.
Why do we use the power 0.1903 in the calculation?
This exponent comes from the barometric formula to convert pressure ratio to altitude, as shown in execution_table step 2.
Why do we repeat reading pressure continuously?
Because the drone needs updated altitude to adjust flight in real time, as shown in execution_table step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the altitude calculated at step 2?
A101325 meters
B90000 meters
C1113.57 meters
D0 meters
💡 Hint
Check the 'Altitude (m)' column at step 2 in the execution_table.
At which step does the program print the altitude?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look for the 'Output' column showing printed altitude in the execution_table.
If the pressure reading increases, how does the altitude change?
AAltitude increases
BAltitude decreases
CAltitude stays the same
DAltitude becomes zero
💡 Hint
Refer to the formula in execution_table step 2 and how pressure relates to altitude.
Concept Snapshot
Barometer measures air pressure.
Altitude is calculated using: altitude = 44330 * (1 - (pressure / 101325)^0.1903).
Lower pressure means higher altitude.
Drone reads pressure repeatedly to update altitude.
Altitude helps drone control flight height.
Full Transcript
This program uses a barometer sensor to read air pressure. It then calculates altitude from that pressure using a standard formula. The altitude is printed out. The program repeats this process to keep updating altitude as the drone flies. Lower pressure means the drone is higher up. The calculation uses a power of 0.1903 to convert pressure ratio to altitude. This helps the drone know how high it is and adjust its flight accordingly.