I'm working on diy flight controller for quadcopter. I have a question for which I can't find a good answer. So perhaps you could help me. I'm using a cascaded PID controller for Pitch and Roll regulation. First there is a stabilize PID and rate PID. For the first (stab.) you input desired angle from transmitter and actual angle from IMU. then this output is feed into rate controler. From there it goes to the motors.

In code I'm pooling a function with "data is ready to read from IMU" which happens every 1ms. In this function I'm calculating one regulator and writing to motors. Loop time when this condition is not true is way lower then that. So one regulator should be inside this slow loop and one outside. So which one should be fast and which one slow? In my understanding, stabilize PID should be the fastest? Is that correct? Also should both regulators be PID?

Thanks for your help!


I had some trouble understanding your current setup, But generally you will have an interrupt pin connected to your IMU, and every time the IMU has new data, you process the Rate control loop then the Stabilize control loop, then update the motor output. You want the shortest possible time from the reading of the IMU data to the processing of the rate control loop to the output of the motor commands. Generally you can update the stabilize loop ~5 times slower than the rate loop to save time. I would shoot to run the rate loop as fast as you can update the motors (50Hz for pwm 400+Hz if your using Oneshot or Fast PWM), and to save time you can run the stabilized loop at 10-50Hz.

  • $\begingroup$ Check out my reply on the other comment. I understand everything, it's just that my "wrong" approach seems to be working, and I'm confused why. $\endgroup$ – KristjanB Dec 23 '16 at 20:16

A cascaded PID controller is normally used when multiple sensors are available. In a normal PID controlled system, you have the measurement from your sensor and your setpoint (both used to calculate your error), and your PID controller which acts to reduce the error through the P, I and D gains. A cascaded PID controller is a nested PID controller, meaning it consists of an inner PID loop which supposedly is faster and an outer PID loop. If applied correctly the faster inner PID loop controller can buffer the impact on the slower outer PID controller resulting in a smoother dynamic performace.

Normally in a quadcopter, the inner/faster loop is the rate loop. The rate loop regulates the angular velocity given a setpoint and the rate measurement usually from the gyroscope. The outer loop/slower loop is the stabilize loop which uses angle input setpoints and measurements from fusing the angles computed from the accelerometer and angles integrated from the gyroscope via sensor fusion (eg. kalman, complementary filter, etc.)

Mathematically, in this case a normal/traditional PID controller (PID) would be equivalent to a cascaded PID controller (P-PI). Where your Kp(traditional) is equivalent to Kp(stab), Ki(traditional) is equvalent to Kp(stab)*Ki(rate) and lastly your Kd(traditional) to Kp(stab)*Kp(rate). See Edouard Leurent's easy to understand explanation/comment here: https://www.quora.com/What-is-rate-and-stabilize-PID-in-quadcopter-control

I'm really sorry because I did not quite understand your question but I hope this helps :)

  • $\begingroup$ Hey! Thank you very much for your answer. So the problem is that if I use rate loop as the fast one and stabilize loop as the slowest one, together, then quadcopter should react to angle change, right? And when I would center my transmitter stick, quadcopter should level itself. But this did not happen. quadcopter drifted in a direction and level itself after about 10 meters. So when I switched the loops, quadcopter reacted to angle change instantly and was infact, leveled. $\endgroup$ – KristjanB Dec 23 '16 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.