MATLAB Answers

Using Discrete PID Significantly Slows Down Simulation

13 views (last 30 days)
Aziz Alawadhi
Aziz Alawadhi on 21 May 2020
Edited: David Balbuena on 9 Jun 2020
Hello,
I am currently modeling a complex system with numerous joints and motors (from sim mechanics) and I ran into an issue while trying to discretize the system. To start, I modeled my PID controllers as continuos (I have 12 of them). I now wish to turn them into discrete-time PIDs.
However, when I switch the PID's to discrete, the simulation that used to take a couple of minutes to run now takes hours. Furthermore, as the simulation goes on, it only gets slower. When I switched the PID's back to continous, the simulation ran in minutes as it did before. I even tried to switch only one of the 12 PID controllers into discrete to see what effect it would have and the same thing ended up happening - the simulation would take hours. I tried this with two different solver types (ode15s and ode23t) and tried to reduce the solver's relative tolerance from 1e-3 to 1e-2 but it did not help.
Initially I used a PID sample time of 0.001 but this ran way too slow so i switched it to 0.01 and it started running faster but the simulation would still take hours.
Is there a reason why this is happening? And is there a way to get around this?
Thanks!

Answers (1)

David Balbuena
David Balbuena on 9 Jun 2020
Edited: David Balbuena on 9 Jun 2020
This is most likely happening because you have a discrete controller driving a continuous variable-step plant. As mentioned in this documentation page,
this scenario will trigger Solver Resets every time the discrete signal changes, which can impact the performance of your model. In R2019b, there was a new "First Order Hold" block added for this specific use-case (discrete controller driving continuous plant):
This block is introduced in greater detail in this blog post:
If you are in R2019b or later, feel free to give the First Order Hold block a try and see how that works.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by