Accelerating the pace of engineering and science

PID Controller Design for a DC Motor

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.

 Video Transcript

In this demonstration you will see how to quickly tune a PID controller for a plant modeled in Simulink.

Read more

In this particular case we modeled a DC motor.

In this block dialog you see the parameters that define the behavior of the motor: damping, inertia, back EMF, resistance and inductance. Looking under block mask we see Simscape and SimElectronics blocks we used to model the motor.

We will now design a digital control system 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 use this error 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 we are also modeling an A/D converter with a sampling time of 0.02 seconds using a Zero Order Hold block.

We now need to add the compensator. To do that we go to the Simulink library browser, Discrete sub-library, take the 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 with PID.

We can specify the sampling time, in this case we’ll use the same one as we used in our A/D converter.  And if we know the gains of the PID controller, we can type them in here. In this case we don’t know what the gains should be yet, so let's apply the sampling time changes and try running the simulation with default gain values. Let’s also add voltage to our scope.

Running the simulation, we see that our control system is not doing all that well. Blue line shows the desired speed, and red line shows the 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 dialog and press the "Tune" button. This launches PID Tuner which linearizes the plant, calculates PID gains and opens the graphical user interface.

In the graphical user interface we see two lines: dashed line shows the closed loop step response of our system for the current gain values and solid line shows the same response for calculated gain values.

So let’s simply accept the gains tool calculated for us.  When we do that we see that all block parameters, PID gains, get updated. Let’s press "OK", go back to our simulation and rerun it. As we see, we indeed improved 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 we 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 we want that, or if we 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 rerun the simulation with this design.

We see that we indeed get much faster response but at the expense of much noisier and much higher voltage request signal so we are probably sacrificing actuator life to achieve this faster response. Now this is the trade-off you can decide on as an engineer, but you now have this tool at your disposal that lets you quickly design and tune PID controllers for plants modeled in Simulink.

This concludes the demo.

Die Arbeitsweise der folgenden Werkzeuge wird gezeigt

  • Simulink Control Design