How to use PID controller
显示 更早的评论
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 个评论
Sam Chak
2024-9-4
It is possible. However, if you do not wish to tune the PID controller through trial-and-error or aimless autotuning, then the mathematical model (preferably in transfer functions) enclosed in the red frame must be known. Since the transfer function of the actuator is provided, the remaining task is to derive the transfer function of the heater in the blue frame.
Ideally, the transfer function derived from first principles should match the transfer function estimated by the Simulink Model Linearizer. Unfortunately, I am unfamiliar with Simscape. Most Simscape documentation provides the physics, such as that of the Pipe (TL), but does not directly offer the transfer function, which is preferred in future release.
If you encounter difficulties, you may consult @Yifeng Tang, who is an expert and regularly addresses Simscape application-related issues.

Shivam Gothi
2024-9-4
Can you please share the simulink model of the above closed loop system? It will be usefull to tune the PID controller and also test its performance.
Muhammad Ali
2024-9-16
Yifeng Tang
2024-9-17
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.
采纳的回答
更多回答(1 个)
Shivam Gothi
2024-9-16
0 个投票
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 个评论
Muhammad Ali
2024-9-17
Shivam Gothi
2024-9-17
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
2024-9-17
类别
在 帮助中心 和 File Exchange 中查找有关 Real-Time PID Autotuning 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







