0% found this document useful (0 votes)
15 views50 pages

AISE3350A FW24 Lecture Notes Week3 2

The document outlines the principles of modeling cyber-physical systems (CPS) using mathematical concepts such as differential equations and conservation laws. It discusses the importance of modeling for predicting system behavior, optimizing designs, and early detection of flaws, while emphasizing the relationship between physical phenomena and mathematical representation. Various modeling techniques, including continuous-time and discrete-time models, are introduced to analyze and design complex systems effectively.

Uploaded by

mecoma8742
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views50 pages

AISE3350A FW24 Lecture Notes Week3 2

The document outlines the principles of modeling cyber-physical systems (CPS) using mathematical concepts such as differential equations and conservation laws. It discusses the importance of modeling for predicting system behavior, optimizing designs, and early detection of flaws, while emphasizing the relationship between physical phenomena and mathematical representation. Various modeling techniques, including continuous-time and discrete-time models, are introduced to analyze and design complex systems effectively.

Uploaded by

mecoma8742
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

AISE3350A

Cyber-Physical Systems Theory Computation

Fall 2024
Instructor: Elvis C.S. Chen
Department of Electrical and Computer Engineering
Faculty of Engineering, Western University
Cyber Physical

Information

Lecture 2 Communication Control


Week 3 Systems
September 20, 2024

1
Modelling Physical Systems
• How can we use math to predict the behaviour of physical systems?
• This lecture cover principles of modelling physical systems:
– Differential equations, with a focus on ordinary differential equations
– Systems of equations
– One-, two-, and three-dimensional mechanical systems (statics and dynamics), and
– Resistive and linear electric circuits.

2
Terminology
• Plant: The physical world that is to be Example
controlled by a component called the In the thermostat design, the plant is the
plant. room whose temperature is to be
• Controller: The evolution of the plan controlled. The sensor is the
can be influenced by the controller thermometer that measures the current
using actuators, but it also depends on temperature.
uncontrollable factors from the The task of the controller is to regulate
environments, called disturbances. the temperature so it stays close to the
• Reference inputs: The controller reference temperature set by the
responds to command from the user, occupant on the thermostat.
called the reference inputs, and make
its decisions based on measurements
of the plan provided by the sensors.
3
Terminology
• The controller influences the • In the continuous-time model, the
temperature by adjusting the heat flow values of the variables of a dynamic
from the furnace. system are updated continuously with
• The plant model, in this case, needs to the passage of time.
capture how the temperature of the • These variables of a continus-time
room changes as a function of the component typically range over a
heat-flow from the furnace and the compact set such as a closed interval
difference between the room of a set of real numbers with specified
temperature and the outside unit of measurement.
(ambient) temperature, which is the • E.g. the velocity 𝑣 of a car can be
uncontrolled disturbance. modelled by a variable that ranges
over the real number in the interval
from 0 to 160 km/h
4
Reconnecting with the physical world
• CPSs are ubiquitous in modern society. • The physical phenomena that are
• CPSs are closely coupled with the useful to model depends on the
physical world. problem; the phenomena may be
• To understand these systems and to – Physical
build the skill required to develop new – Chemical
innovation, we need to have some – Biological
experience with modelling physical – Economic, or even
systems. – Social
• Often, it is the physical nature of the • We’ll focus on physical phenomena
problem that will either derive a – Mechanics,
solution or affect the extent to which a – Electromagnetics
new product solves the given problem. – thermodynamics

5
Modelling
Why modelling?
• Imaging you are designing an autonomous
vehicle what is capable of navigate
between two moving vehicles, how would
you develop/program an algorithm to
achieve such task?
– What possible inputs/sensors are available,
– How do these inputs (variables) change over
time?
• Mathematical modelling provides a toolkit
for understanding, analyzing, and
predicting the bahaviour of complex https://imechewebresources.blob.core.windows.net/imech
systems before they are built. e-web-content/images/default-source/pe-
news/shutterstock_1855631032.jpg?sfvrsn=88929e12_0

6
Benefits of Modelling
• Prediction: simulates system behavior Examples
under different conditions, exploring • Given the speed of the vehicle, and the
the what-if scenarios and anticipating distance of an obstruction on the road,
potential issues can the vehicle achieve full stop in
time, or should the vehicle drive
around it?

• Early detection of flaws: identify • Given the weight of the vehicle, should
design flaws or weakness in the early the break system be resized to reduce
stages of the development, saving time the braking distance?
and resources

