Example: Solution to the Cruise Control Problem Using PID control

The transfer function for this cruise control problem is the following,

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

and the block diagram of an typical unity feedback system is shown below.

The design criteria for this problem are:

Rise time < 5 sec
Overshoot < 10%

To see the original problem setup, see Cruise Control Modeling page.

Recall from the PID tutorial page, the transfer function of a PID controller is

Let's first take a look at the proportional control.

## Proportional control

The first thing to do in this problem is to find a closed-loop transfer function with a proportional control (Kp) added. By reducing the block diagram, the closed-loop transfer function with a proportional controller becomes:

Recall from the PID tutorial page, a proportional controller (Kp) decreases the rise time. This is what we need, if you refer to the Cruise Control Modeling page.

For now, let Kp equals 100 and see what happens to the response. Create an new m-file and enter the following commands.
```
kp=100;
m=1000;
b=50;
u=10;
num=[kp];
den=[m b+kp];
t=0:0.1:20;
step(u*num,den,t)
axis([0 20 0 10])
```
Running this m-file in the Matlab command window should give you the following step response.

Note: You can use the Matlab command cloop to find the closed-loop response directly from the open-loop transfer function. If you choose to do so, change the m-file to the following and run it in the command window. You should get the same plot as the one shown above.
```
kp=100;
m=1000;
b=50;
u=10;
num=[1];
den=[m b];
[numc,denc]=cloop(kp*num,den,-1);
t = 0:0.1:20;
step (u*numc,denc,t)
axis([0 20 0 10])
```

As you can see from the plot, both the steady-state error and the rise time do not satisfy our design criteria. You can increase the proportional gain (Kp) to improve the system output. Change the existing m-file so that Kp equal 10000 and rerun it in the Matlab command window. You should see the following plot.

The steady-state error has dropped to near zero and the rise time has decreased to less than 0.5 second. However, this response is unrealistic because a real cruise control system generally can not change the speed of the vehicle from 0 to 10 m/s in less than 0.5 second.

The solution to this problem is to choose a proportional gain (Kp) that will give a reasonable rise time, and add an integral controller to eliminate the steady-state error.

## PI control

The closed-loop transfer function of this cruise control system with a PI controller is:

Recall from the PID tutrial page, an addition of an integral controller to the system eliminates the steady-state error. For now, let Kp equals 600 and Ki equals 1 and see what happens to the response. Change your m-file to the following.

```
kp = 600;
ki = 1;
m=1000;
b=50;
u=10;
num=[kp ki];
den=[m b+kp ki];
t=0:0.1:20;
step(u*num,den,t)
axis([0 20 0 10])
```

Note: If you choose to obtain the closed-loop response directly from the open-loop transfer function, enter the following commands instead of the ones shown above:
```
kp=600;
ki=1;
m=1000;
b=50;
u=10;
num=[1];
den=[m b];
num1=[kp ki];
den1=[1 0];
num2=conv(num,num1);
den2=conv(den,den1);
[numc,denc]=cloop(num2,den2,-1);
t=0:0.1:20;
step(u*numc,denc,t)
axis([0 20 0 10])

```

Whichever the m-file you run, you should get the following output:

Now adjust both the proportional gain (Kp) and the integral gain (Ki) to obtain the desired response. When you adjust the integral gain (Ki), we suggest you to start with a small value since large (Ki) most likely unstabilize the response.

With Kp equals 800 and Ki equals 40, the step response will look like the following:

As you can see, this step response meets all design criteria.

## PID control

For this particular example, no implementation of a derivative controller was needed to obtain a required output. However, you might want to see how to work with a PID control for the future reference. The closed-loop transfer function for this cruise control system with a PID controller is.

Let Kp equals 1, Ki equals 1, and Kd equals 1 and enter the following commands into an new m-file.

```
kp=1;
ki=1;
kd=1;
m=1000;
b=50;
u=10;
num=[kd kp ki];
den=[m+kd b+kp ki];
t=0:0.1:20;
step(u*num,den,t)
axis([0 20 0 10])
```

Running this m-file should give you the step response of the system with PID controller. Adjust all of Kp, Kd, and Ki until you obtain satisfactory results. We will leave this as an exercise for you to work on.

Suggestion: Usually choosing appropriate gains require trial and error processes. The best way to attack this tedious process is to adjust one variable (Kp, Kd, or Ki) at a time and observe how changing one variable influences the system output. The characteristics of Kp, Kd, and Ki are summarized in the PID Tutorial page.

## User feedback

PID 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: RL

Tutorials

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

8/26/97 DK