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
Item Quantity Notes
ESP32 Drone 1 Fully assembled
Fan 1 To simulate light wind
Computer 1 With browser installed

PID is a classic control algorithm consisting of three parts:

Parameter Name Function
P Proportional Controls response speed
I Integral Eliminates steady-state error
D Derivative Prevents 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:

Phenomenon Adjustment
Excessive shaking Decrease kp
Cannot take off Increase kp
Drifting Increase ki
Slow response Increase 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.

First published atdrone.imagrove.com/intermediate/pid-tuning/Please credit Imagrove and link back to this page when quoting or republishing.

Questions or issues with this tutorial?

Sign in with GitHub to leave a comment. If a step fails for you, tell us — we verify it and update the tutorial.

ImagroveMore ESP32 tutorials · ESP32 IoT Tutorial

© 2026 ESP32 Drone. All rights reserved.