7
Benefits of Modelling
• Optimization: enable the exploration Examples
of different design choices and • In a plug-in hybrid vehicle, how to
parameters values to optimize system optimize the amount of battery to
performance, efficiency, and safety achieve best fuel efficiency/range?

• Virtual prototyping: allowing • Matlab/Simulinks


engineers to experiment with different
design iterations in a simulated
environment before committing to
physical prototypes.

8
Benefits of Modelling
• However, it is important to remember that models are
simplified representations of reality. The accuracy and
usefulness of a model depends on how well it captures the
essential features of the system being studies.

9
Conservation Laws and Constitutive Relationships
• A theme in physical modelling is the
presence of conservation laws. These
laws are the workhorse of the process
of mathematical modelling
• Examples from mechanical systems
– Conversation of energy
– Conservation of momentum (translational
and rotational)
– Conservation of mass
• Example from electrical system
– Conservation of current

10
Conservation Laws and Constitutive Relationships
• Deeper principles in physics allow us to Definition: a conservation law states that
connect some of the principles a particular measurable property of an
mentioned: 𝐸 = 𝑚𝑐 2 allows to isolated physical system does not change
connect energy and mass as the system evolves over time.
• These principles allow us to model and
analyze physical systems. Alternatively: the rate at which the
quantity 𝑄(𝑡) changes has to be
accounted by how much of the substance
goes into the system, and how much of it
goes out of the system
𝑑𝑄
= 𝑄𝑖𝑛 − 𝑄𝑜𝑢𝑡
𝑑𝑡

11
Conservation of Energy
• Definition: in a closed system, the total
energy remains constant over time.
Energy can be transformed from one
form to another, but it cannot be
created or destroyed

https://en.m.wikipedia.org/wiki/File:Pendulum-no-text.gif

12
Conservation of Momentum
• Definition: in a closed system, the total
momentum (linear and angular)
remains constant in the absence of
external forces or torques

• Linear momentum
𝑝 = 𝑚𝑣

• Angular momentum
𝐿 = 𝐼𝜔 = 𝑟 × 𝑝
https://makeagif.com/gif/conservation-of-momentum-
JWUZ5p

13
Conservation of Mass
• Definition: in a closed system, the total
mass remains constant over time, even
if substances undergo physical or
chemical changes

https://en.wikipedia.org/wiki/Conservation_of_mass

14
Mechanical Systems: Mass
• Conservation laws are essential for
modelling a wide range of CPS,
providing constraints that govern
system behaviour.
• In addition, mechanical and physical
systems have standard elements that
we need to understand to model their
behaviour accurately.
• Mass: a measure of an object’s
resistance to acceleration
𝑭 = 𝒎𝒂
https://youtu.be/oYEgdZ3iEKA?t=21
15
Mechanical Systems: Lever
• Lever is an element that consists of a
long rod balanced on a pivot
• The lever is in equilibrium if the
torques around the pivot are equal
𝒎𝟏 𝒈𝒂 = 𝒎𝟐 𝒈𝒃
Where 𝒎𝟏 and 𝒎𝟐 are the masses, 𝒂
and 𝒃 are the distances from the
center of the mass to pivot, and 𝒈 is
the gravitational acceleration.
If there is no gravity, the above
equation still holds true.

16
Mechanical Systems: Friction
• Friction is a phenomena that generates a
force opposite in the direction of
(potential) movement, and is usually
proportional to a normal force (𝑁) that is
normal to the direction.
• Two types of dry frictions:
– Static friction: prevents object from
moving when at rest
𝑓𝑠 ≤ 𝜇𝑠 𝑁
– Kinetic friction: acts on moving objects,
slowing them down. Generally weaker
than static friction
𝑓𝑘 ≤ 𝜇𝑘 𝑁
where 𝑓𝑠 and 𝑓𝑘 are coefficient of static/kinetic friction, respectively
17
Mechanical Systems: Spring
• Spring is a component modelled by Hooke’s
Law:
𝐹 = −𝑘𝑥
Where 𝐹 is a force, 𝑥 is a displacement
relative to a neutral position for the spring,
and 𝑘 is a (scalar/stiffness) coefficient that
relates these two.
• 𝐹 and 𝑥 quantities can be dimensional,
and 𝑘 is always a scalar.
• Hooke’s Law is only a first-order linear
approximation to the real response of
spring and other elastic bodies to
applied force.

18
Mechanical Systems: Damper
• Damper creates a force against the
direction of movement, and in
proportion to the speed of the
moment
𝐹 = −𝑐𝑣
where 𝐹 is the damping force (in 𝑁), 𝑐
is the damping coefficient (in 𝑁 ∙
𝑠/𝑚), and 𝑣 is the velocity (in 𝑚/𝑠)

19
Mechanical Systems: Air Resistance
• Air resistance is a force created by air
and applied to any object moving
through it. At slow speeds (<< speed of
sound), we can view this as being
proportional to the square of the
speed:
𝐹 = −𝑘𝑣 ∙ 𝑎𝑏𝑠(𝑣)
• Terminal velocity?

20
Electrical Systems: Resistors
• Resistors resist the flow of electric
current. It follow Ohm’s Law

𝑉 = 𝐼𝑅

where 𝑉 is the voltage, 𝐼 the current,


and 𝑅 the resistance

21
Electrical Systems: Capacitor
• Resistors is an element where the voltage
across is proportional to the integral of the
current through the current. Alternatively,
current is proportional to the rate of
change of the voltage across it

𝐼 = 𝐶𝑉′
where the ratio 𝐶 is called the
capacitance. The higher the capacitance,
the greater the current needed to
correspond to a small change in voltage

22
Electrical Systems: Inductor
• Inductor is an element where the rate
of change in current is proportional to
the voltage across it:

𝑉 = 𝐿𝐼′
where the ratio 𝐿 is called the
inductance. The higher the
inductance, the higher the voltage we
need to get the same rate of change in
current.

23
Remarks
• Each of these elements comes with a • At any node (region of the circuit that
set of equations that describes its is connected and is not interrupted by
effect on the system that it is used in. elements), the total in-going and out-
• To analyze a given circuit, these rules going current must be zero.
are applied, along with one or more • Around any loop in the circuit (any
instances of the basic conservation path through connected components
laws for circuits, which are that in the circuit), the total voltage
difference experienced must be zero.

24
Static Problem
• A static problem is one where the
system components are not moving,
and nothing internal to the system can
cause them to move.
• E.g. for the system shown in the
picture, if we are told that the system
is at rest, then we can write an
equation that relates 𝑚, g, 𝑘, x, and 𝐹𝑘

25
Dynamic Problem
• A dynamic system has at least one
component that may be moving
• E.g. the 𝑚1 (at position 𝑥1 ) may be
moving with a speed of 𝑥 ′ and
acceleration 𝑥 ′′
• Need to know other states (position at
some given time) in order to solve the
resulting equations
• Often involves formulating a system of
ODEs involving the variables, their
derivatives, and their second order
derivatives.

26
Modelling CPS
How to model CPSs then? • Continuous-time model: time is
• Discrete-time model: simple but continuous or infinite number of time
powerful technique: time is discrete instances. This model is what we will
and the values of the variables may use mainly for the physics component
take in discrete sets, but also of a CPS, and it relates to differential
potentially on dense sets. This equations:
technique essentially uses allotted
time, and one model the system when
t=0, t=1, t=2, …, etc.,

27
Modelling CPS
• Finite-state machine: a more • Hybrid automata: a general type of
structured type of discrete model. It modelling framework that essentially
has a state that take value from a finite combines all of above
set, and the model itself will allow only • Not covered in this course.
transition between the different state
using some sort of a law.
• Not covered in this course.

28
Discrete-time model
• A discrete-time model relates inputs to
outputs to a system:
• 𝑘 = 0,1,2, … , denotes a discreate time
instance and 𝑘 ∈ ℕ
• 𝑣 is the input to the system, which is a
function of time 𝑘, i.e. we know v(𝑘)
when 𝑘 = 1,2,3, …
• The state of the discrete-time system
• 𝜂 is the output of the system, defined typically is a vector 𝑥 that captures all
only on a discrete time instance. The meaningful variables of the system in
first value of 𝜂 will also depends on the order to describe these changes over time
initial state of the discrete-time system

