Digital Control Example: Designing Cruise Control using Root-Locus method

In this digital control version of the cruise control problem, we are going to use the root-locus design method to design the digital controller. If you refer to the Cruise Control: Modeling page, the open-loop transfer function was derived as

where
• m = 1000
• b = 50
• U(s) = 10
• Y(s) = velocity output

The design requirements are

• Rise time: Less than 5 seconds
• Overshoot: Less than 10%
• Steady-state error: Less than 2%

## Discrete transfer function

The first step in performing a discrete analysis of a system is to find the discrete equivalent transfer function of the continuous portion. We will convert the above transfer function (Y(s)/U(s)) to the discrete transfer function using the MATLAB function called c2d. To use this c2d, you need to specify three arguments: system, sampling time (Ts), and the 'method'. You should already be familiar with how to enter num and den matrices. The sampling time (Ts), in the unit of sec/sample, should be smaller than 1/(30*BW), where BW is the closed-loop bandwidth frequency. For the method, we will use the zero-order hold ('zoh').

Let the sampling time equal 1/50 sec; this is sufficiently fast assuming that the bandwidth frequency is 1 rad/sec. Now enter the following commands into an m-file and run it in the command window.

```num = [1];
den = [1000 50];
cruise = tf(num,den);

Ts = 1/50;

cruise_d = c2d(cruise,Ts,'zoh')
```

The following matrices should be returned to the command window.

```	Transfer function:
1.999e-05
---------
z - 0.999

Sampling time: 0.02
```

## Root-Locus in z-plane

Recall from the Digital Control Tutorial, the MATLAB function called zgrid can be used to find an acceptable region of the discrete root-locus that gives the desired gain (K). The zgrid command requires two arguments: Natural frequency (Wn) and damping ratio (zeta). These two arguments can be found from the rise time and the overshoot requirements and the following two equations.

where

• zeta=Damping ratio
• Tr=Rise time
• Mp=Maximum overshoot

Since our rise time and overshoot requirements are 5 seconds and 10%, respectively, we can determine that the natural frequency (Wn) must be greater than 0.36 rad/sec and the damping ratio (zeta) must be greater than 0.6.

Let's generate the root-locus and use the zgrid to find the acceptable region of the root-locus. But before doing that, if you refer to the Digital Control Tutorial, the natural frequency argument for zgrid needs to be in the unit of rad/sample, so let Wn = 0.36*Ts = 0.0072 rad/sample. Now add the following commands to the above m-file and rerun it. You should get the following plot.

```Wn = 0.0072;
zeta = 0.6;

rlocus(cruise_d)
zgrid(zeta, Wn)
axis ([-1 1 -1 1])
```

The region of the complex plane which interests us is that which is near the point (1,0), so you should zoom in on this point. Rerun using the axis command below you should now see

```axis ([0.95 1 -.1 .1])
```

The dotted line on the right, indicates the locations of constant natural frequency (Wn), and the natural frequency is greater than 0.0072 outside the line. The other dotted line indicates the locations of constant damping ratio (zeta), and the damping ratio is greater than 0.6 inside the line. The jagged vertical line is a portion of the unit circle which is calculated at low resolution (hence the jaggedness).

In the above plot, you see that part of the root-locus is inside the desired region. Let's find a gain (K) using the MATLAB function rlocfind and obtain the corresponding step response. Add the following commands to the above m-file and rerun it in the MATLAB command window.

```[K,poles] = rlocfind(cruise_d)

```

In the command window, you should see the prompt asking you to select a point on the root-locus. Remember that if you choose a pole which is too far inside the unit circle, then the step response will be too fast indicating a physically unreasonable acceleration. Therefore you should choose the pole which is near the intersection of the constant natural frequency and the real axis. The gain (K) and the pole location should be returned to the command window. Selecting the point at 0.99 gives the following root locus graph.

```sys_cl = feedback(K*cruise_d,1);
U = 10;
figure
step(U*sys_cl,10);
```

This response satisfies the rise time and overshoot requirements. But the steady state error is about 11%. To obtain the desired steady state error, we will modify the discrete controller.

## Compensation using a digital controller

Recall from the continuous Cruise Control: Root-Locus page, the lag controller was added to the system to obtain the desired response. In this digital control version of the cruise control problem, we will modify the existing digital controller by adding a function of the form

There is a guideline to design digital lead and lag compensators and a guideline for design continuous time lead and lag compensators. The discrete design method described says that the zero of the lag compensator should be chosen to (approximately) cancel one of the plant poles, as long as it is stable. Thus, we choose the zero to be at Zo = 0.999.

To reduce the steady state error, we note that the low frequency gain of the discrete time control system with a lag compensator is increased by a factor of of (1 - Zo)/(1 - Po). To reduce the steady state error by a factor of 5, we choose Po = 0.9998. To have a a gain of 1 at zero frequency, the numerator is multiplied by Kd = (1 - Zp)/(1 - Zo) = 0.2 before using the root locus. Note that the whole compensator is multiplied by the gain determined from the root locus.

Now we have the discrete compensator transfer function. Let's generate the root-locus and obtain the step response. Create a new m-file and enter the following commands.

```num = [1];
den = [1000 50];
cruise = tf(num,den)

Ts = 1/50;
cruise_d = c2d (cruise,Ts,'zoh');
contr = tf(0.2*[1 -0.999],[1 -0.9998],Ts);

Wn = 0.0072;
zeta = 0.6;

rlocus(contr*cruise_d)
zgrid(zeta, Wn)
axis([0.98 1 -0.01 0.01])

[K,poles] = rlocfind(contr*cruise_d)

sys_cl = feedback(K*contr*cruise_d,1);
U = 10;
figure
step(U*sys_cl,10);

```

Running this m-file in the command window give you the following root-locus.

In the command window, you should be asked to pick a point on the root-locus. Click on the locus near +0.99. You should now have the step response similar to the one shown below.

This response rises about as fast as before, but the steady state error has been reduced to 2%. This system satisfies all design requirements with the reasonable control effort.

Note: A design problem does not necessarily have a unique answer. For practice, you may try other compensators to obtain a better response than the one shown above.

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

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

Tutorials

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