Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PID implementation - Parallel vs Ideal #12362

Closed
bresch opened this issue Jun 28, 2019 · 7 comments · Fixed by #12472
Closed

PID implementation - Parallel vs Ideal #12362

bresch opened this issue Jun 28, 2019 · 7 comments · Fixed by #12472

Comments

@bresch
Copy link
Member

bresch commented Jun 28, 2019

I wanted to discuss a bit in this issue the different types on PID controllers. The main reason is that I find the current implementation not intuitive to adjust manually.

Parallel:
This is the current implementation of the rate and velocity controllers in PX4. The specificity of that implementation is that the P, I and D path are independent. This sounds to be a good idea, but in practice it is not practical because modifying the proportional gain (P) changes the integral and derivatives actions. Consequence: both decreasing or increasing the P gain can destabilize the system because decreasing P increases the integral effect.
PID_parallel

Ideal:
This implementation is widely used in commercial controller as it decouples the integral and derivative actions from the proportional gain: The gain of the controller is defined by the P gain, the integral action by its time constant Ti (or Ki' = 1/Ti) and the derivative action by Td (or Kd' = Td).
PID_ideal

Describe problem solved by the proposed feature
Adjusting a parallel PID controller requires to modify all three gains together. This a a reason why the tuning sequence is "Set I and D to zero, tune P and D together and then add a bit of I to reduce the steady-state error." and that some vehicles are poorly tuned because "the integrator is scary".

Changing to the ideal form should make the tuning easier. In order to show why it is not intuitive, I collected some rate controller gains of the standard config files, computed the integral and derivative effects and plotted the integral effect with the Ki gain (scaled up) on the same graph.
On the graph, you can directly see that more Ki doesn't necessarily mean "more integral action".

Take for example the M100 and the Mid size quad 1: the M100 has 20% more integral action but it's Ki gain is three times smaller. Also, its derivative time constant is only 50% smaller even if Kd is 7 times smaller. This is simply because the proportional gain of those two vehicles are quite different, mainly due to different propulsion systems and inertia. Furthermore, Td is quite constant across the frames but Kd have to be tuned every time Kp changes.

I am convinced that a simple slider that changes the Kp' gain of an ideal PID would be enough to tune most of the vehicles.

PID_Survey_2

pid_survey_2

Implementation
We can easily convert the actual algorithm into a Ideal form by introducing a "Controller gain" Kc that multiplies Kp, Ki and Kd. This Kc can then be mapped to a slider in QGC to increase or decrease the performance/robustness of the controller.

FYI: @bkueng

@LorenzMeier
Copy link
Member

Very cool! Let's make sure we can execute on this on a fixed timeline.

@jlecoeur
Copy link
Contributor

Sounds very cool!

I was curious and displayed the gains you collected:
px4_gains

For the derivative part (left), it indeed looks like Kd was tuned together with Kp. Sounds like Kc=Kp, Kp'=1, Kd'=0.029 would be a good starting point.

For the integrator, however, there is no such correlation between Kp and Ki, two options:

  • the platforms were not properly tuned (as you said "the integrator is scarry")
  • the platforms were properly tuned, and it is better not to scale the integral action with Kc

@LorenzMeier
Copy link
Member

@jlecoeur It is important to note that we have protected against large I gains with this commit, so tuning can now include a large I gain:
ea31f34

I would also argue that a lot of airframe configs here would not stand an evaluation on what we consider "great performance", as we find that community-provided tuning values are hit-and-miss. My take-away is that we need to centralize these configs and make sure we have the same scrutiny on them as we have on code changes.

@bresch
Copy link
Member Author

bresch commented Jul 1, 2019

@jlecoeur Thanks for your input and the graphs. Yes, there is a quite clear linear relation between Kp and Kd.
There is no visible linear relation between Kp and Ki because Kp mainly depends on total thrust and inertia ratio while Ki depends essentially on the inertia of the vehicle.

  • Weak and heavy vehicle: high Kp, low integral
  • Powerful and heavy vehicle: low Kp, low integral
  • Weak and light vehicle: high Kp, high integral
  • Powerful and light vehicle, high Kp and high integral

(when I say "low integral", understand low 1/T1 or low Ki')

In summary, the integral time constant is more correlated with the size of the vehicle than Kp. This is why in the table of my original post (sorted by increasing 1/T1), the VTOL plane is at the top, the medium size drones at the middle and the racers at the bottom while the Kp gains seem more random (even if a racer usually have a much higher thrust-to-weight ratio than other drones).

I'll add a new variable for the "controller gain" with a default of 1.0 and try with different platforms to see if it's really easier to tune in practice. Since it only scales the other gains, there will be no visible changes for the current setups.

@jlecoeur
Copy link
Contributor

jlecoeur commented Jul 1, 2019

@bresch sounds good!

If it turns out that you often need to tune Kc and Ki separately then you may consider an "ideal-parallel" implementation where Kc scales both the proportional and derivactive actions, but not the integral action.

@bresch
Copy link
Member Author

bresch commented Jul 1, 2019

@jlecoeur In fact you still want to Ki with Kc because this decouples the static part (pure gain) from the dynamic tuning (integral and derivative time constants).

Intuitive example
Let's look at the following scenario:
You have a drone well tuned for you application with the gains Kp, Ki and Kd. Now, you want to update your lifting system to use 6S batteries instead of 4S and even if you changed the motors with a lower KV, the gain of the system is now higher. To obtain the same behavior as before, you have to adjust the gains.

  • Parallel PID: In parallel form, you would have to adjust together Kp, Ki and Kd (reducing Kp only might create oscillations). You will mot likely en up setting Ki to zero and start the tuning from scratch.

  • Ideal PID: Since the Kp' gain controls the overall gain of the controller, the only adjustment you need to do is to reduce this gain in order to keep the product Kp' x drone gain constant. Since nothing else changed on the drone there is no reason why the integral and derivatives time constants should change.

Proof
A more theoretical proof can be shown by inspecting the transfer functions of both Ideal and Parallel PID controllers:

We clearly see that the zeros of the ideal transfer function are defined by Ki' and Kd' while in the parallel form, the proportional gain affects the position of the zeros.

Edit: The equations were a bit oversimplified so I updated with more general and correct ones

@jlecoeur
Copy link
Contributor

jlecoeur commented Jul 1, 2019

Very clear explanation, thank you! Looking forward to seeing the PR ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants