You are on page 1of 69

cyber physical systems

modeling
SSK5220
Cyber-Physical Systems Modeling

Chapter 2
Model based
Design
Part 1 , 2 ,
3
2

Overview

What is a Model Based


Design?
3

Modeling, Design, Analysis

 Modeling is the process of


gaining a deeper
understanding of a system
through imitation.
Models specify what a system
does
 Design is the structured creation of
artifacts. It specifies how a
system does what it does. This
includes optimization
 Analysis is the process of gaining a
deeper understanding of a system
through dissection. It specifies why
a system does what it does (or fails to
do what a model
4

What is
Modeling?
 Developing insight about a system, process, or
artifact through imitation

 A model is the artifact that imitates the system,


process, or artifact of interest

 A mathematical model is a model in the form of a set of


definitions and mathematical formulas
5

What is Model-Based Design?


 Create a mathematical model of all the parts of
the embedded system Mathematics is formal
 Physical world  Continuous behavior
 Control system
 Software environment
 Hardware platform
 Network
 Sensors and actuators
 Construct the implementation from the model
 Construction may be automated, like a compiler
 More commonly, portions are automatically constructed
6

Modeling Techniques in this


Course
 Models that are abstractions of system dynamics (how
things change over time)

 Examples:
 Modeling physical phenomena, continuous dynamics – Ordinary
Differential Equations (ODEs)
 Feedback control systems – time-domain modeling
 Modeling modal behavior, discrete dynamics – FSMs, hybrid
automata
 Modeling sensors and actuators – calibration, noise
 Modeling software – concurrency, real-time models
 Modeling networks – latencies, error rates, packet loss
7

Overview

A Quick
Recipe
At a Glance: Model-based
8

Design 10 Steps Solution


MBD Step 1: State the Problem
 Use simple language to describe the problem 
without the use of mathematics or technical
terminology.
 This is the “elevator speech” for the project and is a handy reference
for developers, collaborators, colleagues and experts, vendors, and
machine shops
 Developers of large or safety critical applications should
also write a project plan consisting of requirement
tracking, metrics, formal testing processes, and (most
importantly) a process for peer review
 Given the multidisciplinary nature of cyber-
physical systems, this step is necessary to
effectively communicate design requirements
 One alternative is to use functional modeling
At a Glance: Model-based
11

Design 10 Steps Solution


MBD Step 2: Model Physical Processes
 A first iteration of physical modeling should establish
basic observations and insight into relevant physical
systems
 For example: the environment in which the cyber-physical system
resides, or physical processes to be controlled.
 Models of physical processes  simplified
representations of real systems
 Differential equations or Laplace transfer functions
 This simple mathematical models will be refined in the
following development of a control algorithm,
specification of hardware, and testing of components and
subsystems.
At a Glance: Model-based
12

Design 10 Steps Solution

MBD Step 3: Characterize the Problem


 Isolate fixed parameters, adjustable parameters,
and variables to be controlled.
 Identify quantities that characterize physical processes,
such as configuration spaces, safety limitations, input
and output sets, saturation points, and modal behavior.
 Understand how a physical process may interact with a
computation, including end-to-end latency
requirements, fault conditions, and reactions to noise
and quantization.
At a Glance: Model-based
13

Design 10 Steps Solution

MBD Step 4: Derive a Control Algorithm


 Determine conditions under which physical processes
are controllable and derive a suitable control algorithm to
be executed by an embedded computer.
 Use the problem characterization (step 3) to specify
requirements on latencies, delays, sampling rates, jitter,
and quantization so that the physical dynamics of interest
can be accurately measured and suitably controlled;
 these requirements must be satisfied by the computational platform
used.
At a Glance: Model-based
14

Design 10 Steps Solution

MBD Step 4: Derive a Control Algorithm (Continue)


 In highly distributed systems (globally asynchronous but
locally synchronous)  it may be necessary to select models
of computation (MOC) (Step 5) before a control algorithm
can be derived
 Revisit this step after selecting MOC and specifying
hardware to determine the impact of latency jitter or variable
sampling rates introduced by an asynchronous model of
computation, or saturation or other nonlinear artifacts
introduced by hardware
At a Glance: Model-based
15

Design 10 Steps Solution

MBD Step 5: Select Models of Computation


(MOC)
 A model of computation is a set of allowable
instructions used in a computation along with rules that
govern the interaction, communication, and control flow
of a set of computational components.
 A formal model of computation defines semantics that
often result in greater analyzability and the potential to
simulate CPS through the use of heterogeneous modeling
tools
At a Glance: Model-based
16

Design 10 Steps Solution


MBD Step 5: Select MOC (Continue)
 Models described by formal models of computation may be
easier to analyze with respect to determinism, execution
time, state reachability, memory usage, and latency.
 These software dynamics alter the evolution of a CPS, and
if modeled may be generalized and used in an MBD
workflow.
 The inherent complexity of many cyber-physical systems
often necessitates the composition of multiple MOC
 Advantages of using a specific model of computation
depend on its semantics, whether timing constructs are
used, and whether it is Turing-complete.
At a Glance: Model-based
17

Design 10 Steps Solution


MBD Step 6: Specify Hardware
 Select hardware that is capable of withstanding the
environment, interacting with the modeled physical
systems, and implementing the control algorithm
 For each component, consider
 its input and output bandwidths,
 delay from input to output,
 power usage,
 measurement resolutions and rates, and
 mechanical parameters such as form factor,
 rejection of electrical interference, durability, and lifespan.
 Mechanical actuators should be capable of producing forces
and torques in excess of minimum values derived from
earlier problem characterizations (Step 3)
At a Glance: Model-based
18

Design 10 Steps Solution


MBD Step 6: Specify Hardware (Continue)
 Consider and model the impacts of using cost-
effective substitutes for ideal parts
 keep in mind that manufacturer specifications are not always accurate,
and that hardware components should be independently tested.
 Selection of an embedded computer may hinge on a
deeper understanding of:
 latency and execution time requirements of control algorithms,
 worst-case execution time measurements of synthesized software,
and
 reasoning as to how software will interact with a specific hardware
architecture.
 This step may require several iterations with software
design and simulation before an embedded computer can
be selected with confidence
At a Glance: Model-based
19

Design 10 Steps Solution


MBD Step 7: Simulate
 Solve the problem using a desktop simulation
tool.
 If multiple MOCs are to be used, simulation and synthesis tools
must allow the compositions of and interactions between multiple
models of computation  Co-Simulation
 Depending on the robustness of the development environment,
incorporate models of sensors, actuators, and physical processes
 Use platform-based design to separate application logic
and architecture-specific software  modular
components,
 Improved code portability,
 reduce the impact of changing hardware components

 allow components to be reused in other contexts

At a Glance: Model-based
20

Design 10 Steps Solution


MBD Step 7: Simulate (Continue)
 Models of individual components and subsystems are
as important as a complete end-to-end model
 Component models provide a test harness for
construction, verification of synthesized software, and
testing
 If no one modeling tool can completely describe the
system, then for each subsystem use the modeling tool
that best captures its dynamics
 While disjoint simulations cannot represent relationships
between signals that cross subsystem boundaries, or the
behavior of compositions of these subsystems  co-
iteration of physical modeling, simulation, and testing
 Ptolemy II is a versatile tool for researching heterogeneity, allowing
developers to easily create new MoC and simulate their behavior
At a Glance: Model-based
21

Design 10 Steps Solution


MBD Step 7: Simulate (Continue)
 Many simulation tools exist, but most are limited to only a
few MoC and are unable to capture the interactions between
heterogeneous systems
 Ptolemy II and LabVIEW are capable tools in this realm:
 continuous systems are expressed as ODE or DAE, and discrete
systems are expressed as difference equations
 LabVIEW Control, Design, and Simulation Module: concurrent state
machines are expressed in models created in the LabVIEW Statechart
Module (which implements a variant of Harel’s Statecharts)
 Imperative expressions are expressed as formula nodes (subset of
ANSI C)
 Mathworks, Inc. MATLAB/Simulink software and others;
 data acquisition and program flow are expressed in structured dataflow,
which is general enough to allow the composition of each of these
models of computation.
At a Glance: Model-based
22

Design 10 Steps Solution


MBD Step 8: Construct
 Build the device according to specifications, taking note
where exceptions have been made that may impact
earlier modeling.
 Plan construction in a way that allows individual
components and subsystems to be tested against
theoretical models, which facilitates co-iteration
between simulation and testing.
At a Glance: Model-based
23

Design 10 Steps Solution


MBD Step 9: Synthesize Software
 Code synthesizers are sometimes incorporated into
desktop simulation environments.
 They may directly support the embedded computer or generic code
may be synthesized and tied to handwritten, architecture-specific code.
 Assuming the code synthesizer produces code that
faithfully executes the semantics of the models of
computation used, the logic of synthesized code is correct
by construction.
 Timing behavior, however, must still be verified, as code generators
and compilers may introduce software timing artifacts, and hardware
features such as pipelines and caches may introduce jitter.
 Other constraints such as memory footprint or processor utilization may
also require independent verification. Timing and other constraints
should be verified against existing models.
At a Glance: Model-based
24

Design 10 Steps Solution


Step 10: Verify, and Validate, and Test
 Configure adjustable parameters to create test
environments that are as simple as possible, and test
each component and subsystem independently.
 Computational systems may be isolated from physical
systems via hardware-in-the-loop testing, where
programmable hardware such as embedded computers
or FPGAs simulate the feedback from physical or other
computational processes
 Measurements of execution time and latency can be used
to refine previous models, and unexpected test results
may point to errors in modeling or implementation.
At a Glance: Model-based
25

Design 10 Steps Solution


Step 10: Verify, and Validate, and Test (Continue)
 Formal verification and validation give insight into the
behavior of an algorithm over all or certain combinations
of its inputs, or over the course of time.
 Precisely state requirements and translate them into
a formal specification for verification and validation.
 List invariants that should be verified during testing.

Verification and validation are perhaps the most


difficult aspects in the design of a cyber-physical
system
26

Reference and reading

 For this quick recipe study the following paper.


A Model-Based Design Methodology for Cyber-
Physical Systems
 https://citeseerx.ist.psu.edu/document?repid=rep1&type=p
df&doi=631fd4253eaabf8c3e43a0d0b01dfb183e02d97a
Step 1 – Step 4
Step 1 (Stating the problem) : Describe the problem in simple language for
developers, collaborators, experts, etc. In addition, developers should write a project
plan to communicate the design requirements.

Step 2 (Model Physical Processes) : Modeling should establish basic observations


and insight into relevant physical systems (environment control process).

Step 3 (Characterize the Problem) : Isolate fixed parameters, adjustable parameters,


and variables to be controlled, Identify quantities that characterize physical
processes, understand how a physical process may interact with a computation.

Step 4 (Derive a Control Algorithm) : Determine conditions controllable and derive a


suitable control algorithm to be executed by an embedded computer. Problem
characterization specify delays, sampling rates, jitter, and quantization. May
necessary to select models of computation before a control algorithm can be
derived.
Step 5 – Step 8
Step 5 (Select Models of Computation) : A model of computation is a set of
computational components. A model of computation have greater
analyzability and potential to simulate CPS through modeling tools, and the
latency aspect may be easier to analyze.

Step 6 (Specify Hardware) : Capable of withstanding the environment,


interacting with the modeled physical systems, and control algorithm, this
step may require several iterations can be selected with confidence.

Step 7 (Simulate) : Solve the problem using a desktop simulation tool, use
platform-based design to separate application logic and architecture-specific
software (modular components)

Step 8 (Construct) : Build the device may impact earlier modeling. Allows
individual components and subsystems to be tested against theoretical
models, which facilitates co-iteration between simulation and testing.
Step 9 – Step 10

Step 9 (Synthesize Software) : Code integration are


sometimes incorporated into desktop simulation
environments. The logic of the synthesized code is correct by
construction.

Step 10 (Verify, and Validate, and Test) Configure adjustable


parameters to create test environments that are as simple as
possible, and test each component and subsystem
independently.
4

Overview

Modeling of Continuous
Dynamics
5

Modeling of Continuous
□Dynamics
Ordinary differential equations (ODE)
□ Laplace transforms
□ feedback control systems
□ stability analysis
□ robustness analysis

6

Modeling of Continuous
□Dynamics
Classical mechanics: mechanical parts that moves
□ Applications:
□ Mechanical objects
□ Electric circuits,
□ Chemical Processes,
□ Biological processes
□ Motion of mechanical parts may be modeled using
differential equations (integral equations)
□ It works only for smooth motions – with assumptions
□ Linearity - system's response to input is assumed to be linear
□ time invariance - system's behavior doesn't change over time
□ continuity - system's behavior is assumed to be continuous,
without sudden jumps or disruptions in its motion
□ Others ➔ Collisions of mechanical parts are modeled using discrete
instantaneous events (hybrid systems modeling)
□ Collisions involves abrupt changes in velocity, position, or
energy.
An Example: Modeling 7

Helicopter
Dynamics
8

Modeling Physical Motion

□ Six degrees
of freedom:
□ Position in a 3
dimensional space: x, y, z
□ Orientation: pitch, yaw,
roll ➔ Angle of rotation

□ Position in space of an object is represented using


six functions
□ 3 for position
□ 3 for orientation
Source: https://www.britannica.com/technology/helicopter
9

Notation

Functions of this form


are known as
continuous-time signals

Vector-valued functions
10

Notation

for all values of the time t that is


elements of real numbers
11

Newton’s Second Law


motion Changes in position or orientation
are governed by Newton’s second law,
relating force with acceleration.
Acceleration is the second derivative
of position

□ x(0) is the initial position


□ if you know the initial position and initial velocity of an object and the forces
on the object in all three directions as a function of time, you can determine
the acceleration, velocity, and position of the object at any time.
12

Orientation

(force is applied)

□ Angular version of force is torque➔ For a point mass


rotating around a fixed axis
13

Torque
Angular version of force is torque➔ For a point mass
rotating around a fixed axis:

Ty(t ) = r f (t )
angular momentum, momentum

□ Just as force is a push or a pull, a torque is a twist


□ Units:
□Force newton
□Torque: newton-meters/radian, Joules/radian
Rotational Version of Newton’s 14

Second Law

T(t) = IӪ(t)
Rotational Version of Newton’s 15

Second Law
Rotational Version of Newton’s 16

Second Law

θ(0) is the initial orientation.


if you know the initial orientation and initial
rotational velocity of an object and the
torques on the object in all three directions as
a function of time, you can determine the
rotational acceleration, velocity, and
orientation of the object at any time.
17

Model-order Reduction

□ Model-order reduction: Example, we used the


spherical object
□Simplify by reducing the number of dimensions that are
considered
□ A n object is a moving vehicle on a flat surface,
there may be little reason to consider the y axis
movement or the pitch or roll of the object
17

Model-order Reduction
□ key points and objectives
1. Complex Systems: In many engineering and scientific applications,
complex systems are modeled with high-dimensional equations or
numerical simulations. These models can be computationally
expensive and challenging to analyze.
2. Reducing Computational Burden: One primary objective of MOR is
to reduce the computational burden associated with solving,
simulating, or analyzing these high-dimensional models. This can lead
to faster simulations and more efficient computations.
3. Preserving Key Properties: While reducing the model's order, MOR
aims to preserve key properties of the system, such as its stability,
response to specific inputs, or dynamic behavior. It ensures that the
reduced model accurately captures the phenomena of interest.
17

Model-order Reduction
□ Methods: employs various mathematical and numerical
techniques to perform the dimensionality reduction.
□ Proper Orthogonal Decomposition (POD): This method identifies
dominant modes of the system and retains only the most significant
ones.
□ Balanced Truncation: It balances the system and then truncates it to
reduce its order while maintaining key dynamics.
□ Krylov Subspace Methods: These iterative methods are used to
compute a reduced model based on certain approximations.
□ Model Reduction by Interpolation (Krylov and Loewner): These
methods construct reduced models by interpolating key system
responses.
17

Model-order Reduction
1.Applications:
1. MOR is applied in various fields, including control systems,
electromagnetics, structural mechanics, and fluid dynamics.
2. It is used in the design and analysis of complex systems like aircraft,
space systems, electronic circuits, and structural designs.
3. In control theory, reduced-order models are often used to design
controllers that maintain system stability and desired performance.

2.Trade-offs: While MOR can significantly reduce computational costs,


it may lead to a loss of certain fine-grained details in the model. Therefore,
the choice of reduction method and the level of reduction should be
carefully considered based on the specific problem and application.
18

Example: Feedback Control


Problem
A helicopter without a tail rotor, like the
one below, will spin uncontrollably due to
the torque induced by friction in the rotor
shaft

Control system
problem: Apply
torque using the tail
rotor to
counterbalance the
torque of the top
rotor.
19

Simple
Example
□ Helicopter has two rotors
► One above that provided lift
► One on the tail
□ Goal: Model a helicopter.
□ Assumptions:
► Helicopter position is fixed at the origin ➔
we do not need any equation governing the
dynamics of position.
► Helicopter remains vertical ➔ pitch and roll
are fixed at zero

□ Simplified model.
20

Simple
Example
Therefore, we may now model the helicopter by a system that takes
as input a continuous time signal Ty, the torque around the y axes.
21

References

All the content of this lecture has been adapted from the
book and lectures of Edward A. Lee and S. Seshia
2.2 Actor Model of Systems
oA system is a function that
accepts an input signal
and yields an output
signal
o Continuous time system- x:R→R , Y:R→
operates on continuous
time signals
R
o The domain and range of SX→Y
the system function are
sets of signals, which
X=Y=(R→R)
themselves are functions
o Parameters may affect
the definition of the
function S
o Tool: LabView, Simulink
Actor model of the helicopter

oInput is the net torque of


the tail rotor and the top
rotor. Output is the
angular velocity around
the y axis

oParameters of the
model are shown in
the box. The input
and output relation
is given by the
equation to the
right
Cascade composition

o In particular, given two actors S1 and S2 , we can form


a cascade composition as follows:
Actor models with multiple inputs

S(R→R)2→(R→R)
2.3 Properties of Systems

. Causal systems
. Memoryless systems
. Linearity and time invariance
. Stability
Causal Systems
Memoryless Systems
. A system has memory if the output depends not only on the
current inputs, but also on past inputs (or future inputs, if not
causal).
. In a memoryless system, the output at time t depends only on the
input at time t .
. Formally, a system is memoryless if there exists a function
f : A → B such that for all x ‘ X and for all t ℝ

(S(X))(t ) = f(x (t ))

. The Integrator is not memoryless, but the adder is.


. A strictly causal, memoryless system has a constant output for all
inputs.
Linearity and Time Invariance
. A system is linear if it satisfies the superposition property:
V ,∈ xandva,bER,s(a+b)=as()+bs()
y (0) = 0.
. The helicopter example is linear if and only if θ̇
. Integrator is linear when i = 0, and scale factor/adder are always
linear.

x1(t) y1(t)
Linear System

x2(t) y2(t)
Linear System

x(t) = a1 x1(t)+ a2 x2(t) y(t) = a1 y1(t)+ a2 y2(t)


Linear System
Linearity and Time Invariance
. A system is time invariant if:

where D:x→y is a delay such that


. Helicopter example is not time invariant unless no initial angular
rotation, and the integral starts at − 。 .
x(t) y(t)
x(t-t0)
system
y(t-t0)
x(t) y(t)
t
t

x(t-t0)
y(t-t0)
t
t
t0
t0
Stability

. A system is bounded-input bounded-output (BIBO) stable if the


output signal is bounded for all input signals that are bounded.

. Consider a continuous-time system with input w and output


v. . The input is bounded if there is a real number A < 。 such
that
|w(t)l≤AforallteR.
. The output is bounded if there is a real number B < 。 such that
. The system is stable if for any input bounded by some A, there is
some bound B on the output.
Open-Loop Helicopter

. Helicopter example is not stable.


. Consider input Ty = u where u is a unit step input:

. The system function is:


2.4 Feedback Control
. Feedback control is used to achieve stability.
. These systems measure the error (difference between actual and
desired behavior) and use this information to correct the behavior.

y e
K
Mathematical
Analysis
Mathematical Analysis
(cont)
Helicopter Model with Separately
Controlled Torques
Mathematical
Analysis
Continuous vs Discrete Signals
. Continuous, also called continuous time, signals defined as
x:R→R
. Discrete, also called discrete time, signals defined as
Key Concepts in Model-Based Design
o Models describe physical dynamics
o Specifications are executable models
o Models are composed to form designs
o Models evolve during design
o Deployed code may be (partially) generated from
models
o Modeling languages have semantics
o Modeling languages themselves may be modeled
(meta models)
o For embedded systems, this is about
o Time
o Concurrency
o Dynamics
Summary

o Two distinct modeling techniques that describe physical


dynamics
o Ordinary Differential Equations (ODE) èa venerable
toolkit for engineers
o Actor models, a newer technique driven by software
modeling and simulation tools
o we may use multiple models for a system, and that
models are distinct from the systems being modeled
o The fidelity of a model (how well it approximates the
system being modeled) is a strong factor in the success or
failure of any engineering effort
Concluding Remarks

. This lecture introduces two modeling techniques


that describe physical dynamics: ODEs and actor
models.
. This lecture emphasizes the relationship between
these models.
. The fidelity of a model (how well it approximates the
system) is a strong factor in the success or failure of
any engineering effort.

You might also like