# PID Control with Error Rotation Matrices?

I'm modeling a rocket with PID controllers for thrust vectoring.

The PID controllers take in attitude errors as input, then output engine gimbal actuator commands.

The attitude errors are individual roll, pitch, and yaw angles that I obtain from error rotation matrices coming from guidance calculations.

Everything in guidance is based on rotation matrices. The individual errors each feed into a separate PID controller---one for roll, one for pitch, one for yaw. Roll, pitch, and yaw are each defined in the rocket's main frame.

This all works great, but I'm bothered by my conversion from rotation matrix to roll/pitch/yaw. The conversion is approximate and works well up to ~10 deg errors. I got it from an old Apollo-era paper I found in the NASA repository, but which I've since lost track of.

I'm wondering: is there a way to pass the error rotation matrix directly to a single PID controller and have it output a vector of roll/pitch/yaw commands (in the rocket's axes)?

• Why not use quaternions?
– Paul
May 6, 2021 at 1:40
• Because I committed to rotation matrices early in the model. I’m looking to streamline what I have (by using my error rotation matrix directly as input to my PID controllers), not change it to something else. In another life, maybe. This model’s been a hell of a lot of work.
– user39728
May 6, 2021 at 2:08
• If you want something better than what you are using now, step 1 is to post what you are using now. Use MathJax for equations.
– uhoh
May 6, 2021 at 22:45
• I’m not asking for feedback on my model. Nor am I asking for suggestions on how to improve it. My question is very specific: “Is there a way to pass the error rotation matrix directly to a single PID controller and have it output a vector of roll/pitch/yaw commands?” The answer should be independent of any modeling I might have done.
– user39728
May 6, 2021 at 23:27
• Can you add links / references to some literature that you are following ? Have you searched for literature with keywords "PID control on rotation matrices" or "PID control on SO(3)" ?
– AJN
May 8, 2021 at 5:42

Error rotation matrix can be transformed to a required "angular velocity" (in body frame) using the inverse of the exponential map (I think it would be called a log map then).

The exponential and log mentioned are matrix exponential and matrix logarithm. The matrix logarithm is a costly operation, so it needs to be approximated for real-time implementation.

This "angular velocity" is a vector. The proportional part of the PID control can then be driven from this vector (one component each for each axis).

An alternate way to think about this is to remember that you can extract the eigen vector from the error rotation matrix to get the axis of rotation required to bring it to the reference. An angular velocity about this axis (with the correct sign) will bring the body towards the reference. The angle to be rotated can be used as the magnitude of error for computing the proportional term.

• Above answer mentions only a choice for the proportional term. 1 it may not be the best choice when a velocity error also exist. 2 ID part of the PID is not covered. The D part may be something as simple as directly using the angular velocity. 3 I part would be even more complicated, I think.
– AJN
May 8, 2021 at 5:40
• Ah! This is useful! I actually just found out that any rotation matrix Q can be expressed as the exponential of a skew matrix C, then approximated to first degree using the first two terms of a Taylor Series expansion---which gives exp(C) ~ I + C, where I is the identity matrix. The instantaneous attitude error is then ~(I + C) - I ~ C, which works for small errors (e.g., <10 deg). So the skew symmetric matrix C seems a path forward.
– user39728
May 8, 2021 at 14:11
• And as it turns out, the elements of the skew matrix C give the instantaneous errors about the x, y, and z axes---in the small-angle approximation assumed in the Taylor series expansion above. And those elements happen to be exactly what I've been using as errors all this time---just pulling them from my rotation matrix Q and feeding them separately to my roll, pitch, and PID controllers, a strategy I got from an Apollo-era navigation paper I've now lost track of, but which did just that, without mention of skew matrices, and probably because they were so computationally constrained.
– user39728
May 8, 2021 at 14:18
• This is so cool, because I can see the parallel between what I've been doing (which has worked very well) and what I would like to do (using rotation matrices directly). At a minimum, it sheds a new light on why this small-angle approximation that I picked up from that Apollo-era paper works.
– user39728
May 8, 2021 at 14:19
• But yeah, exact derivatives and integrals of an exp(C) matrix get convoluted fast, it seems, so the Taylor series approximation seems the only practical way to deal with them. And it seems that the derivative of a matrix Q is the matrix of element derivatives, dot(q_i), and that the integral of a matrix Q is the matrix of element integrals, int(q_i), which I guess explains why differentiating and integrating the elements of my approximate error vector [qx qy qz] has worked fine---because that vector is derived from the skew matrix which can be Taylor-expanded, then diff'd/int'd?
– user39728
May 8, 2021 at 14:56