How to use PID controller

146 次查看(过去 30 天)
Muhammad Ali
Muhammad Ali 2024-9-4,13:34
评论: Yifeng Tang 2024-9-17,13:37
I have a control loop such that:
  • The loop starts by calculating the error between the desired and measured temperature.
  • The relay block turns the heating system on or off based on this error, with a hysteresis of ±5 degrees to prevent frequent switching.
  • The output from the relay (on/off signal) is passed through a transfer function to simulate the dynamics of the system (introducing a delay or lag in the heating response).
  • The scaled output from the transfer function (now a power signal) is converted into a physical signal.
  • Finally, the physical signal controls the heat source, which in turn affects the system's temperature.
I want to use PID controller block instead of this, how can I achieve that?
  4 个评论
Muhammad Ali
Muhammad Ali 2024-9-16,14:31
Hello Shivam, I have attached the simulink model of the system, the system where I am trying to put at the moment is the heating system (as you will see in the model) which I will then include in the user side as well. Please let me know if you need anything else.
and apologies for the late reply
Yifeng Tang
Yifeng Tang 2024-9-17,13:37
I've done something similar to this. PID tuner does the job. It will first attempt to linearize the fluids systems, which is usually not that linear :p So it matters at which time you do the linearization (I think you can choose that in the tuner). Usually t=0 is NOT a good point to do the linearization. I've found that using a time where the system has stablized tends to give you a linearized system that's more useful.

请先登录,再进行评论。

采纳的回答

Shivam Gothi
Shivam Gothi 2024-9-5,4:55
As mentioned by @Sam Chak, The most proper way to design a PID controller is by modelling of plant and making its linear model. You can then use an input-output transfer of this model to decide the PID controller gains that satisfies the required time or frequency domain specifications.
However, I was just searching across the MATLAB documentation and discovered that SIMULINK offers a convenient feature that might interest you.
The "PID Tuner App" in SIMULINK can automatically tune PID controller parameters to achieve your desired time or frequency domain response. It has an impressive graphical user interface, allowing the user to enter rise time, settling time, and other time domain specifications to be satisfied by the resultant closed loop system. When the "PID Tuner" launches, the software computes a linearized plant model seen by the controller. The software automatically identifies the plant input and output, and uses the current operating point for the linearization
For further information on the "PID Tuner App," you can refer to the following documentation:
I tried to reproduce the system, somewhat similiar to that demonstrated by you in the attached image. Below given figure demonstrates it. I have also attached the Simulink file along with this answer.
Properties of blocks:
System response with “on/off” relay:
I set a reference temperature of 305 kelvin, and the hysteresis of +-2 degrees. Below given is the response of temperature of the pipe with respect to time. You can see that it is between hysteresis band, but non-steady.
System response with PID controller:
Follow the following steps to use a PID controller:
  • Add a “PID(s)” block (as shown in below image) to your model.
  • Open the block parameters of "PID controller" by double clicking it. Go to the “main” tab, and click on “tune” button under the “Automated tuning” section.
  • “PID tuner App” will open as shown below:
  • Adjust the “rise time” and “transient behavior” from the sliding bars as per your requirements.
  • To view the (“P”, “I”, and “D”) values computed by “PID tuner App, click on “show parameters” icon on the top menu bar.
  • Click on ” Update Block” button on top menu bar to automatically set the parameters of PID controllers.
  • Now close the “PID tuner App” and open the “block parameters” of “PID controller”. You will see the updated values of the controller gains.
  • Run the model.
  • The below given scope waveform shows the temperature of the pipe when PID controller is used.
Conclusions:
We can see that now temerature is controlled in very smooth way and steady state error is also zero.
This is the basic guidline to automatically tune the PID controller for your system. I have attached the simulink file. You can make changes to it according to your requirements, but repeat the above steps to tune your "PID" parameters again, as the plant is changed.
I hope this helps and is as per your expectation!
  1 个评论
Muhammad Ali
Muhammad Ali 2024-9-16,14:38
Thanks a lot @Shivam Gothi.
This is really helpful but I just dont understand the curve when I open the tuner App. It doesnt make any sense, the amplitude!
I have attached my model in your previous response.

请先登录,再进行评论。

更多回答(1 个)

Shivam Gothi
Shivam Gothi 2024-9-16,16:50
I followed the same steps as suggested in above answer and got good results. I am attaching the modified simulink file.
You need to first connect the PID controller block in the network and then click on "tune" button. The tuner app will decide the gains best suitable to achieve the specified performance. Below given is the screenshot of "PID tuner app" I used in your attached model.
the screenshot from scope inside the "temperature control block" found inside "heating system" is shown below:
Please let me know whether this is correct and as per your expectation.
  3 个评论
Shivam Gothi
Shivam Gothi 2024-9-17,8:47
I have saved and attached the Simulink model files in the R2023a version. Please let me know if you are able to open them successfully. Additionally, if any of the responses meet your expectations and prove useful, I would appreciate your feedback or if you could mark the answer as accepted.
Muhammad Ali
Muhammad Ali 2024-9-17,9:10
Thanks a lot @Shivam Gothi. This indeed has been very useful.
something I was doing wrong, which I haven't figured out yet. If I do, I ll post it here as well.
Thanks again!

请先登录,再进行评论。

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by