Control Tutorials for MATLAB and Simulink Cruise Control System Modeling.pdf
Control Tutorials for MATLAB and Simulink Cruise Control System Modeling.pdf
Contents
Physical setup
System equations
System parameters
State-space model
Physical setup
Automatic cruise control is an excellent example of a feedback control system found in many modern vehicles. The purpose
of the cruise control system is to maintain a constant vehicle speed despite external disturbances, such as changes in wind
or road grade. This is accomplished by measuring the vehicle speed, comparing it to the desired or reference speed, and
We consider here a simple model of the vehicle dynamics, shown in the free-body diagram (FBD) above. The vehicle, of
mass m, is acted on by a control force, u. The force u represents the force generated at the road/tire interface. For this
simplified model we will assume that we can control this force directly and will neglect the dynamics of the powertrain, tires,
etc., that go into generating the force. The resistive forces, bv, due to rolling resistance and wind drag, are assumed to vary
linearly with the vehicle velocity, v, and act in the direction opposite the vehicle's motion.
System equations
With these assumptions we are left with a first-order mass-damper system. Summing forces in the x-direction and applying
(1)
Since we are interested in controlling the speed of the vehicle, the output equation is chosen as follows
(2)
System parameters
For this example, let's assume that the parameters of the system are:
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SystemModeling 1/2
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: System Modeling
State-space model
First-order systems have only has a single energy storage mode, in this case the kinetic energy of the car, and therefore only
one state variable is needed, the velocity. The state-space representation is therefore:
(3)
(4)
We enter this state-space model into MATLAB using the following commands:
m = 1000;
b = 50;
A = -b/m;
B = 1/m;
C = 1;
D = 0;
cruise_ss = ss(A,B,C,D);
(5)
We enter the transfer function model into MATLAB using the following commands:
s = tf('s');
P_cruise = 1/(m*s+b);
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SystemModeling 2/2
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: System Analysis
Contents
System model and parameters
Performance specifications
Open-loop poles/zeros
(1)
Performance specifications
The next step is to come up with some design criteria that the compensated system should achieve. When the engine gives
a 500 Newton force, the car will reach a maximum velocity of 10 m/s (22 mph), see open-loop step response section below.
An automobile should be able to accelerate up to that speed in less than 5 seconds. In this application, a 10% overshoot
and 2% steady-state error on the velocity are sufficient.
Keeping the above in mind, we have proposed the following design criteria for this problem:
m = 1000;
b = 50;
u = 500;
s = tf('s');
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SystemAnalysis 1/4
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: System Analysis
P_cruise = 1/(m*s+b);
step(u*P_cruise)
We see that the open-loop system exhibits no overshoot or oscillations (characteristic of first-order systems), and does
reach the desired steady-state speed of 10 m/s; however, the rise time is much too slow, ~60 s. Therefore we need to
design a feedback controller which speeds up the response significantly without negatively affecting the other dynamic
performance metrics.
Open-loop poles/zeros
The cruise control system has a single pole at s = -b/m which we can see plotted on the s-plane using the following MATLAB
commands:
pzmap(P_cruise)
axis([-1 1 -1 1])
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SystemAnalysis 2/4
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: System Analysis
We observe that the open-loop system is stable and does not oscillate since the pole is real and negative. Furthermore, the
speed of response is determined by the magnitude of this pole,b/m: the larger the magnitude, the quicker the system
approaches the steady-state value. Since we're typically not able to change the system parameters to change the dynamic
response of the system, we must instead design controllers which alter the poles and zeros of the closed-loop system to
meet the desired performance specifications.
bode(P_cruise)
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SystemAnalysis 3/4
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: System Analysis
We see that the Bode plots exhibit the definitive features of first-order systems, including a -3 dB magnitude and -45 deg
phase at the corner frequency of w = b/m = 0.05 rad/s and -20 dB/dec roll-off at high frequencies.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SystemAnalysis 4/4
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: PID Controller Design
Contents
System model and parameters
Performance specifications
PID overview
Proportional control
PI control
PID control
(1)
Performance specifications
Rise time < 5 s
PID overview
The block diagram of a typical unity feedback system is shown below.
Recall from the Introduction: PID Controller Design page, the transfer function of a PID controller is
(2)
We can define a PID controller in MATLAB using the transfer function directly:
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlPID 1/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: PID Controller Design
Kp = 1;
Ki = 1;
Kd = 1;
s = tf('s');
C = Kp + Ki/s + Kd*s
C=
s^2 + s + 1
-----------
s
Alternatively, we may use MATLAB's pid controller object to generate an equivalent continuous time controller as follows:
C = pid(Kp,Ki,Kd)
C=
Kp + Ki * --- + Kd * s
with Kp = 1, Ki = 1, Kd = 1
Proportional control
The first thing to do in this problem is to find a closed-loop transfer function with a proportional control (C = Kp) added.
By reducing the unity feedback block diagram, the closed-loop transfer function with a proportional controller becomes:
(3)
Recall from the Introduction: PID Controller Design page, a proportional controller, Kp, decreases the rise time, which is
desirable in this case.
For now, use Kp equal 100 and a reference speed of 10 m/s. Create a new m-file and enter the following commands.
m = 1000;
b = 50;
r = 10;
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlPID 2/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: PID Controller Design
s = tf('s');
Kp = 100;
C = pid(Kp);
T = feedback(C*P_cruise,1)
t = 0:0.1:20;
step(r*T,t)
axis([0 20 0 10])
T=
100
------------
1000 s + 150
Note that we have used the MATLAB feedbackcommand to simplify the block diagram reduction of the closed-loop system.
Please verify for yourself that the result agrees with the closed-loop transfer function, T, derived above.
Running the m-file in MATLAB should give you the step response above. As you can see from the plot, neither the steady-
state error nor the rise time satisfy our design criteria.
You can increase the proportional gain, Kp, to reduce the rise time and the steady-state error. Change the existing m-file so
that Kp equals 5000 and rerun it in the MATLAB command window. You should see the following plot.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlPID 3/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: PID Controller Design
Kp = 5000;
C = pid(Kp);
T = feedback(C*P_cruise,1);
step(r*T,t)
axis([0 20 0 10])
The steady-state error is now essentially zero, and the rise time has been reduced substantially. 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 seconds due to power limitations of the engine and drivetrain.
Actuator limitations are very frequently encountered in practice in control systems engineering, and consequently, the
required control action must always be considered when proposing a new controller. We will discuss this issue much more
in subsequent tutorials.
The solution to this problem in this case is to choose a lower proportional gain, Kp, that will give a reasonable rise time, and
PI control
The closed-loop transfer function of this cruise control system with a PI controller (C = Kp + Ki/s) is:
(4)
Recall from the Introduction: PID Controller Design page, an addition of an integral controller to the system eliminates the
steady-state error. For now, let Kp equal 600 and Ki equal 1 and see what happens to the response. Change your m-file to
the following.
Kp = 600;
Ki = 1;
C = pid(Kp,Ki);
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlPID 4/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: PID Controller Design
T = feedback(C*P_cruise,1);
step(r*T,t)
axis([0 20 0 10])
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 a large Ki can destabilize the response. When Kp equals
800 and Ki equals 40, the step response will look like the following:
Kp = 800;
Ki = 40;
C = pid(Kp,Ki);
T = feedback(C*P_cruise,1);
step(r*T,t)
axis([0 20 0 10])
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlPID 5/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: PID Controller Design
PID control
For this particular example, no implementation of a derivative controller was needed to obtain the 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 (C = Kp + Ki/s + Kd*s) is:
(5)
Let Kp equal 1, Ki equal 1, and Kd equal 1 and enter the following commands into an new m-file.
Kp = 1;
Ki = 1;
Kd = 1;
C = pid(Kp,Ki,Kd);
T = feedback(C*P_cruise,1);
Plot the step response and 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 requires a trial and error process. The best way to attack this tedious
process is to adjust one variable (Kp, Ki, or Kd) at a time and observe how changing one variable influences the system
output. The characteristics of Kp, Ki, and Kd are summarized in theIntroduction: PID Controller Design page.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlPID 6/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Root Locus Controller Design
Contents
System model
System parameters
Performance specifications
Proportional control
Lag controller
System model
The transfer function model for the cruise control problem is given below. Please see the Cruise Control: System
(1)
System parameters
For this example, let's assume that the parameters of the system are
and the block diagram of a typical unity feedback system is shown below.
Performance specifications
Rise time < 5 sec
Proportional control
Recall from the Introduction: Root Locus Controller Design page, the root-locus plot shows the locations of all possible
closed-loop poles when a single gain is varied from zero to infinity. Thus, only a proportional controller, K_P, will be
considered to solve this problem. The closed-loop transfer function becomes:
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlRootLocus 1/8
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Root Locus Controller Design
(2)
Also, from the Introduction: Root Locus Controller Design page, we know that the MATLAB command sgridcan be used to
display an acceptable region of the root-locus plot. To use thesgrid, both the damping ratio, zeta, and the natural frequency,
Wn, need to be determined first. The following two equations will be used to find the damping ratio and the natural
frequency:
(3)
(4)
where
Mp = Maximum Overshoot
One of our design criteria is to have a rise time of less than 5 seconds. From the first equation, we see that the natural
frequency must be greater than 0.36. Also using the second equation, we see that the damping ratio must be greater than
Now, we are ready to generate a root-locus plot and use thesgridto find an acceptable region on the root-locus. Create a
m = 1000;
b = 50;
r = 10;
s = tf('s');
P_cruise = 1/(m*s+b);
rlocus(P_cruise)
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlRootLocus 2/8
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Root Locus Controller Design
The two dotted lines in an angle indicate the locations of constant damping ratio (zeta=0.6); the damping ratio is greater than
0.6 in between these lines and less than 0.6 outside the lines. The semi-ellipse indicates the locations of constant natural
frequency (Wn=0.36); the natural frequency is greater than 0.36 outside the semi-ellipse, and smaller than 0.36 inside.
We can then find a gain to place the closed-loop poles in the desired region by employing the rlocfindcommand. Add the
code [Kp,poles]=rlocfind(P_cruise)onto the end of your m-file to help you choose a specific loop gain. After running
in the command window, you should see a prompt asking you to pick a point on the root-locus plot. Since you want to pick a
point in between dotted lines (zeta>0.6) and outside the semi-ellipse (Wn>0.36), click on the real axis just outside the semi-
ellipse (around -0.4) as indicated by the cross mark in the following figure.
After doing this, you should see the following output in the MATLAB command window.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlRootLocus 3/8
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Root Locus Controller Design
selected_point =
-0.4002 + 0.0019i
Kp =
350.2419
poles =
-0.4002
Note that the value returned from your MATLAB command window may not be exactly the same, but should at least have the
same order of magnitude. This returned value can be used as the gain for the compensator and the closed-loop step
response can be generated as follows.
Kp = 350.2419;
sys_cl = feedback(Kp*P_cruise,1);
t = 0:0.1:20;
step(r*sys_cl,t)
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlRootLocus 4/8
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Root Locus Controller Design
With the gain Kp you just chose, the rise time and the overshoot criteria have been met; however, a steady-state error of
more than 10% remains.
Lag controller
To reduce the steady-state error, a lag controller will be added to the system. The transfer function of the lag controller is:
(5)
(6)
Finally, including the loop gain Kp, the closed-loop transfer function becomes:
(7)
If you read the "Lag or Phase-Lag Compensator using Root-Locus" section in the Lead and Lag Compensator Design page,
the pole and the zero of a lag controller need to be placed close together. Also, it states that the steady-state error will be
reduced by a factor of zo/po. For these reasons, let zo equal 0.3 and po equal 0.03.
zo = 0.3;
po = 0.03;
s = tf('s');
C_lag = (s+zo)/(s+po);
rlocus(C_lag*P_cruise);
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlRootLocus 5/8
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Root Locus Controller Design
sgrid(0.6,0.36);
Using the rlocfind command again, we can choose a new loop gain Kp. Enter the
code[Kp,poles]=rlocfind(C_lag*P_cruise)into the command window and click on the real axis around -0.4 as
shown in the following figure.
After doing this, you should see the following output in the MATLAB command window.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlRootLocus 6/8
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Root Locus Controller Design
selected_point =
-0.4002 - 0.0012i
Kp =
1.2936e+03
poles =
-0.9733
-0.4003
Kp = 1293.6;
sys_cl = feedback(Kp*C_lag*P_cruise,1);
t = 0:0.1:20;
step(r*sys_cl,t)
axis([0 20 0 12])
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlRootLocus 7/8
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Root Locus Controller Design
As you can see, the steady-state error has been reduced to near zero. The overshoot is a result of the zero added in the lag
controller. For now all of the design criteria have been met and no further iterations are needed; however, you should
experiment with different zo and po values to see what their effect is on the closed-loop system response.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlRootLocus 8/8
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Frequency Domain Methods for Controller Design
Contents
System model
System parameters
Performance specifications
Proportional controller
Lag compensator
System model
The transfer function model for the cruise control problem is given below. Please see the Cruise Control: System
Modelingpage for the derivation.
(1)
System parameters
For this example, let's assume that the parameters of the system are
and the block diagram of an typical unity feedback system is shown below.
Performance specifications
Rise time < 5 sec
The first step in solving this problem using frequency response is to determine what open-loop transfer function to use. Just
like for the Root-Locus design method, we will only use a proportional controller to solve the problem. The block diagram
and the open-loop transfer function are shown below.
(2)
In order to use a Bode plot, the open-loop response must be stable. Let Kp equal 1 for now and see how the open-loop
response looks like. Create a new m-file and enter the following commands.
m = 1000;
b = 50;
u = 500;
Kp = 1;
s = tf('s');
P_cruise = 1/(m*s+b);
C = Kp;
step(u*C*P_cruise)
As you can see, the open-loop system is stable; thus, we can go ahead and generate the Bode plot. Change the above m-
bode(C*P_cruise);
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlFrequency 2/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Frequency Domain Methods for Controller Design
Proportional controller
Refer to the Introduction: Frequency Domain Methods for Controller Design page, and let's see what system characteristics
(3)
For this system, the low frequency gain is -34dB = 0.02; therefore, the steady-state error should be 98%. We can confirm this
by generating a closed-loop step response as follows.
r = 10;
sys_cl = feedback(C*P_cruise,1);
step(r*sys_cl);
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlFrequency 3/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Frequency Domain Methods for Controller Design
We need to increase the low frequency gain in order to improve the steady-state error. Specifically, the error needs to be <
2%; therefore, 1/(1+M_{w=0}) < 0.02 -> M_{w=0} > 49 = 33.8 dB. So to reach the desired steady-state error using proportional
control only requires a Kp > 67.8 dB = 2455. Let's look at the Bode diagram of the compensated open-loop system.
Kp = 2500;
C = Kp;
bode(C*P_cruise);
As you can see from the Bode plot above, the low frequency magnitude is now, 34 dB. Now let's simulate the step response
of the closed loop system with this gain.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlFrequency 4/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Frequency Domain Methods for Controller Design
sys_cl = feedback(C*P_cruise,1);
step(r*sys_cl);
The steady-state error meets the requirements; however, the rise time is much shorter than is needed and is unreasonable
in this case since the car can not accelerate to 10 m/s in 2 sec. Therefore, we will try using a smaller proportional gain to
reduce the control action required along with a lag compensator to reduce the steady-state error.
Lag compensator
If you take a look at the "Lag or Phase-Lag Compensator using Frequency Response" section of the Lead and Lag
Compensator Design page, the lag compensator adds gain at the low frequencies while keeping the bandwidth frequency
at the same place. This is actually what we need: Larger low frequency gain to reduce the steady-state error and keep the
same bandwidth frequency to maintain the desired rise time. The transfer function of the lag controller is:
(4)
If you read the "Lag or Phase-Lag Compensator using Root-Locus" section in Lead and Lag Compensator Design page, the
pole and the zero of a lag controller need to be placed close together. Also, it states that the steady-state error will be reduce
by a factor of zo/po. For these reasons, let zo equal 0.1 and po equal 0.02. The proportional gain, Kp = 1000 was chosen by
trial-and-error.
Kp = 1000;
zo = 0.1;
po = 0.02;
C_lag = (s+zo)/(s+po);
bode(Kp*C_lag*P_cruise);
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlFrequency 5/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Frequency Domain Methods for Controller Design
sys_cl = feedback(Kp*C_lag*P_cruise,1);
t = 0:0.1:20;
step(r*sys_cl,t);
As you can see, there is a very slight overshoot, the steady state error is close to zero, and the rise time is under 5 seconds.
The system has now met all of the design requirements. No more iteration is needed.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlFrequency 6/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: State-Space Methods for Controller Design
Contents
State-space equations
Design requirements
Reference input
State-space equations
The equations of motion in state-space form are as follows:
(1)
(2)
where
Design requirements
Rise time < 5 s
To see the original problem setup, see the Cruise Control: System Modeling page.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlStateSpace 1/4
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: State-Space Methods for Controller Design
(3)
where
Recall from the State-Space Tutorial page, we can use a "pole placement" technique to obtain the desired output. Poles of a
closed-loop system can be found from the characteristic equation: the determinant of the [sI-(A-B*K)] matrix. If the poles the
system can be placed in the desired location by designing an appropriate control matrix (K), then the desired output can be
obtained. In this tutorial, poles will be chosen first, then we will use MATLAB to find the corresponding control matrix (K).
Now, we need to determine where to place poles for our system. Since our [sI-(A-B*K)] matrix is 1x1, we have only one pole
to place. Let the pole be at -1.5 (arbitrary). Just as in the State-Space Tutorial, the MATLAB command placewill be used to
find the control matrix K. Create a new m-file and enter the following commands. Running the m-file in the MATLAB
command window should give you the control matrix and step response shown below.
m = 1000;
b = 50;
t = 0:0.1:10;
u = 500*ones(size(t));
A = [-b/m];
B = [1/m];
C = [1];
D = [0];
sys = ss(A,B,C,D);
x0 = [0];
p1 = -1.5;
K = place(A,B,[p1])
sys_cl = ss(A-B*K,B,C,D);
lsim(sys_cl,u,t,x0);
axis([0 10 0 0.35])
K=
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlStateSpace 2/4
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: State-Space Methods for Controller Design
1450
As you can see, the rise time is satisfactory, but the steady-state error is too large.
Reference input
Once again from the State-Space Tutorial page, a scaling factor called Nbar (the schematic is shown below) can be used to
eliminate the steady-state error. We can use the rscale function to compute the scaling factor. Download it here, rscale.m.
The input is already multiplied by 500, and we want the steady-state speed to be 10 m/sec, so we need to account for these
factors as well.
Copy the following commands to an m-file and run it in the MATLAB command window. You should get the step response
shown below.
Nbar = rscale(sys,K)*10/500;
sys_cl = ss(A-B*K,B*Nbar,C,D);
lsim(sys_cl,u,t,x0);
axis([0 10 0 11])
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlStateSpace 3/4
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: State-Space Methods for Controller Design
As you can see, the steady-state error has been eliminated. The rise time is less than 5 seconds and the overshoot is, in
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=ControlStateSpace 4/4
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Modeling
Contents
Physical setup and system equations
Open-loop response
Using Newton's 2nd law, the governing equation for this system becomes:
(1)
where u is the force generated between the road/tire interface and can be controlled directly. For this example, let's assume
that
m = 1000 kg
b = 50 N.sec/m
u = 500 N
Open Simulink and open a new model window. First, we will model the integral of acceleration.
(2)
Insert an Integrator Block (from the Continuous library) and draw lines to and from its input and output terminals.
Label the input line "vdot" and the output line "v" as shown below. To add such a label, double click in the empty space
just above the line.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkModeling 1/5
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Modeling
Since the acceleration (dv/dt) is equal to the sum of the forces divided by mass, we will divide the incoming signal by the
mass.
Insert a Gain block (from the Math Operations library) connected to the Integrator block input line and draw a line leading
to the input of the Gain block.
Edit the Gain block by double-clicking on it and change its value to "1/m".
Change the label of the Gain block to "inertia" by clicking on the word "Gain" underneath the block.
Now, we will add in the forces which are represented in Equation (1). First, we will add in the damping force.
Attach a Sum block (from the Math Operations library) to the line leading to the inertia Gain block.
Insert a Gain block below the Inertia block, select it by single-clicking on it, and select Flip from the Format menu (or type
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkModeling 2/5
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Modeling
Set the block's value to "b" and rename this block to "damping".
Tap a line (hold Ctrl while drawing) off the Integrator block's output and connect it to the input of the damping Gain block.
Draw a line from the damping Gain block output to the negative input of the Sum Block.
The second force acting on the mass is the control input, u. We will apply a step input.
Insert a Step block (from the Sources library) and connect it with a line to the positive input of the Sum Block.
To view the output velocity, insert a Scope block (from the Sinks library) connected to the output of the Integrator.
To provide an appropriate step input of 500 at time equal zero, double-click the Step block and set the Step Time to "0"
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkModeling 3/5
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Modeling
You can download a model file for the complete system here,ccmodel.mdl.
Open-loop response
To simulate this system, first, an appropriate simulation time must be set.
Select Parameters from the Simulation menu and enter "120" in the Stop Time field. 120 seconds is long enough to
The physical parameters must now be set. Run the following commands at the MATLAB prompt:
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkModeling 4/5
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Modeling
m = 1000;
b = 50;
u = 500;
Run the simulation (hit Ctrl-T or select Start from the Simulation menu). When the simulation is finished, double-click on the
Scope and hit its autoscale button. You should see the following output.
Observing the above, we would like to improve the response of the cruise control system. The model created here will be
employed for controller design and analysis within Simulink in the Cruise Control: Simulink Controller Design page.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkModeling 5/5
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
Contents
Extracting a linear model into MATLAB
Implementing PI control
Closed-loop response
In the Cruise Control: Simulink Modeling page we created a Simulink model of the cruise control system. You can recreate
the model or download it here. In this section, we will show how to implement a feedback controller in Simulink to meet the
Replace the Step Block and Scope Block with an In1 and an Out1 block, respectively (these blocks can be found in the
Ports & Subsystems library). This defines the input and output of the system for the extraction process.
Save your file as "ccmodel.mdl" (select Save As from the File menu). MATLAB will extract the linear model from the saved
model file, not from the open model window. At the MATLAB prompt, enter the following commands:
m = 1000;
b = 50;
u = 500;
[A,B,C,D] = linmod('ccmodel')
cruise_ss = ss(A,B,C,D);
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 1/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
A=
-0.0500
B=
1.0000e-03
C=
1
D=
To verify the model extraction, we will generate an open-loop step response of the extracted transfer function in MATLAB. We
will multiply the numerator by 500 to simulate a step input of 500 N. Enter the following command in MATLAB.
step(u*cruise_ss)
Implementing PI control
In the Cruise Control: PID Control page a PI controller was designed with Kp = 800 and Ki = 40 to give the desired response.
We will implement this in Simulink by first containing the open-loop system from earlier in this page in a Subsystem block.
Drag a Subsystem block from the Ports & Subsystems library into your new model window.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 2/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
Double-click on this block. You will see a blank window representing the contents of the subsystem (which is currently
empty).
Open your previously saved model of the cruise control system, ccmodel.mdl.
Select Select All from the Edit menu (or Ctrl-A), and select Copy from the Edit menu (or Ctrl-C).
Select the blank subsystem window from your new model and select Paste from the Edit menu (or Ctrl-V). You should
see your original system in this new subsystem window. Close this window.
You should now see input and output terminals on the Subsystem block. Name this block "plant model".
Now, we will build a PI controller around the plant model. First, we will feed back the plant output.
Tap a line of the output line and draw it to the negative input of the Sum block.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 3/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
The output of the Sum block will provide the error signal. From this, we will generate proportional and integral components.
Insert an Integrator block after the Sum block and connect them with a line.
Insert and connect a Gain block after the Integrator block to provide the integral gain.
Insert a new Gain block and connect it with a line tapped off the output of the Sum block.
Now we will add the proportional and integral components and apply the sum to the plant.
Insert a Sum block between the Ki block and the plant model and connect the outputs of the two Gain blocks to the Sum
block inputs.
Connect the Sum block output to the input of the plant block.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 4/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
Finally, we will apply a step input and view the output with a Scope block.
Attach a Step block to the free input of the feedback Sum block.
Double-click the Step block and set the Step Time to "0" and the Final Value to "u". This allows the input magnitude to be
changed outside of Simulink.
In this example, we constructed a PI controller from fundamental blocks. As an alternative, we could have used a Transfer
Function block (from the Continuous library) to implement this in one step, as shown below.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 5/6
12/21/2015 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
Closed-loop response
To simulate this system, first, an appropriate simulation time must be set. Select Parameters from the Simulation menu and
enter "10" in the Stop Time field. The design requirements included a rise time of less than 5 sec, so we simulate for 10
seconds to view the output. The physical parameters must now be set. Run the following commands at the MATLAB prompt:
m = 1000;
b = 50;
u = 10;
Kp = 800;
Ki = 40;
Run the simulation (hit Ctrl-T or select Start from the Simulation menu). When the simulation is finished, double-click on the
scope and hit its autoscale button. You should see the following output.
http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 6/6