← Swipe for prev/next tutorial →
intermediate Level

PID Tuning Challenge

Adjust PID parameters to make the drone hover stably even in windy conditions.

⏱️ 1.5 hours 📋 Complete Project 01

Overview

The PID controller is the core of stable drone flight. In this project, you will learn about PID control principles and adjust parameters to make the drone fly more stably.

What You’ll Learn

  • PID controller principles
  • Closed-loop control systems
  • Parameter tuning methods
  • Stability analysis

Materials Needed

ItemQuantityNotes
ESP32 Drone1Fully assembled
Fan1To simulate light wind
Computer1With browser installed

Step 1: Understand PID Control

PID is a classic control algorithm consisting of three parts:

ParameterNameFunction
PProportionalControls response speed
IIntegralEliminates steady-state error
DDerivativePrevents overshoot and oscillation

Step 2: Find PID Parameter File

Open controller_pid.c and find the PID structure:

typedef struct {
  float kp; // Proportional coefficient, controls reaction speed
  float ki; // Integral coefficient, eliminates static error
  float kd; // Derivative coefficient, prevents overshoot
} PID_t;

Find the pid_update function:

float pid_update(PID_t* pid, float setpoint, float feedback) {
  float error = setpoint - feedback;
  pid->integral += error * dt;
  float derivative = (error - pid->last_error) / dt;
  pid->last_error = error;
  return pid->kp * error + pid->ki * pid->integral + pid->kd * derivative;
}

Step 3: Initial Parameter Testing

Default parameters: kp=0.5, ki=0.1, kd=0.2

Test indoor flight and observe stability:

PhenomenonAdjustment
Excessive shakingDecrease kp
Cannot take offIncrease kp
DriftingIncrease ki
Slow responseIncrease kd

Step 4: Light Wind Testing

  1. Use a fan to simulate light wind (1 meter away, medium speed)
  2. Adjust parameters until the drone can hover stably

Step 5: Record Optimal Parameters

Enter parameters in pid_tuner.html to generate a tuning report.

Troubleshooting

Drone shakes violently

  • Decrease kp value
  • Increase kd value

Drone cannot maintain altitude

  • Increase ki value
  • Check barometer data

Achievement

Congratulations! You have mastered the basic methods of PID tuning, which is a core skill for drone control!

Next Steps

In the next project, you will learn how to read barometer data for more precise altitude hold.

Continue to Project 03: Altimeter Decryption →

← Tutorials