# Tuning a cascaded attitude and attitude rate PID controller

Assume that I have an object in 3D, and I want to have a controller that stabilizes its orientation (also referred to as "attitude").

To be sure we are clear:

• attitude is measured in "degrees" or "radians"
• attitude rate is measured in "degrees/s" or "radians/s"

• attitude controller: the error controlled by this controller is the difference between the reference attitude and the real attitude
• attitude rate controller: the error controlled by this controller is the difference between the reference attitude rate and the real attitude rate

The attitude controller is made only of a P term, and therefore it is not hard to tune. However, the attitude rate controller has all three terms P, I, and D.

I am using the well-known Ziegler-Nichols method to tune the attitude rate controller. However, I am not sure that theoretically, what I am doing is correct.

My question is: is it possible to tune the P, I, and D terms of the attitude rate controller while observing the step response by giving a command in attitude? To apply this procedure, should I provide an attitude rate command instead? (The main problem is I cannot give an attitude rate command because my object would start to rotate and this is not practical). FYI and for completeness: my object is a drone, but I don't think it matters too much regarding my question.

• You said, The main problem is I cannot give an attitude rate command because my object would start to rotate and this is not practical, but then what are you expecting is going to happen if you give a step command for attitude? – Chuck Mar 26 '20 at 14:26

You can operate the quadcopter with a poorly tuned attitude rate PID, log relevant quantities, build a model from the data, and finally use the model to tune the PID iteratively.

Suppose that such an inner PID delivers voltage commands to the propellers. You could instruct the quadcopter to safely perform a bunch of maneuvers and at the same time log/acquire the data you will then use to build the model. Candidate data will consist of pairs of voltage and measured speed samples.

The key point here is to control the quad such that the acquired dataset will be informative enough to support the subsequent identification stage. To this end, alternate low and quick maneuvers with different amplitudes. Anyway, since the inner and outer loops will be operational, the quad will fly safely.

Using those data you can perform closed-loop identification via the Predicted Error Method (PEM). Typical PEM based approaches resort to the well-known ARX, ARMAX, BJ, OE structures.

Once done with the model, you could tune your PID based on such knowledge by employing standard methods like pole placement, loop shaping and the like. If you use MATLAB, there exist automatic techniques for that.

Iterate through this process multiple times until you get acceptable performance.