PID controller design using Simulink MATLAB : Tutorial 3

In this tutorial, a simple PID (Proportional Integral Derivative) is designed using MATLABs’ Simulink. At the start a brief and comprehensive introduction to a PID controller is given and a simple block diagram which can help you to implement a PID controller on a simple input on your own. After that a simple example is provided in which the controller is designed using Simulink. We can design a PID controller on Simulink in two different ways, each of the two ways is implemented and after the implementation the results from both the methods are compared. At the end a simple exercise is provided regarding the concepts and blocks used in this tutorial. You may also like to check these tutorials on Simulink:

Introduction to PID controller

PID (Proportional Integral Derivative) controllers are the most widely used controllers in industrial settings because of their ease of use and the satisfaction of performance they are capable to provide the user for a large number of processes. Although the cost/benefit ratio provided by these controllers is way more than provided by any other controller. Many techniques have been proposed for their design, because of their widespread use, for the tuning of the parameters of PID i.ie Kp, Ki and Kd and for the implementation of additional functionalities that improve their performance.PID controller design using Simulink MATLAB :  Tutorial 3

Figure 1: PID control

Control loops are used almost everywhere now a day. Anytime we adjust our current works according to the results obtained in previous results we form a control loop. For example, when we feel cold and turn our heater on we form a feedback loop, and when we press the accelerator of a car whenever we are getting late we again for a control loop.Whenever we change make any change in environment by sensing the previous results of that process we form a closed control loop in our mind. Changing the speed of the car is one of the best examples. The block diagram of a simple PID controller is provided in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 2: PID block diagram

PID controller design using Simulink MATLAB

Lets’ now move towards a simple example regarding the working of a simple PID controller using Simulink. In Simulink a PID controller can be designed using two different methods. Simulink contains a block named PID in its library browser. We can implement the PID controller by either using the built in PID block or we can design our own PID controller using the block diagram in figure 2. The results of both of them are however not the same as you will see shortly. Lets’ now begin with the programming part. Open MATLAB and then Simulink as we have down in previous tutorials. After that open the library browser and from the library browser select the continuous sub block as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 3: Continuous sub block

  • Double click on the continuous block in the library browser and from that block select the PID block as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 4: PID controller

  • This block will be used as the PID controller itself. The next we need a supply i.e. a step response to apply the PID on. Now from the simulink library browser select the sources as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 5: Sources

  • From the sources subsection, now select the Step block which will be used as an input source to the PID block as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 6: Step response

  • Now click on the sinks subsection from the list at the left of the library browser as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 7: Sink

  • From the sinks subsection select the scope which will be used to display the output. You can also access the scope block from the commonly used blocks section in the library browser. Also if you do not know where exactly the block is placed in the library browser of simulink you can also search the block by typing its name in the search bar in the library browser. Refer to the figure below to see the scope block selected from the sinks section.PID controller design using Simulink MATLAB :  Tutorial 3

Figure 8: Scope

  • We also need a system to apply the PID controller on it. By placing a system here what I actually meant is to place a transfer function of the system in the block diagram. We can get a transfer function block from the continuous section of the library browser of the simulink as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 9: Transfer function

  • The last block left to be placed is the sum block which will be used to subtract the feedback path of the closed loop system. The sum block can be obtained from the commonly used blocks as shown in the figure belowPID controller design using Simulink MATLAB :  Tutorial 3

Figure 10: Sum block

  • The placed components so far are shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 11: Placed components

  • What we need to do know is to change the parameters and properties of all the blocks according to the current requirement. For instance, lets’ first change the list of signs in the summation block as we need the second sign to be negative to subtract the feedback path from the current input as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 12: List of signs

  • Now we need to update the transfer function according to our need. Double click on the transfer function block and change the values of numerator and denominator as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 13: Transfer function

  • Double click on the step response block and adjust the properties as shown in the figure below. This is done so because we need to start our step from time 0s.PID controller design using Simulink MATLAB :  Tutorial 3

Figure 14: Step response

  • Now double click on the PID block and change the values of Kp, Ki and Kd as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 15: PID parameters

  • These are just a hint we can update them later for the tuning purpose of PID. Connect all the block with wires and complete circuit diagram will look like as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 16: Block diagram

  • The only step left is to update the model configuration according to the step response and adjust the sampling time of the system. Click on the model configuration icon as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 17: Model configuration

  • In the model configuration dialog box, change the variable step to fixed steps and change the sampling time to 0.01s as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 18: Model configuration steps

  • These properties have a great impact on the response of the system. Now run the system from the run icon at the top of the simulink page as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 19: Running

  • After running open the scope to see the generated waveform. The output of the waveform is shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 20: Output

  • The output is a little overdamped and we can adjust it by tuning the values of Kp, Ki and Kd.
  • Lets’ now move toward the other method. Place 3 gain blocks in row and at the input connect the output of the step block and name them as Kp, Ki and Kd. Refer to the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 21: Gain blocks

  • At the output of the Ki block place an integral block as we have used previously. And from the continuous section of library browser select the derivative block as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 22: Derivative block

  • Place this block at the output of the Kd gain block and sum up all these gain using a sum block as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 23: PID controller

  • Adjust the values of the gain as we have adjusted in previous method and the complete block diagram of the PID controller is shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 24: Complete block diagram

  • Run the block diagram again and open the scope to see the response of the system as shown in the figure below,PID controller design using Simulink MATLAB :  Tutorial 3

Figure 25: Output

The output is slightly underdamped and it can be adjusted by tuning the gains of the PID controller and it is left as an exercise for the reader.

Exercise:

  • Tune the values of Kp, Ki, and Kd try to make the step response of the transfer function critically damped.

Leave a Comment

shares