Introduction
Keeping a drone at the right height is tricky because it can easily drift up or down due to wind or other forces. Without a way to control altitude, the drone might crash or fly too high and lose connection.
Imagine riding a bicycle on a hill where you want to keep your speed steady. You watch your speedometer and pedal harder or slower to keep the speed you want, even if the hill goes up or down.
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ Desired │ │ Sensors │ │ Control │
│ Altitude │──────▶│ Measure │──────▶│ System │
│ (Setpoint) │ │ Current │ │ Adjusts │
└───────────────┘ │ Altitude │ │ Motor Speed │
└───────────────┘ └───────────────┘
▲ │
│ ▼
┌───────────────┐ ┌───────────────┐
│ External │ │ Drone │
│ Factors │──────▶│ Altitude │
│ (Wind, etc.) │ │ Changes │
└───────────────┘ └───────────────┘current_altitude = 50
set_target = 100
if current_altitude < set_target:
print('Ascending')
else:
print('Holding position')def adjust_altitude(current, target):
if current > target
return 'Descending'
else:
return 'Ascending'def control_altitude(current):
target = 120
if current < target:
power = 70
elif current > target:
power = 30
else:
power = 50
return power
print(control_altitude(120))Pass the test and this pattern moves unknown