PID Controller in MATLAB/Simulink using Transfer Function approach | PID Controller in MATLAB | How to simulate PID Controller in Simulink

Source: MathWorks
Source: MathWorks
 

REVISION



In previous blog, we saw what is control system, what is PID controller and it's basic explanation. I really hope you all are familiar with all these concepts and now we can further go to MATLAB/Simulink application of this controller.

Steps to Simulation

It has always been observed that with low RAM or after internet connection, the MATLAB/Simulink become slow in functioning. The Simulink takes time to open, so using command line to open Simulink would be better.

Command Line text for MATLAB


Follow the steps after opening the blank Simulink Model now add the following blocks:
1. Transfer fcn
2.  Add block
3. Step
4.  PID block

Now connect all this in given formation in this image


Now open the transfer function block and configure it like this


In this, the array of the numerator coefficients of  s², s and constant, must be written and same as for denominator as highlighted. Now open the PID controller block and given this dialogue box will appear.


Select the highlighted configuration parameters. Now click on Tune button as shown in RED circle. This tuning of parameters of Kp, Ki, and Kd and filter coefficient can be obtained. A new dialog box will appear for tuning the PID tuning. The best thing of the Simulink is it automatically recognize the plant model and try to give the best tuning value of these parameters. Since we generally use parallel PID controller in industry. Many people ask what is filter coefficient? 

The filter coefficient is used to implement derivative action. Since implementing something like "Kd*s"  is not possible since implementing improper transfer function is not possible.

So basically it just limiting coefficient for derivation operation.

PID Tuner Dialogue box
Now after opening of this dialogue box, I have highlighted some boxes in red with number on it whose description is as follows.
  1.  Tuning Tools: This tool is used to make tuned response of the plant as fast or slow, robust or  aggressive. As the system becomes fast and aggressive, the overshoot percentage becomes high and not good for step response of the plant as it may be dangerous. Slow and robust system have accuracy but slow response is not accepted in many systems as it may lead to wastage of material and energy.
  2. Show parameters: This option gives the comparative data of step response of the block before tuning and after tuning, with P, I , D and N value as shown in this figure. In general, following parameters must be maintained.
    • Peak Overshoot: < 10% - 12%
    • Settling Time: 2 sec - 5 sec
    • Rise Time: < 2 sec
    • Closed loop system must be stable and no oscillations
  3. Parameters: These are some important parameters that must be controlled as per above units.
  4. Update block: Now, after controlling all these parameters and tuned response, all values will be updated using this button.
Now close this dialogue box and in PID controller block click on OK button and now proceed to simulate the model. 
PID scope output

Now this output of PID controller is gives 50% error as it is poorly tuned and only P controller is been used. Only P value is considered with this system. Now let's compare all the controller in PID block and observe their response. All the PID controller options, P, I, PD, PI, PID and without feedback can be seen in below figure.

PID controller comparison

Let's see the scope output now
PID Scope Output

Depending upon the transfer function, it can be concluded that which controller will be suitable for plant. Here the PD controller look more suitable due to less overshoot and high response time, but there is a steady state error that in always there which by the time increases and may lead to oscillations. With this graph, it is easily observable the comparative analysis of the tuned step response of the blocks.

Bonus Simulations:

Major of the people ask about ideal PID vs parallel PID controller and it is sometimes very problematic to have comparative study of both. For that I created a simulation for the purpose.

Ideal PID controller


Parallel PID controller



Comparison between both types of controllers
As from the scope output, from the same value of P, I, D and N, the step response varies due to internal organization of these blocks. Generally in industry parallel PID is preferred due to it's programmable realization, more robustness, and better noise immunity. 

Summary

Here, we saw how to use PID block in Simulink and compared different outputs of different blocks. The tuning of PID must be so that the parameters adhere to given constraints and viola... its tuned and smooth output response is achieved. I have used the same approach to tune for a DC motor integrated with Arduino and the rpm was controlled with input from IR sensors to follow the line in line follower robot. 

Message from me

Hello folks...!!! I pray this pandemic treats you well. First of all I am sorry for posting so late. I hope you must have got the idea how to tune and use PID block in Simulink. In future blogs, I will be covering other approaches for tuning the PID block, like frequency based tuning and transfer function prediction with input-output data as well as state space based plant's controller. Till then please practice this with different stable, unstable, and marginally stable 2nd order transfer function.

Regards

-Curious Silly Yours

😀😀😀

Comments

  1. Thank you so much for this crystal clear explanation in very simple language...
    Waiting for further contents . . :)

    ReplyDelete
  2. Nice explanation and very simple language.

    ReplyDelete
  3. Thank you so much for such a nice explanation.

    ReplyDelete
  4. Thank you so much for the great explanation with examples and simple language. Waiting forward to your new blogs with good concepts.

    ReplyDelete

Post a Comment

Popular posts from this blog

Simscape Library | HIL testing Simulation in Simulink | Simscape blocks and their application in Simulink | MATLAB/Simulink based simulated HIL testing

Introduction to Control System | Application of Control System | Open Loop and Closed System | Types of Feedback systems