Units for the PID control loops
« on: February 27, 2019, 07:29:30 pm »
I'm currently working on project that involves modeling a quadrotor, including a CC3D flight controller.

I have a model of the physical drone dynamics and the structure of the CC3D controller, but I'm not sure sure what "units" the PID constants are. For example, I am currently using theses values that show up on LibrePilot for my FC https://imgur.com/a/cQRANYD

When I assume radians per second I get decent results: https://imgur.com/a/QDD5GyZ ,but I'd like to be sure. Degrees per second gives me a really slow response that seems unreasonable.

Are the units of the PID gain constants in (rad/s)/(rad/s) ?

Re: Units for the PID control loops
« Reply #1 on: February 27, 2019, 08:44:17 pm »
The internal calculations use degrees per second like the stick sensitivity roll rate uses for instance.  A quick look at the code:
  flight/libraries/math/pid.c
  flight/modules/Stabilization/innerloop.c
shows that the pid functions are called with deg/sec values and don't convert these into rad/sec.  The PID functions don't even know they are handling angle units at all.

There is some outdated code that multiplies (then divides) by 1000 in the pid_apply*() functions.  This was apparently done during a time when this used integer calculations.  It either is still needed to maintain compatibility with old PID values or is just a bad waste of processor time (assuming it doesn't get optimized out, which I can hardly imagine).

It is on my list to remove this */1000.0f stuff and see if the PIDs can be the same or not and to measure the CPU utilization change.  At least for my edification.  :)
« Last Edit: February 27, 2019, 08:52:34 pm by TheOtherCliff »

Re: Units for the PID control loops
« Reply #2 on: February 27, 2019, 10:32:13 pm »
Thanks!

So that means, in my simulated control loops I should be able to use the PID values displayed and make sure that the error is calculated using degrees/sec?

Re: Units for the PID control loops
« Reply #3 on: February 27, 2019, 11:04:49 pm »
I'm not even sure the PIDs can be described as having proper units.  (deg/sec)/(deg/sec) would imply that a setting of 0.003 on one vehicle would have the same rotational response to error as any other vehicle.

Ahh  Googling
PID units
says they are dimensionless.
?

============================

For instance the PID output differential is basically fed to the ESCs which then produce a rotational acceleration that depends on the thrust (torque) and rotational inertia which is different for each different vehicle.
« Last Edit: February 27, 2019, 11:10:22 pm by TheOtherCliff »

Re: Units for the PID control loops
« Reply #4 on: February 28, 2019, 12:56:42 am »
Yup, the PID gains are dimensionless I'm using the term units like "(deg/sec)/(deg/sec)" kind of like how we use V/V when describing op-amp gains. The units cancel, but the error needs be be calculated according to some dimensions. For example, an error of 100cm and and error of 1m can yield different result for a controller.

I believe I have it figured out now. If you are correct about the values in the code being degrees/second and never getting converted, I think it makes sense to convert my feedback of rad/s to match the input of degrees/second. Here's what I got if you're curious!

https://imgur.com/a/C7pxTYn

Re: Units for the PID control loops
« Reply #5 on: February 28, 2019, 05:22:56 am »
100cm=1m  :)  Well I understood what you meant.

The problem is that the settings in an underpowered vehicle will respond differently than the same settings in an overpowered vehicle.  The PIDs are where you tune them both to respond to the control or error as quickly as possible but one will get there quicker.

Given a single vehicle then yes, 10cm error should produce 1/10 the response of a 100cm error.