Arkadiy Turevskiy, MathWorks
Design a PID controller for a DC motor modeled in Simulink®. Create a closed-loop system by using the PID Controller block, then tune the gains of PID Controller block using the PID Tuner.
In this demonstration you will see how to quickly tune the PID controller for a planned model in Simulink.
In this particular case, we model the DC motor. In this block dialog are the parameters that define the behavior of the motor: damping, inertia, back EMF, resistance, and inductance.
Working on their block mask we see Simscape and Simutronics blocks. We use the model as a motor. We will not design the digital control systems that will control the rotation speed of the motor shaft. The controller will calculate the error signal between the desired speed and the measured speed, and it uses our signal to calculate the voltage request to command to the motor.
Notice that we are modeling sensor noise in the measurement channel, and because our control system is digital, they are also modeling an A to D converter is a sampling time off 0.02 seconds, using a zero order over the whole block.
You now need to add the compensator. To do that, we go to Simulink Library Browser and just create sub library. Take discrete PID controller block and add it to our model. Let's now connect this block to the rest of our model and open the block dialog.
Here we can specify the type of controller we want to use: PID, PI, PD, proportional, or simply integral. We will stay this at PID. We can specify the sampling time. In this case we'll use the same one as we used in our A to D converter. And if you know the gains of the PID controller, we can type them in here. In this case, we don't know what the gain should be yet, so let's apply the sampling time changes and try running the simulation as default gain values. Let's also add voltage to our scope.
Running the simulation, we see that our control system was not doing all that well. Blue lines show the desired speed, and a red line shows actual measured speed. As we see, our control system is not tracking very well. Let's try to improve that performance. To do that we'll go back to the block dialogue and press the Tune button.
This launch has paired the tuner, which linearizes a plan, calculates PID gains, and opens a graphical user interface. In the graphical user interface we see two lines. The dashed line shows a closed loop step response of our system for the current gain values. And solid lines show the same response for calculated gain values.
So let's simply accept the gains to calculate it for us. When we do that, we see that our block parameters, PID gains, get updated. Let's press OK, go back to our simulation, and rerun it. As we see, we indeed improve the performance of our control system. It is now tracking very well with zero steady state error. It's relatively fast and has relatively little overshoot.
If you want to improve the performance of our control system, we can come back to the PID tuner graphical user interface and, for example, try to make the overshoot a little lower, if you want that. Or if you want faster response, we could try to use a slider here to move it to the right to make the system response faster.
For example, let's try this design. We now go back to our model and we run the simulation with this design. We see that we indeed get much faster response, but at the expanse of much noisier and much higher voltage request signal, so we are probably sacrificing actuator life to achieve this faster response.
Now, this is a trade-off you can decide on as an engineer, but you now have this tool at your disposal that lets it quickly design and tune PID controllers for plans modeled in Simulink. This concludes the demo.