Example: Digital DC Motor Speed Control with PID Control

Continuous to Discrete Conversion
PID Controller

In this page, we will consider the digital control version of DC motor speed problem. A digital DC motor model can be obtained from conversion of the analog model, as we will describe. The controller for this example will be designed by a PID method.

From the Modeling a DC Motor Page, the open-loop transfer function for DC motor's speed was derived as:

Where:

*electrical resistance (R) = 1 ohm
*electrical inductance (L) = 0.5 H
*electromotive force constant (Ke=Kt) = 0.01 Nm/Amp
*moment of inertia of the rotor (J) = 0.01 kg*m^2/s^2
*damping ratio of the mechanical system (b) = 0.1 Nms
*input (V): Source Voltage
*output (theta dot): Rotating speed
*The rotor and shaft are assumed to be rigid

The design requirements for 1 rad/sec step input are

Continuous to Discrete Conversion

The first step in designing the discrete control system is to convert the continuous transfer function to a discrete transfer function. The MATLAB command c2d will do this for you. The c2d command requires the following three arguments: system, the sampling time (Ts) and method for conversion. In this example, we will use the zero-order hold ('zoh') method.

From the design requirement, let the sampling time, Ts equal 0.12 seconds, which is 1/10 the time constant of a system with a settling time of 2 seconds. Let's create a new m-file and enter the following commands:

Running this m-file should return the following:

After you have done this, let's see what the closed-loop step response looks like with a proportional gain of 1. The step command will do this for you. Click here for more information. Add the following MATLAB code to the end of previous m-file and rerun it.

You should see the following plot:

PID Controller

Recall that the continuous-time transfer function for a PID controller is:

There are several ways for mapping from the s-plane to z-plane. The most accurate one is . We cannot obtain PID transfer function in this way because the discrete-time transfer function would have more zeroes than poles, which is not realizable. Instead we are going to use the bilinear transformation shown below.

Thus we can derive the discrete PID controller with bilinear transformation mapping. For more detail on the derivation of the discrete PID controller, see the Discrete PID Controller Page. Equivalently, the c2d command in MATLAB will help you to convert the continuous-time PID compensator to discrete-time PID compensator by using the "tustin" method. The "tustin" method use the bilinear approximation to convert to discrete time. According to the PID Design Method for the DC Motor page, Kp = 100, Ki = 200 and Kd = 10 satisfy the design requirement. We will use all of these gains in this example. Now add the following MATLAB commands to your previous m-file and rerun it in MATLAB window.

Let's see if the performance of the closed-loop response with the PID compensator satisfies the design requirements. Now add the following code to the end of your m-file and rerun it. You should get the following closed-loop stairstep response.

As you can see from the above plot, the closed-loop response of the system is unstable. Therefore there must be something wrong with compensated system. So we should take a look at root locus of the compensated system. Let's add the following MATLAB command into the end of your m-file and rerun it.

From this root-locus plot, we see that the denominator of the PID controller has a pole at -1 in the z-plane. We know that if a pole of a system is outside the unit circle, the system will be unstable. This compensated system will always be unstable for any positive gain because there are an even number of poles and zeroes to the right of the pole at -1. Therefore that pole will always move to the left and outside the unit circle. The pole at -1 comes from the compensator, and we can change its location by changing the compensator design. We choose it to cancel the zero at -0.62. This will make the system stable for at least some gains. Furthermore we can choose an appropriate gain from the root locus plot to satisfy the design requirements using rlocfind. Enter the following MATLAB code to your m-file.

Note how the first line of code above allows you to change the denominator of the system transfer function directly, without having to redefine the system. The new closed loop poles will have a pole at -0.625 instead of -1, which almost cancels the zero of uncompensated system. In the MATLAB window, you should see the command asking you to select the point on the root-locus plot. You should click on the plot as the following:

Then MATLAB will return the appropriate gain and the corresponding compensated poles, and it will plot the closed-loop compensated response as follows.

The plot shows that the settling time is less than 2 seconds and the percent overshoot is around 3%. In addition, the steady state error is zero. Also, the gain, K, from root locus is 0.2425 which is reasonable. Therefore this response satisfies all of the design requirements.


Digital Control Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam

Motor Speed Examples
Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

Tutorials
MATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | State Space | Digital Control | Simulink Basics | Simulink Modeling | Examples