What it is:
This is a project I made since I decided to learn more about flight controllers, especially the algorithms they use to maintain and change their positions smoothly. I was interested in how they use orientation and position data to stay balanced even in windy environments. Since building an entire flight controller was out of my scope due to time constraints, I decided to build a one-degree-of-freedom test rig using my Bambu Lab printer to validate and apply my newly gained knowledge.
A flight controller uses a PID control algorithm to compare its desired orientation against its actual orientation to calculate an error. PID breaks the error into 3 pieces:
- Proportional (P): Reacts to the present error
- Integral (I): Accounts for accumulated past error
- Derivative (D): Responds to how fast the error is changing
How it works:
The stand is a 3D-printed beam on a pivot with a small motor at each end. An ESP32 runs a control loop about 500 times a second, and each pass goes through these four steps:
- Sense: An MPU6050 reports acceleration and rotation rate over I²C. The accelerometer gives the beam's absolute angle, and the gyroscope gives how fast it is rotating.
- Estimate: The accelerometer is noisy, and the gyroscope drifts over time. A complementary filter blends them, using the gyro for quick changes and the accelerometer to cancel drift.
- Control: The PID loop compares that pitch to the target (level) and calculates a correction. The integral term and the output are both capped so the correction never asks the motors for more than they can give.
- Actuate: Both motors spin at a base throttle. The correction is added to one motor and subtracted from the other, so one end of the beam lifts while the other drops.
To make tuning easier, I can change the PID gains, the target angle and the base throttle over the serial console while the rig is running, without reflashing. The ESP32 also streams the pitch and motor outputs to the serial plotter, so I can see how each change affects the response.
What I learned:
- This project taught me about PID control and especially how to tune various parameters to get the most accurate result when working in a noisy environment (my finger disrupting the beam's balance).