SYDE 351:
Software
Implementation
Systems Models
Dr. Charbel Azzi
1
What we are going to cover today…
• Introduce Simulink and use it to solve the Quarter-Car Suspension application
• Introduce Simscape and use it to solve the Quarter-Car Suspension application
• Introduce SimulationX and use it to solve the Quarter-Car Suspension
application
Yay Systems!
2
Fun Facts: Some History
500,000 different medical technologies are available (including
medical devices, in vitro diagnostics, imaging equipment and ehealth).
The first computer was almost 2.5 meters high and weighed nearly
30,000kg.
The name Google was created accidentally. A spelling error was
made by the original founders who were under the impression they
were going for Googol.
3
Motivation
❖ Let us take the quarter-car suspension model from Lecture 4 Example 3:
𝑘1 𝑥2 − 𝑥1 + 𝑐(𝑥2ሶ − 𝑥1ሶ ) = 𝑚1 𝑥1ሷ
ቊ
−𝑘1 𝑥2 − 𝑥1 − 𝑐 𝑥2ሶ − 𝑥1ሶ + 𝑘2 𝑦 − 𝑥2 = 𝑚2 𝑥2ሷ
❖ In previous lectures:
▪ We derived the equations of motion
▪ Learned how to draw Block Diagrams
▪ Learned how to represent the equations with general State-Variable
mathematical model
➢ Let us learn to implement real-life applications via software like Simulink,
Simscape and SimulationX
4
Simulink Basics
❑ Consider a general second order system (mass-spring-damper) with input force
𝑓(𝑡) and output displacement 𝑥(𝑡) with all initial conditions zero from lecture 5:
𝑚𝑥(𝑡)
ሷ + 𝑐𝑥(𝑡)
ሶ + 𝑘𝑥(𝑡) = 𝑓(𝑡)
1 1 𝐹(𝑠) 1 1
𝑥ሷ = 𝑓 𝑡 − 𝑐 𝑥ሶ 𝑡 − 𝑘𝑥 𝑡 ⇒ 𝑋 𝑠 = 2
− 𝑐𝑋 𝑠 − 2 𝑘𝑋(𝑠)
𝑚 𝑚 𝑠 𝑠 𝑠
❑ We built the block diagram:
➢ Let’s solve that Numerically in Simulink!
5
Simulink Basics: Starting Simulink
❑ Simulink can be launched by typing: Simulink on the MATLAB command line or
pressing the Simulink icon in the MATLAB toolbar
❑ To open the Simulink model window select File -> New -> Model from the
Simulink library window and press the red circle to enable the library view
6
Simulink Basics: Modeling
❑ Taking the MDS model with zero initial conditions:
1 1 𝐹(𝑠) 1 1
𝑥ሷ = 𝑓 𝑡 − 𝑐 𝑥ሶ 𝑡 − 𝑘𝑥 𝑡 ⇒ 𝑋 𝑠 = 2
− 𝑐𝑋 𝑠 − 2 𝑘𝑋(𝑠)
𝑚 𝑚 𝑠 𝑠 𝑠
❑ Simulink Model mimics the block diagram:
7
Simulink Basics: Modeling
❑ Taking the MDS model with zero initial conditions:
1 1 𝐹(𝑠) 1 1
𝑥ሷ = 𝑓 𝑡 − 𝑐𝑥ሶ 𝑡 − 𝑘𝑥 𝑡 ⇒ 𝑋 𝑠 = 2
− 𝑐𝑋 𝑠 − 2 𝑘𝑋(𝑠)
𝑚 𝑚 𝑠 𝑠 𝑠
1. The integrator block can be found under the section continuous in
Simulink: It performs the integral of the input variable for that timestep
2. Gain : Multiplies the input variable by a constant gain (specified by the user
in the gain parameters window)
3. To workspace : Sends all the datapoints of that variable to the MATLAB
workspace. The name of the variable in MATLAB can be chosen from the To
Workspace parameters window. Selecting the Save Format from the parameters
window as array will save the data as an array
4. Scope : For plotting data in Simulink
5. Mux (multiplexer) : Merges multiple signals into a single signal. The number of
signals can be increased or decreased
6. Circle : Allows the sum and/or subtraction operations 8
Simulink Basics: Modeling
❑ Taking the MDS model with zero initial conditions:
1 1 𝐹(𝑠) 1 1
𝑥ሷ = 𝑓 𝑡 − 𝑐𝑥ሶ 𝑡 − 𝑘𝑥 𝑡 ⇒ 𝑋 𝑠 = 2
− 𝑐𝑋 𝑠 − 2 𝑘𝑋(𝑠)
𝑚 𝑚 𝑠 𝑠 𝑠
✓ The Step : is the input force which can be modeled as step function here. You
can set the step start to 0 instead of 1
✓ The initial conditions are zeros and should be
set to zero by clicking on the both integrator
blocks and setting them to zero
✓ The variables (m, c, k) should be defined in the
command window of MATLAB or using a script as Base
Workspace, or defined within the block as a Model
Workspace otherwise an error will be generated
9
Simulink Basics: Simulation
❑ Taking the MDS model with zero initial conditions:
2
1 1 𝐹(𝑠) 1 1
𝑠 𝑋 𝑠 = 𝐹 𝑠 − 𝑐𝑠𝑋 𝑠 − 𝑘𝑋(𝑠) ⇒ 𝑋 𝑠 = 2
− 𝑐𝑋 𝑠 − 2 𝑘𝑋(𝑠)
𝑚 𝑚 𝑠 𝑠 𝑠
✓ You can the simulation time from the simulation window “Stop Time”
✓ In the MATLAB command window you can use the “simout” from the workspace
data we created to plot or view or export data to analyze
✓ You can use the configuration properties on the scope simulation to specify the
maximum step size, change simulation time, Limit Data Points to see the entire set
of data points, etc.
10
SimulationX
❑ A SimulationX model is based on the Physical Network approach using blocks
representing physical system elements
❑ Unlike Simulink, it is acausal (not based on signal following)
❑ Most often the network is similar to familiar schematic diagrams of the systems
❑ Doesn't need prior mathematical description of the system
❑ SimulationX:
▪ For 3D use SimulationX as it offer the MBS library with easy and great smooth
user interface
▪ SimulationX has much faster solver and much easier user interfaces
=> In this course we will use SimulationX. You are welcome to try Simscape
model that I will release for you with instructions.
11
SimulationX: Variable Types
❑ Physical Network approach supports Linear Graph Theory which are based on 2
types of variables:
1. Through (or flow) —Variables that are measured with a gauge connected in
series to an element. A through-variable represents a property that appears to
pass through an element, unaltered. (e.g., force, current, fluid flow rate, and
heat transfer rate)
2. Across (or potential) —Variables that are measured with a gauge connected in
parallel to an element, as the difference in the values at the two ends of the
element. i.e., the value at one end of the element with respect to the value at
the other end. (e.g., velocity, voltage, pressure, and temperature)
❑ Usually, the energy flow (power) in Watts is the product of these two variables
12
Simscape/SimulationX: Elements Types
❑ Lines:
▪ Lines carry physical variables (Across and Through variables) to enable the
exchange of energy flows/power
▪ Two or more (branching) directly connected ports must have the same values
for all their Across (Potential) variables (such as velocity or angular velocity)
▪ For each Through (Flow) variable, the sum of all its values flowing into a branch
point equals the sum of all its values flowing out
▪ Potential quantities from kinematic connectors (yellow) to elements
▪ Flow quantities from kinetic connectors (white) back to the kinematic
connectors (e.g., of joints)
▪ Potential quantities are computed by Joints
13
SimulationX: Reference Frames
❑ Global Coordinate System:
o The global coordinate system does not need to be explicitly modeled, as it is
built-in in all MechanicsMBS elements,
o e.g. a free (not connected) kinetic connector is fixed by definition
❑ Reference Frames: All other elements determine their initial position and
orientation from a reference frame, which can be:
o Predecessor Frame
o Origin RECOMMENDED TO
o Input USE THIS!
14
SimulationX: Degrees of Freedom (DOF)
❑ Elements are fixed in place, unless they are provided with DOF via Joints
1. Joints with one DOF:
2. Joints with multiple DOF:
3. General Joint
➢ Define any kind of joint (DoF) by preset of constraints (fix displacement
difference in coordinate direction on zero)
4. Rigid Link: is a joint without any DoF, e.g. to insert a transformation from point to
point
15
SimulationX: Necessary Parts
❑ Joints:
▪ Prismatic Joint: adds the possibility for all
connected elements to translate in one direction
▪ Revolute Joint: adds the possibility for all
connected elements to rotate around one axis
❑ Rigid Bodies
▪ The rigid body is one kinetic connector applying
the mass and inertia transformation from the
center of mass to the reference coordinate
system
▪ Neither states nor DoF
▪ Computes mass and mass moment of inertia
from geometry
▪ Visualizes geometry for 3D animation
▪ Center of mass can be optionally moved from
the body reference frame
16
SimulationX: Necessary Parts
❑ Surface Contacts:
▪ Fixed Triangulated Surface: ground model for
wheel contact
▪ Contact with Circle: wheel contact model
✓ Note: this only models the contact forces, not
the inertia of the wheel
▪ Circle-Line: general circular contact without fixed
end but has spring-damper in it
❑ Forces:
▪ Body Force: applies a force relative to the
coordinate system of the connected body
▪ Global Force: applies a force relative to a direction
of the global coordinate system
✓ Use this to always apply a force e.g. in global X
direction
17
SimulationX: Necessary Parts
❑ Signal Blocks:
• f(x) : Write custom functions, parameters, or refer
to variables in the model
• Curve: Enter a y(t) or y(x) curve
18
SimulationX
❖ Let us take the quarter-car suspension model from Lecture 4 Example 3 and model
it in SimulationX now:
𝑘1 𝑥2 − 𝑥1 + 𝑐(𝑥2ሶ − 𝑥1ሶ ) = 𝑚1 𝑥1ሷ
ቊ
−𝑘1 𝑥2 − 𝑥1 − 𝑐 𝑥2ሶ − 𝑥1ሶ + 𝑘2 𝑦 − 𝑥2 = 𝑚2 𝑥2ሷ
❖ You can model the bump as you wish – in this
model the roadbump to be an external
disturbance with this time curve (e.g. the road
jumps 10cm at 1 second)
19
SimulationX: MBS Library
❑ Let’s start with the model of the mass, spring, and damper. From the
Mechanics>MBS Mechanics (3D)>Rigid Bodies library, select and place 2 Cylinders
to represent the left and right wheels:
▪ The right wheel here is optional and is designed for completeness
▪ Select their dimensions in the “Parameters” tab – select realistic ones such as 8
inches outer radius and 20 cm height
▪ Make sure the axis of rotation is about its axial i.e. Y-axis in this model
❑ Add a road model as a cuboid (or any other shape you want) from the
Mechanics>MBS Mechanics (3D)>Rigid Bodies library
▪ Select their dimensions – select realistic ones such as 8 inches outer radius and
20 cm height
20
SimulationX: Wheels and Contact Blocks
❑ From the Mechanics>MBS Mechanics (3D)>Contacts Elements library, select
and place 2 Circle line contact one for each wheel and connect them all to the
road block:
▪ This makes sure the wheels are in contact with the ground and generates
the necessary normal and frictional forces
▪ Make sure the “Position” for these components are (0, 0, road.lz/2) to
establish the necessary contact with the top surface of the road
▪ Note that the Circle line contact has built “Parameters” for a spring and a
damper → we will use the spring stiffness here as k2
21
SimulationX: Wheels and Contact Blocks
❑ So far we should have built this model and its 3D view
❑ You can see the 2 wheels are aligned with each other and below the road → we
need to defined our references via joints to fix this
❑ Remember we aim at studying the motion along the roadbump in the upwards
direction i.e. Z-axis here so we have only translational motion along Z
22
SimulationX: 3D Joints
❑ From the Mechanics>MBS Mechanics (3D)>Joints library, select and place 2
Prismatic Joint one for each wheel and connect them all to the wheels:
▪ Prismatic Joint allows 1 DOF translation along the specified axis i.e. Z-axis here
which is what we want to study i.e. the translation x1 and x2
▪ Make sure the to position them properly to separate the wheels from each
other in the X direction (I picked 1 m apart here), and to have the center of
their reference frame at the center of each wheel i.e. in the Z direction R + hroad
▪ These can be set in the “Position” for each prismatic joint component
{-0.5,0,wheel1.ro+road.lz/2}
❑ So far we should have built this model and its 3D view:
23
SimulationX: 1D Mass-Spring-Damper
❑ Now we will use the 1D mechanics library Mechanics>Linear Mechanics library to
select and place the Mass and Spring-Damper elements:
▪ Connect it to one of the wheels via the prismatic joint
▪ Note that you cannot view this in the 3D view
❑ From the Block Parameters window for each of these elements and specify
m1 = 240 Kg, m2 = 36 Kg, k1 = 16,000 N/m, k2 = 160,000 N/m (this is in the circle
contact), c1= 2743 Ns/msn
❑ So far we should have built this model and its 3D view:
24
SimulationX: Modeling the Roadbump
❑ SimulationX allows smoother modeling of curves via the Signal Blocks>Signal
Sources library to select and place the Curve block:
▪ Connect it to the road via a Preset block
▪ Preset block is a constraint block that takes the input force and apply it to the
road block from the Mechanics>MBS Mechanics (3D)>Constraints
▪ For the preset block you need to set the force input displacement to be in the z
direction. That could be done either as self.in1 or roadBump.y (y(t) is the
displacement of the bump curve we created)
▪ It is easy to model the roadbump curve as seen below:
25
SimulationX: Adding Animation Blocks
❑ SimulationX allows you to animate a 1D model to view it in 3D via
the Mechanics>MBS Mechanics (3D)>Animation Bodies library to select and place
the Cuboid block to animate the mass in 3D:
▪ You will need to position the block on top of the wheels by changing the
"Displacement" option in the "Position" tab to {-
0.5,0,(wheel1.ro*2)+road.lz/2+mass1.x+0.1} - this will place the animation
block on top of the wheel assuming a 0.1m height for spring and dampers
▪ You need to make sure it moves with the mass thus adding the mass1.x
displacement to it
▪ You can choose to also animate the second wheel with no mass by having the
position {0.5,0,(wheel2.ro)+road.lz/2+prismaticJoint2.x[3]+0.1} - here since
there is not mass we add the displacement of the Prismatic Joint to visualize it
26
SimulationX: Final Model
❑ The final model and its 3D view can be seen here:
27
SimulationX: Final Model Simulation
❑ Simulate the model for 5s:
▪ You can change the properties via Simulation>Properties and make it go
infinitely – for more information check the video tutorials we have on Learn
▪ In the Simulation>Animation tab you can run a slow motion version of the
simulation and see what is happening step by step
▪ You can enter a logical termination condition for the “termCond” parameter to
terminate the simulation via Simulation>Properties. Check Tutorial 2 by Alex for
more tips and tricks
❑ Key take points:
➢ Wheel 1 and mass 1 have
smooth bounce as expected
which establishes comfort
➢ Wheel 2 without suspension
bounces non-stop and never
recovers
28
Simscape vs SimulationX Results
❑ If you run the Simscape model provided and comparing both results:
✓ The behavior/response is the same
✓ SimulationX provide more realistic response due to 3D dimensions:
➢ higher amplitudes for both displacements
➢ The wheel bounces back to its original height i.e. does not penetrate the
ground
29
End of Lecture
o Suggested Readings:
▪ William J. Palm III, System Dynamics, 4th international edition, 2021,
McGraw-Hill Higher Education
▪ Clarence W. de Silva, Modeling of Dynamic Systems, 2017, Taylor and
Francis
▪ Shuvra Das, Modeling and simulation of mechatronic systems using
Simscape, 2020, Morgan & Claypool
o Suggested Problems:
▪ Chapter 5 (Simulink and SimulationX/Simscape): 5.50, 5.51, 5.57, Hydraulic
Arm Lowering Mass problem
▪ SimulationX problems will given through the project and assignments
30
Selected Quote
“Genius is 1 percent inspiration and 99 percent perspiration”
Thomas A. Edison
31