Introduction
Keeping a drone steady in the air is tricky because wind and movement can push it off balance. To solve this, drones use a special system that helps them adjust quickly and stay stable during flight.
Imagine balancing a broomstick on your hand. You move your hand quickly to catch it if it starts to fall (proportional). If it keeps leaning a bit, you slowly adjust your hand position to fix that steady lean (integral). And if it suddenly starts falling faster, you prepare to move your hand faster to stop it (derivative).
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ Error (e) │─────▶│ Proportional │─────▶│ │
│ (Desired - │ │ Control (P) │ │ │
│ Actual) │ └───────────────┘ │ │
└───────────────┘ │ │
│ │
┌───────────────┐ ┌───────────────┐ │ │
│ Error Sum │─────▶│ Integral Ctrl │─────▶│ │
│ (Accumulated) │ │ (I) │ │ PID Output │────▶ Drone Motors
└───────────────┘ └───────────────┘ │ │
│ │
┌───────────────┐ ┌───────────────┐ │ │
│ Error Change │─────▶│ Derivative │─────▶│ │
│ (Rate of e) │ │ Control (D) │ └───────────────┘
└───────────────┘ └───────────────┘error = target_angle - current_angle integral += error * dt derivative = (error - last_error) / dt output = Kp * error + Ki * integral + Kd * derivative last_error = error print(round(output, 2))
target_angle = 10, current_angle = 7, last_error = 2, integral = 5, dt = 1, Kp = 1, Ki = 0.1, and Kd = 0.05, what is the printed output?integral = 0 dt = 0.1 error = target - current integral += error output = Kp * error + Ki * integral * dt + Kd * (error - last_error) / dt
Pass the test and this pattern moves unknown