6 Control Tutorials for MATLAB and Simulink - Cruise Control_ Simulink Simscape
6 Control Tutorials for MATLAB and Simulink - Cruise Control_ Simulink Simscape
INTRODUCTION CRUISE CONTROL MOTOR SPEED MOTOR POSITION SUSPENSION INVERTED PENDULUM
SYSTEM
Modeling w/ Simulink
CONTROL Circuit Sim Activity
PID
Related External Links
ROOT LOCUS Simscape Multibody
FREQUENCY
Intro
Simscape Multibody
STATE-SPACE
Video
DIGITAL Simscape Vehicle
Modeling
SIMULINK
MODELING
CONTROL Contents
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 1/13
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Simscape
Controller design
Open-loop response
Controlled-system response
Physical setup
In this section we alternatively show how to build the cruise control model using physical modeling blocks of Simscape Multibody. The
blocks in the Simscape library represent actual physical components; therefore, complex multi-body dynamic models can be built without
the need to build mathematical equations from physical principles as was done by applying Newton's laws in Cruise Control: Simulink
Modeling.
The following figure shows the vehicle schematic along with the forces that are acting on it.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 2/13
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Simscape
Open a new Simscape Multibody model by typing smnew in the MATLAB command window. A new model, shown below, will open with a
few commonly used blocks already in the model. The PS-Simulink and Simulink-PS blocks define the boundary between Simulink
input/output models where the blocks are evaluated sequentially and Simscape models where the equations are evaluated
simultaneously.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 3/13
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Simscape
Double-click on the Mechanism Configuration block and set Gravity to "[0, 0, -9.81]". This represents an acceleration due to gravity of
acting along the global -Z direction. This is good practice, but in this simulation is not essential.
Open the Solver Configuration block and ensure that the Use local solver checkbox is not selected
Ensure that the Solver uses the default "auto" setting, the Type is set to "Variable-step", and the Stop time to "120"
We will model the vehicle as a point mass moving along an axis. We use the World Frame to define the axis along which the vehicle will
travel.
Connect the B port of the Rigid Transform block to the W port of the World Frame
In group Rotation, set Method to "Standard Axis", Axis to "+Y" and Angle to "90 deg"
1. Use Quick Insert to add the blocks. Click in the diagram and type the name of the block (use the letters in bold below). A list of blocks
will appear and you can select the block you want from the list.
2. After the block is entered, a prompt will appear for you to enter a parameter.
3. To rotate a block or flip blocks, right-click on the block and select the desired option from the Rotate & Flip menu.
4. To show the parameter below the block name, see Set Block Annotation Properties in the Simulink documentation.
* Prismatic Joint
* Step
The Prismatic Joint allows only one translational degree of freedom. The Prismatic Joint will be actuated by a force input.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 4/13
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Simscape
The Prismatic Joint then needs to be connected to the rest of the model.
Connect the B port of Prismatic Vehicle to the F port of block Transform Vehicle Axis
Connect the F port of Prismatic Vehicle to the R port of the Solid block
Rename the Step block to "Force" and connect the output to the Simulink-PS Converter block that is already in the diagram
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 5/13
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Simscape
Connect the output of the Simulink-PS Converter block to the force input of Prismatic Vehicle
Double-click on the Simulink-PS Converter block and set Input signal unit to "N" for Newtons
Double-click on one PS-Simulink block and set Output signal unit to "m", and connect that block to the p port of the Prismatic
Vehicle block
Double-click on the other PS-Simulink block, set the Output signal unit to "m/s" and connect it to the v port of the Prismatic Vehicle
block
Since we are modeling the vehicle as a point mass, only the vehicle mass will affect the simulation results.
Set parameter Dimensions to "[0.2,0.2,0.4]" so that the longest dimension points along the direction of travel
In group Inertia, set Type to "Point Mass" and Mass to "1000 kg"
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 6/13
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Simscape
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 7/13
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Simscape
Then run the simulation (type CTRL-T or press the green arrow run button). The plot shows both the distance traveled by the vehicle and
its speed.
We will put everything except the Force input and the Scope into a subsystem.
Click once in the diagram (but not on a block) and press CTRL-A to select all blocks
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 8/13
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Simscape
Hold the Shift key and click on the Force block and Scope to unselect those blocks
Rename the input port "Force" and the output ports "Position" and "Speed"
Controller design
Design a control loop for this model to simulate the cruise control system. The control task is to ensure the vehicle travels at a constant
speed.
Subtract
PID Controller
Manual Switch
Scope
The switch lets you configure the model for closed-loop and open-loop operation. The goal of the controller is to hold the speed steady at
10 m/s.
Set the Step time to "0", Initial value to "0" and Final value to "10"
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 9/13
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Simscape
Open the PID Controller and choose the option to make it a PI controller
Set the Proportional (P) gain to "800" and the Integral (I) gain to "40"
Connect the Desired Speed output to the + port of the Subtract block
Connect the Speed output of Vehicle Subsystem to the - port of the Subtract block
Connect the output of the PI block to one of the inputs of the manual switch
Connect the Force (step input) to the other input of the switch
Connect the new Scope to the Position output and rename the Scope "Vehicle Position"
Connect the Speed output and Desired Speed output to the original scope and rename it "Vehicle Speed"
Open-loop response
Double-click on the switch until the Force block is the selected input.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 10/13
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Simscape
Run a simulation (type CTRL-T or press the green arrow run button). The vehicle speed rises from zero and eventually reaches a steady
speed of 10 m/s.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 11/13
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Simscape
Controlled-system response
With the switch connected to the PI output, run the simulation (type CTRL-T or press the green arrow run button). The plot shows the
controlled response of the system. The steady-state speed of 10 m/s is reached in a few seconds.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 12/13
3/25/2020 Control Tutorials for MATLAB and Simulink - Cruise Control: Simulink Simscape
You can download the final Simscape model created here by right-clicking here and then selecting Save link as ....
All contents licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl§ion=SimulinkSimscape 13/13