29
Difference Equation Model
• Given functions 𝐺 and ℎ, the model of the • G updates the state of the system
input/output relationship is given: iteratively:
𝑥 + = 𝐺(𝑥, 𝑣) • 𝑥 1 = 𝐺 𝑥 0 ,𝑣 0
𝜂 = ℎ(𝑥, 𝑣)
• 𝑥 2 = 𝐺 𝑥 1 ,𝑣 1
• 𝐺 describes how the state of the discrete-
time system evolves with time as a = 𝐺 𝐺 𝑥 0 ,𝑣 0 ,𝑣 1
function of the current state 𝑥 and input • 𝑥 3 = 𝐺 𝑥 2 ,𝑣 2
𝑣, while
= 𝐺(𝐺 𝐺 𝑥 0 , 𝑣 0 , 𝑣 1 , 𝑣(2))
• The output of the system 𝜂 is governed by
a function ℎ that also depends on 𝑥 and 𝑣
• Together, 𝐺 and ℎ are the Discrete-Time
model

30
Difference Equation Model
• Given a discrete-time system, we can • So how to determine the function 𝑥?
define the solutions or trajectories to the • You can either guess what it is, and given
system from a particular initial condition the initial condition 𝑥0 and the input 𝑣,
for a given input: verify whether the solution you guessed is
𝑥 + = 𝐺 𝑥, 𝑣 indeed correct, or
𝜂 = ℎ 𝑥, 𝑣 • You can construct it iteratively. As this is an
𝑥0 = 𝑥0 iterative method, it is very simple and
Input 𝑣 systematic.
• A solution from 𝑥0 under the effect of the
input 𝑣 is a function of discrete time,
labelled 𝑥, such that it satisfies the
following property:
𝑥 𝑘 + 1 = 𝐺 𝑥 𝑘 , 𝑣 𝑘 , ∀𝑘 ∈ ℕ
where 𝑣 is defined.

31
Difference Equation Model
• One caveat is that the input 𝑣 may not be • Thus, the solution space for 𝐺 and ℎ are:
defined for all values of 𝑘 ∈ ℕ, so for Let 𝑥 ∈ ℝ𝑛 , v ∈ ℝ𝑚 , then
formality, define: 𝐺: ℝ𝑛 × ℝ𝑚 ⇒ ℝ𝑛
• 𝑑𝑜𝑚 𝑓 as the domain for an arbitrary ℎ: ℝ𝑛 × ℝ𝑚 ⇒ ℝ𝑝
function 𝑓, which is a collection of all the • Note that the output dimension 𝑝 is
points at which 𝑓 is defined. This allows us entirely user-defined.
to define
• E.g. to model a ground vehicle, we can
𝑥 𝑘 + 1 = 𝐺 𝑥 𝑘 , 𝑣 𝑘 , ∀𝑘 ∈ ℕ ∩ 𝑑𝑜𝑚 𝑣
control the paddle for acceleration (force)
where 𝑣 is defined, and and the steering while (2 inputs), with
𝜂 = ℎ(𝑥 𝑘 , 𝑣 𝑘 ) position (x,y) and orientation being
measured (3 states). However, the system
is used as a GPS, the output of the system
may only be the position (x,y), i.e. 𝑝 = 2

32
Example: Discrete-time model
• Suppose we want to model the • The input to the system can be
movement of a ground vehicle using 3 – Force/thrust 𝑣1
variables: – Angular speed 𝑣2
𝑣1
– 𝑥1 denotes the horizontal position v= 𝑣
2
– 𝑥2 denotes the vertical position
• And let the output be only the angle
– 𝑥3 denotes the orientation/angle
𝑥1 𝜂 = 𝑥3 ⇒ ℎ 𝑥, 𝑣 = 𝑥3 ∈ ℝ, (p=1)
𝑥 = 𝑥2 ∈ ℝ3 , (n=3)
𝑥3

33
Example: Discrete-time model
• We can relate the state, the input, and the
output using the first principle:
𝑥1+ = 𝑥1 + 𝑑 sin 𝑥3 𝑣1
𝑥2+ = 𝑥2 + 𝑑 cos 𝑥3 𝑣1
𝑥3+ = 𝑥3 + 𝑐𝑣2
which is the function G(x, v). The
constant d and c depends on the
sampling rate
• Given the initial state 𝑥0 and the
constant 𝑑 and 𝑐 corresponding to the
model, and given the input 𝑣1 and 𝑣2 as
a function of 𝑘, we can now generate the
change of the state according to these
difference equation, and generate the
output according to this equation.

34
Simulation
• Create a directory called “week3”, and
start Matlab
• Start Simulink by typing “simulink” in
Matlab prompt
• If Simulink is not installed as part of
your Matlab, an error message will
pop-op with a link. Follow the link to
install Simulink on your Matlab base

