Simulink bug - adding a PID only to scope creates large fluctuations

14 views (last 30 days)
I am a student doing a homework assignment and encountered this bug. Is this a known bug? Couldn't find anything when I searched for it.
I'm trying to implement a PID control loop. However, I noticed that the PID block's transfer function has an extra parameter (N) that I wasn't taught. I looked it up online and I understand why it's there, but nevertheless, I noticed that the "derivative" block doesn't require the same parameter (it requires a "c" parameter which defaults to inf, whereas N can't be set to inf) so I decided to implement PID "manually" using the derivative block, and compare the results with the built-in PID block using the default N and c values.
I created this system:
With the PID block and scope deleted or commented out, the "hand-crafted" PID system works as expected:
However, when I enable the PID and scope blocks, even though they should not affect any other part of the system, I get massively different results:
I assume that somehow the existence of the PID block triggered some (bad) optimization for the derivative block, creating this unexpected result. This is just conjecture of course.
I've attached the .slx file to this post so you can inspect this behavior yourself (not all values and parameters are visible in the screenshot).
This is a pretty crazy bug. Luckily it doesn't actually mess up my usage, but if I were to encounter it in any real-world usage it would be horrifying. How would I work around this?
Nitai Sasson
Nitai Sasson on 15 Jun 2020
I don't know how to check. I've exported it to R2019a though, hopefully it'll exhibit the same behavior and you can play around with it.

Sign in to comment.

Accepted Answer

Jonas on 15 Jun 2020
Edited: Jonas on 15 Jun 2020
Your solver settings change when you uncomment the PID(s). If you fix the solver to ode45 for example, the simulation runs ok. You can click on the link at the bottom right corner of your Simulink window to change it.
I think it is a good time for you to learn more about the solver settings as it can have a significant impact on the simulation results as you can see.

More Answers (2)

Fangjun Jiang
Fangjun Jiang on 15 Jun 2020
Edited: Fangjun Jiang on 15 Jun 2020
It is not a bug. Don't claim it is a bug when you have no idea. You need to learn how digital simulation solves an analog problem (derivative). Your constructed PID controller is a therotically ideal controller which can't be implemented in real world. While the Simulink PID controller is a realistic one that can be implemented in a digital controller.
If you don't know how to check the solver settings, then I bet the settings are all auto. The Simulink solver is looking into the stiffness of the simulation and adjusts the solver, the tolerance and the step size. That is the cause of the fluctuations. You could comment out your own PID controller and connect the Simulink PID controller and see what happens using the default auto settings. Most likely, it is your ideal derivative that causes the stiffness of the simulation.
Press Ctrl+E at your model, click "Solver" at the left column and look into all the settings. Click "Help" button to bring up the document. Or, hover over any one item, e.g. "Max step size", right click, then select "What's this?"
Fangjun Jiang
Fangjun Jiang on 15 Jun 2020
  1. Using auto solver, either comment out your own PID controoler, or comment out the Simulink PID controller, the simulation runs properly. The fluctuation only happens when both PID controllers are simulated. It is like the auto focus of a camera. It is tough to make the face of the person and the background mountain landscape focused at the same time.
  2. I am suprised that changing solver to ode45 would make the simulation run properly. In this sense, the Simulink "auto solver selection" is kind of "buggy".

Sign in to comment.

Saeed Ahmadzadeh Mahboobi
Edited: Saeed Ahmadzadeh Mahboobi on 8 Feb 2021
I'm having a similar problem:
Once I just use an I-Controller (turning the built-in PID to I-Controller) and once I build the I-Controller myself by connecting a "gain" and an "integrator" in series... and I get two different results.
Honestly even after reading the Replies here I haven't got what the problem really is, but at least I know that someone else has also had the same problem like mine




Community Treasure Hunt

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

Start Hunting!