Simulink bug - adding a PID only to scope creates large fluctuations
21 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Nitai Sasson
il 13 Giu 2020
Modificato: Saeed Ahmadzadeh Mahboobi
il 8 Feb 2021
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.
Background:
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/315504/image.png)
With the PID block and scope deleted or commented out, the "hand-crafted" PID system works as expected:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/315507/image.png)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/315510/image.png)
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?
2 Commenti
Jonas
il 15 Giu 2020
I can not view your Simulink file because I am still using version R2019a, but I would inspect the solver settings. Is the solver using a bigger sampling time with the added PID(s) block? Can you try to make sure the sampling time is kept small?
Risposta accettata
Jonas
il 15 Giu 2020
Modificato: Jonas
il 15 Giu 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/316527/image.png)
0 Commenti
Più risposte (2)
Fangjun Jiang
il 15 Giu 2020
Modificato: Fangjun Jiang
il 15 Giu 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?"
3 Commenti
Fangjun Jiang
il 15 Giu 2020
- 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.
- 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".
Saeed Ahmadzadeh Mahboobi
il 8 Feb 2021
Modificato: Saeed Ahmadzadeh Mahboobi
il 8 Feb 2021
Hi
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
0 Commenti
Vedere anche
Categorie
Scopri di più su PID Controller Tuning in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!