# How do I tune the cascaded PID controller in my flight controller?

there is a lot of information out there on how to tune quad PID parameters. However, they mostly regard only the master loop that takes user input and fused absolute angles. How and in which order do I tune my cascaded PID loops? Do I first do the rate loop? How can I tell if it's tuned correctly? I can cause it to spin the drone 2 times a second around itself, and that with low throttle. It stops quickly when I reset the stick position.

I feel stupid because I cannot tune the controller I built myself, but maybe you can explain it to me.

In general, a cascade controller is nothing more than two independent controllers in series. With independent I mean that they do not intend to control the same value (= measurment, plant output). I.e. One controls the rate and the other the position (or what ever is the case in your specific issue). Nevertheless, you still have only one output from both the controller combined to stabilize both values of interest.

Therefore you have to identify how the input to the plant $u_f$ - i.e. the output of the controllers - influence the outputs ($y_s$ and $y_f$!) of the plant. If you have a ruff idea about the crossover frequencies of these individual systems ($u_f \rightarrow y_f$ and $u_f \rightarrow y_s$) you can separate them into one fast and one slow subsystem. For example, you should have a look at the poles of both subsystems. The pole of the fast and slow system have to be different from each other, i.e.: $$\pi_{s,slowest} \neq \pi_{f,slowest}$$ Otherwise you won't be able to tune the controllers individually!

Take this chart as a reference.

TUNE FAST CONTROLLER

So if you have identified your faster subsystem - i.e. the value that response faster to input changes - you can start tuning the corresponding controller (Fast controller $C_f$) with the help of the 'fast output' $y_f$. This can be done with the common methods like Ziegler-Nichols or whatever other P(ID) tuning method you prefer (best practice is to leave the integrator part - it only reduces the bandwidth of the controller - for this controller and use P(D) at most but this depends strongly on your system).

TUNE SLOW CONTROLLER

Now you have to shape the outer, 'slower' controller $C_s$. For that you have to have a look at the combined closed loop system of the fast control system you just tuned. I.e:

$$P_s = \frac{P\cdot C_f}{1+P\cdot C_f}$$

$P_s$ is your new plant. Therefore, you tune your controller on the basis of $P_s$, $r_s$ and $y_s$ as you know it. Here a PI(D) controller is recommended.

• Thanks for the explanation. I could have clarified that I do know which is the faster and which is the slower loop and that the cascade is already implemented. My question was more along the line of "in this special case, what is the desired behaviour of my rate/angle loop". Mar 12, 2018 at 8:39
• Your behavior in the end is not dependent on the implementation (besides update frequencies) rather than on your mechanical system (given you have no bugs in the controllers). Nevertheless, since you managed to clear oscillations - meaning you had an under damped closed loop system - reducing the p-gain brings you closer to a good solution. On the other hand, you could make your rate controller oscillate at a constant amplitude (bounded stable) with a simple P-controller. With that you do ziegler-nychos and determine the other ID-gains. Try it! Mar 13, 2018 at 14:42

I have since tuned the system just by using trial and error. The rate constants are much lower than their maximal values at which oscillation started. It helped to just measure which loop caused oscillations when they happened.

• How much lower is "much lower". A very approximate rule of thumb is that you should go down by a factor of two or four from the value that induces oscillation. You can't really do it right without taking measurements and tuning from them, either directly (i.e., swept-sine measurements and Bode plots) or indirectly (i.e., system identification and some sort of design synthesis method like pole placement or robust tuning). May 11, 2018 at 16:25
• I used the very approximate rule of thumb. The are little oscillations in extreme situations such as falling then turning on the motors, but it does nicely I would say. As for formal methods - of course they are better! May 14, 2018 at 8:43