35
Simulation
• If Simulink was installed, a new
window will pop-up,
• Click on Blank Model to start a new
project
• You will be presented with a clear
canvas. The Library Browser has many
pre-defined blocks we can use

36
Simulation
• Recall these are the equation that
models the physical process (plant) of
the vehicle:

𝑥1+ = 𝑥1 + 𝑑 sin 𝑥3 𝑣1
𝑥2+ = 𝑥2 + 𝑑 cos 𝑥3 𝑣1
𝑥3+ = 𝑥3 + 𝑐𝑣2

37
Simulation
• And because this is an iterative,
discrete-time, process, we are going to
use the Unit Delay block under Library
Browser->Simulink->Discrete. Find the
Unit Delay block and click/drage it to
the canvas

38
Simulation
• Inputs to the Unit Delay will be a
Matlab function that implements the 3
function above.
• To do so, add the Matlab Function
block under Library Browser-
>Simulink->User-Defined Function to
the canvas. Connect the output of the
Matlab Function block (y) to the input
of the Unit Delay

39
Simulation
• Output: to visualize the result, we can
direct the output of the unit delay to
Matlab workspace.
• To do so, add the To Workspace block
from Library Browser->Simulink-
>Sinks to the canvas, and connect the
output of the Unit Delay to the input
of the To Workspace block.

40
Simulation
• Plotting: To assist us in plotting the
results, we need to change the output
format to Array
• Double-click on the To Workspace
block and do the following:
– Change the Variable name to x, and
– Change the Save Format to Array

41
Simulation
• Inputs to the model: we need to
specify the input to the Matlab
function:
𝑥1+ = 𝑥1 + 𝑑 sin 𝑥3 𝑣1
𝑥2+ = 𝑥2 + 𝑑 cos 𝑥3 𝑣1
𝑥3+ = 𝑥3 + 𝑐𝑣2
• Which has 5 inputs:
𝑥1
𝑣1
𝑥
𝑥 = 2 and v = 𝑣
2
𝑥3
• We need a multiplexer to combine these
inputs into a single array so we can pass it to
the Matlab function.
• Add Mux (under Signal Routing)

42
Simulation
• User inputs: 𝑣1 and 𝑣2 can be anything
you want. Let’s use constant for 𝑣1
(force/thrust) and a step function for
𝑣2 (angular speed)
• The Constant block is under Simulink-
>Sources, connect the output to port 1
of the Mux block
• We will define our own step function
by adding the signal editor block.
Connect the output to the port 2 of the
Mux block

43
Simulation
• To specify our own input signal, double
click on the signal editor and launch
the signal editor user interface.
Specify a step function that is 1 from
k=4-6, and 0 otherwise

44
Simulation
• Mathematical Simulation: The actual
simulation of the plant takes place inside
the Matlab Function block, where we
implement the physical laws
mathematically:
𝑥1+ = 𝑥1 + 𝑑 sin 𝑥3 𝑣1
𝑥2+ = 𝑥2 + 𝑑 cos 𝑥3 𝑣1
𝑥3+ = 𝑥3 + 𝑐𝑣2
• In Matlab, we need to parse the input
first: the input to Mux, which combines
multiple inputs into a variable called v, the
order of v depends on how source signals
is connected to the Mux block.

45
Simulation
• Minor tweaking: some minor details
within Matlab need to be adjusted
• Start the model explorer and for the
Matlab function, change the size of
the variable u from -1 to 5
• Double-clock on the Unit Delay block
and change the initial condition to x0
and the Sample time to 0.1

46
Simulation
• Once these changes are made, you
should be able to run the simulation by
clocking on the green Run button. But
first, let’s define some initial condition
• Save the following file as
initialization.m
• Run this code to initialize the
simulation and press the green Run
button.

47
Simulation
• Visualization: save the following script
as postprocessing.m and run it after
the simulation is completed.

48
Simulation
• And you should see something like
this:

49
Exercise
• If you are not getting the plot like
the one shown above, debug your
Simulink program,
• Given the initial state, and our
inputs, try to understand what this
plot represents. Remember, we are
plotting the position of the vehicle.
• Experiment with different signal
sources (for 𝑣1 and 𝑣2 ) and try to
understand their influences on the
position of the vehicle.
• Explore different physical model.
Can we make it more complicated?

50

You might also like