Skip to content

PID Tuning Challenge

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.

  • PID controller principles
  • Closed-loop control systems
  • Parameter tuning methods
  • Stability analysis
ItemQuantityNotes
ESP32 Drone1Fully assembled
Fan1To simulate light wind
Computer1With browser installed

PID is a classic control algorithm consisting of three parts:

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

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;
}

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
  1. Use a fan to simulate light wind (1 meter away, medium speed)
  2. Adjust parameters until the drone can hover stably

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

  • Decrease kp value
  • Increase kd value
  • Increase ki value
  • Check barometer data

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

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