Continuous to Discrete Conversion
Root Locus Design
In this digital DC motor control version of a DC motor, the controller will be designed by a Root Locus method. A digital DC motor model can obtain from conversion of analog DC motor model, as we will describe. According to the Modeling a DC Motor, the open-loop transfer function for DC motor's position was derived by Laplace Transform as shown.
From the design requirement, let the sampling time, T equal to 0.001 seconds, which is 1/100 of the required time constant or 1/40 of the required settling time. Let's create a new m-file and add the following Matlab code:
R=4; L=2.75E-6; K=0.0274; J=3.2284E-6; b=3.5077E-6; num = K; den = [(J*L) (J*R)+(L*b) (R*b)+(K^2) 0]; T = 0.001; [numd,dend] = c2dm(num,den,T,'zoh')Matlab should return the following:
num = 0 0.0010 0.0010 0.0000 den = 1.0000 -1.9425 0.9425 0.0000As noticed in above results, both numerator and denominator of discrete transfer function have one extra root at z = 0. Also, we have to get rid of the leading zero coefficient in the numerator. To do this add the following code to cancel out these extra pole and zero to avoid numerical problem in Matlab. Otherwise it will consider both numerator and denominator to be fourth-order polynomial.
numd = numd(2:3); dend = dend(1:3);Therefore, the discrete-time transfer function from the motor position output to the voltage input is:
We would like to see what the closed-loop response of the system looks like when no controller is added. First, we have to close the loop of the transfer function by using the cloop command. After closing the loop, let's see how the closed-loop stairstep response performs by using the dstep and the stairs commands. The dstep command will provide the vector of discrete step signals and stairs command will connect these discrete signals (click here for more information). Add the following Matlab code at the end of previous m-file and rerun it.
[numd_cl,dend_cl] = cloop(numd,dend); [x1] = dstep(numd_cl,dend_cl,501); t=0:0.001:0.5; stairs(t,x1) xlabel('Time (seconds)') ylabel('Position (rad)') title('Stairstep Response:Original')You should see the following plot:
rlocus(numd,dend) title('Root Locus of Original System') zgrid(0,0)
To get the zero steady-state error from the closed-loop response, we have to add an integral control. Recall that the integral control in the continuous- time is 1/s. If we use the backward difference approximation for mapping from the s-plane to the z-plane as described by s = 1/(z-1), one pole will be added at 1 on the root locus plot. After adding extra pole at 1, root locus will have three poles near 1, therefore the root locus will move out in the right half. The closed-loop response will be more unstable. Then we must add one zero near 1 and inside the unit circle to cancel out with one pole to pull the root locus in. We will add a pole at z = 0.95. In general, we must at least add as many poles as zeroes for the controller to be causal. Now add the following Matlab commands in to your m-file.
numi = [1 -0.95]; deni = [1 -1]; numad = conv(numd,numi); denad = conv(dend,deni);Recall from the Digital Control Tutorial page, the zgrid command should be used to find the desired region, which satisfies the design requirement, on the discrete root locus plot. The zgrid command requires two arguments: the natural frequency (Wn) and the damping ratio (zeta). From the design requirement, the settling time is less than 0.04 seconds and the percent overshoot is less than 16%. We know the formulas for finding the damping ratio and natural frequency as shown:
The required damping ratio is 0.5 and the natural frequency is 200 rad/sec, but the zgrid command requires a non-dimensional natural frequency. Therefore Wn = 200*T = 0.2 rad/sample. Add the following Matlab code into the end of your m-file and rerun it.
rlocus(numad,denad); zgrid(0.5,0.2) title('Root Locus of system with integral control')You should get the following plot:
From the above root locus plot, we can see that system is unstable at all gains because the root locus is outside the unit circle. Moreover, the root locus should be in the region where the damping ratio line and natural frequency cross each other to satisfy the design requirements. Thus we have to pull the root locus in more by first canceling the zero at approximately -0.98, since this zero will add overshoot to the step response. Then we have to add one more pole and two zeroes near the desired poles. After going through some trial and error to yield the root locus in the desired region, one more pole is added at 0.61 and two zeroes are added at 0.76. Add the following command in your m-file and rerun it in Matlab window.
numc = conv([1 -0.76],[1 -0.76]); denc = conv([1 0.98],[1 -0.61]); numoc = conv(numad,numc); denoc = conv(denad,denc); rlocus(numoc,denoc); zgrid(0.5,0.2) title('Root Locus of Compensated System')The denoc will have a pole at 0.61 instead of -0.98. You should get the following root locus plot:
From the above root locus plot, the root locus is drawn in the desired region. Let's find a gain, K, on the root locus plot by using the rlocfind command and obtain the stairstep response with the selected gain. Enter the following commands at the end of your m-file and rerun it.
K = rlocfind(numoc,denoc) [numd_cl,dend_cl] = cloop(K*numoc,denoc); [x2] = dstep(numd_cl,dend_cl,251); t=0:0.001:0.25; stairs(t,x2) xlabel('Time (seconds)') ylabel('Position (rad)') title('Stairstep Response of Compensated 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:
The selected gain should be around 330, and it will plot the closed-loop compensated response as follows.
From the above closed-loop response, the settling time is about 0.05 seconds which is satisfy the requirement, but the percent overshoot is 22% which is too large due to the zeroes. If we select the gain to be larger, the requirements will be satisfied. On the other hand, the problem will be unrealistic and a huge actuator is needed, you can try this yourself by picking a larger gain on the previous root locus plot which will yield an unrealistically sudden step response. So we have to move both one pole and two zeroes a little further to the right to pull root locus in a little bit more, new pole will be put at 0.7 and two zeroes should be at 0.85. Go back to your m-file and change only numc and denc as shown below and rerun it in Matlab window.
numc = conv([1 -0.85],[1 -0.85]); denc = conv([1 0.98],[1 -0.7]);Then you should see the following root locus plot.
On the new root locus, you should click on the plot to select a new gain as the following:
The selected gain should be around 450, and then it will plot the closed-loop compensated response as follows:
Now we see that the settling time and percent overshoot meet the design require ments of the system. The settling time is 0.04 seconds and the percent overshoot is about 10%.
Then let's take a look at a disturbance response of the closed-loop system by canceling the selected gain, the integral transfer function and controller's transfer function from the closed-loop transfer function. So add the following code into your m-file and rerun it.
numcld = conv(numd_cl,conv(denc,deni)); dencld = conv(dend_cl,conv(K*numc,numi)); [x4] = dstep(numcld,dencld,251); t=0:0.001:.25; stairs(t,x4) xlabel('Time (seconds)') ylabel('Position (rad)') title('Stairstep Response of Compensated System')Matlab should return the following plot:
We can see that a response to the disturbance is small (3.3% of the disturbance ) and settles within 2% of the disturbance after 0.04 seconds and eventually reaches zero.
Tutorials