5 Control Tutorials for MATLAB and Simulink - Cruise Control_ Simulink Control
5 Control Tutorials for MATLAB and Simulink - Cruise Control_ Simulink Control
INTRODUCTION CRUISE CONTROL MOTOR SPEED MOTOR POSITION SUSPENSION INVERTED PENDULUM
SYSTEM
Simulink/MATLAB
CONTROL Interaction
Control Activity
PID
FREQUENCY
Simulink Control Video
SIMULINK
MODELING
Contents
CONTROL
Extracting a linear model into MATLAB
SIMSCAPE Implementing PI control
Closed-loop response
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 1/12
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
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 by right-clicking here and selecting Save link as. In this section, we will show how to implement a feedback controller in
A linear model of the system (in state space or transfer function form) can be extracted from a Simulink model into MATLAB. This is done
through the use of In1 and Out1 blocks and the MATLAB function linmod.
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.slx" (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:
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 2/12
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
m = 1000;
b = 50;
u = 500;
[A,B,C,D] = linmod('ccmodel')
cruise_ss = ss(A,B,C,D);
A =
-0.0500
B =
1.0000e-03
C =
1
D =
0
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)
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 3/12
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
Implementing PI control
In the Cruise Control: PID Control page a PI controller was designed with and 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.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 4/12
3/25/2020 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.slx.
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".
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 5/12
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
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.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 6/12
3/25/2020 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.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 7/12
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
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.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 8/12
3/25/2020 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.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 9/12
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
You can download our version of the closed-loop system model by right-clicking here and selecting Save link as.
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.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 10/12
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
You can download this model by right-clicking here and selecting Save link as.
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;
r = 10;
Kp = 800;
Ki = 40;
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 11/12
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Control
Run the simulation (hit Ctrl-T or select Run from the Simulation menu). When the simulation is finished, you should see the following
output.
All contents licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkControl 12/12