Matlab3 Simscape

Download as pdf or txt
Download as pdf or txt
You are on page 1of 70

Modelling and

Simulation with
Simscape
[References]
1. Simscape User’s Guide, Mathworks, 2021.
2. Simscape Getting Started Guide, Mathworks, 2021.
3. Mathematical Modelling Using SimScape (Electrical Systems), Zaer Abo Hammour.
https://www.academia.edu/42834463/_Mathematical_Modeling_Using_SimScape_Electrical
4. Mathematical Modelling Using SimScape (Mechanical Systems), Zaer Abo Hammour.
http://engineering.ju.edu.jo/Laboratories/03_2-%20Mathematical%20Modeling%20Using%2
0SimScape_Mechanical.pdf
5. Physical Modelling with Simscape, Rick Hyde, MATLAB EXPO 2013.
6. Modeling and Simulation of Physical Systems with Simscape, Paul Lambrechts and Tadele
Shiferaw Tadele, MATLAB EXPO 2018.
7. Modeling and Analysis of DYNAMIC SYSTEMS, Ramin S. Esfandiari and Bei Lu, CRC Press, 2014.
2102209 MATLAB – Simscape 1/70
2102209 MATLAB – Simscape 2/70
2102209 MATLAB – Simscape 3/70
2102209 MATLAB – Simscape 4/70
2102209 MATLAB – Simscape 5/70
2102209 MATLAB – Simscape 6/70
2102209 MATLAB – Simscape 7/70
2102209 MATLAB – Simscape 8/70
2102209 MATLAB – Simscape 9/70
2102209 MATLAB – Simscape 10/70
2102209 MATLAB – Simscape 11/70
Introduction to Simscape
• Simscape is a set of block libraries for modeling physical systems in
the Simulink® environment. It employs the Physical Network
approach, which differs from the standard Simulink modeling
approach and is particularly suited to simulating systems that consist
of real physical components such as mechanical, electrical, hydraulic,
thermal, and pneumatic components.
• Simulink blocks represent basic mathematical operations. When you
connect Simulink blocks together, the resulting diagram is equivalent
to the mathematical model of the system under design.
• Unlike Simulink blocks, which represent mathematical operations or
operate on signals, Simscape blocks directly represent physical
components or relationships.

2102209 MATLAB – Simscape 12/70


• Simscape models use a Physical Network approach to model
building: components (blocks) corresponding to physical elements
such as pumps, motors, and op-amps, are joined by lines
corresponding to the physical connections that transmit power.
• Simscape technology lets you create a network representation of the
system under design, based on the Physical Network approach.
• With Simscape blocks, a system model is built the same way a
physical system is assembled. This approach allows for the
description of the physical structure of a system rather than the
causal mathematics.
• According to this approach, each system is represented as consisting
of functional elements that interact with each other by exchanging
energy through their ports.

2102209 MATLAB – Simscape 13/70


• These connection ports are nondirectional. They mimic physical
connections between elements.
• Connecting Simscape blocks together is analogous to connecting real
components. You do not have to specify flow directions and
information flow when connecting Simscape blocks, just as you do
not have to specify this information when you connect real physical
components.
• Simscape automatically constructs, from the model, equations that
characterize the system behavior.

2102209 MATLAB – Simscape 14/70


Library Structure Overview

• Simscape block library contains two libraries:


o Foundation library — Contains basic physical elements and
building blocks, as well as sources and sensors.
o Utilities library — Contains essential environment blocks for
creating Physical Networks models.
2102209 MATLAB – Simscape 15/70
• Simscape serves as the platform for the following Physical Modeling:
➢ SimFluids for modeling and simulating fluid systems
➢ SimDriveline for modeling and simulating power train systems
➢ SimMultibody for modeling and simulating mechanical systems
➢ SimElectrical for modeling and simulating electrical systems

Foundation

Multibody
Electrical
Driveline
Fluids
Simscape
Simulink
Matlab
2102209 MATLAB – Simscape 16/70
Overview of the Physical Network Approach to
Modeling Physical Systems
• In the Physical Network approach, each element is represented by
its non-directional connection ports with the corresponding Through
and Across variables.
component dc_voltage < foundation.electrical.source
% DC Voltage Source
% The ideal voltage source maintains a constant voltage across its
% output terminals, independent of the current flowing through the source.
% The output voltage is defined by the Constant voltage parameter, and
% can be any real value

parameters
v0 = { 1, 'V' }; % Constant voltage
end

equations
v == v0;
end Connections + and – are conserving electrical ports corresponding to the positive
and negative terminals of the voltage source, respectively. The current is positive if
end it flows from positive to negative, and the voltage across the source is equal to the
difference between the voltage at the positive and the negative terminal, V(+) – V(–).
2102209 MATLAB – Simscape 17/70
Connection Ports
• The number of connection ports for each element is determined by
the number of energy flows it exchanges with other elements in the
system, and depends on the level of idealization.
• An energy flow is characterized by its variables. Each energy flow is
associated with two variables, one Through and one Across. These
are the variables whose product is the energy flow in watts. For
example, the basic variables for mechanical translational systems
are force and velocity, for mechanical rotational systems—torque
and angular velocity, for hydraulic systems—flow rate and pressure,
for electrical systems—current and voltage.

2102209 MATLAB – Simscape 18/70


2102209 MATLAB – Simscape 19/70
2102209 MATLAB – Simscape 20/70
Example in
Mechanical Domain

• For example, a hydraulic pump in its simplest form can be


represented as a two-port element, with one energy flow associated
with the inlet (suction) and the other with the outlet.
In this representation, the angular velocity of the driving shaft is
assumed constant, making it possible to neglect the energy
exchange between the pump and the shaft. To account for a variable
driving torque, you need a third port associated with the driving
shaft.

2102209 MATLAB – Simscape 21/70


• This hydraulic element is thus finally represented with three energy
flows: two flows of hydraulic energy through the inlet and outlet of
the cylinder and a flow of mechanical energy associated with the rod
motion. It therefore has the following three connection ports:
o A — Hydraulic conserving port associated with pressure p1 (an
Across variable) and flow rate q1 (a Through variable)
o B — Hydraulic conserving port associated with pressure p2 (an
Across variable) and flow rate q2 (a Through variable)
o R — Mechanical translational conserving port associated with
rod velocity v3 (an Across variable) and force F3 (a Through
variable)

2102209 MATLAB – Simscape 22/70


2102209 MATLAB – Simscape 23/70
Variable Types
Physical Network approach supports two types of variables:
• Through Variables that are measured with a
gauge connected in series to an element.
Kirchhoff’s current law for the through
variables states the sum of currents flowing
towards an electrical node is equal to the sum
of currents flowing away from the node. If
this approach is transferred to the mechanical
rotational domain it means that the amount
of torque flowing into that node must be
equal to the amount flowing out.

2102209 MATLAB – Simscape 24/70


• Across Variables that are measured
with a gauge connected in parallel to
an element. Kirchhoff’s voltage law
for the across variables states that
the directed sum of the electrical
potential differences around any
closed circuit must be zero. This
implies that the voltage of all
components’ ports attached to an
electrical node must be the same. If
this approach is transferred to the
mechanical rotational domain it means that the angular velocity at all of
the component’s ports attached to that node must be the same.

2102209 MATLAB – Simscape 25/70


The following table lists the Through and Across variables associated
with each type of physical domain in Simscape software:
2102209 MATLAB – Simscape 26/70
2102209 MATLAB – Simscape 27/70
Direction of Variables
• Each variable is characterized by its magnitude and sign. The sign is
the result of measurement orientation. The same variable can be
positive or negative, depending on the polarity of a measurement
gauge.

• Elements with only two ports are characterized with one pair of
variables, a Through variable and an Across variable. Their
2102209 MATLAB – Simscape 28/70
orientation is defined with one direction. For example, if an element
is oriented from port A to port B, it implies that the Through variable
(TV) is positive if it “flows” from A to B, and the Across variable is
determined as AV = AVA –AVB, where AVA and AVB are the element
node potentials or, in other words, the values of this Across variable
at ports A and B, respectively.

2102209 MATLAB – Simscape 29/70


Connection Ports and Connection Lines
Simscape blocks have the following types of ports:
o Physical conserving ports — Nondirectional ports (for example,
hydraulic or mechanical) that represent physical connections and
relate physical variables based on the Physical Network approach.
o Physical signal ports — Unidirectional ports transferring signals
that use an internal Simscape engine for computations.

2102209 MATLAB – Simscape 30/70


Physical Conserving Ports
• Simscape blocks have special conserving ports . You connect
conserving ports with physical connection lines, distinct from normal
Simulink lines. Physical connection lines have no inherent
directionality and represent the exchange of energy flows, according
to the Physical Network approach.
• You can connect conserving ports only to other conserving ports of
the same type.
• You cannot connect physical lines to Simulink ports or to physical
signal ports.
• The physical connection lines that connect conserving ports together
are nondirectional lines that carry physical variables (Across and
Through variables) rather than signals.

2102209 MATLAB – Simscape 31/70


• Two directly connected conserving ports must have the same values
for all their Across variables (such as pressure or angular velocity).
• You can branch physical connection lines. When you do so,
components directly connected with one another continue to share
the same Across variables.
• Any Through variable (such as flow rate or torque) transferred along
the physical connection line is divided among the multiple
components connected by the branches. How the Through variable
is divided is determined by the system dynamics.
• For each Through variable, the sum of all its values flowing into a
branch point equals the sum of all its values flowing out.

2102209 MATLAB – Simscape 32/70


Physical Signal Ports
• Physical signal ports carry signals between Simscape blocks. You
connect them with regular connection lines, similar to Simulink
signal connections.
• Physical signal ports are used in Simscape block diagrams instead of
Simulink input and output ports to increase computation speed and
avoid issues with algebraic loops. Physical signals can have units
associated with them.
• Simscape Foundation library contains, among other sublibraries, a
Physical Signals block library. These blocks perform math operations
and other functions on physical signals and allow you to graphically
implement equations inside the physical network.
• Physical signal lines also have a distinct style and color in block
diagrams, similar to physical connection lines.
2102209 MATLAB – Simscape 33/70
Avoiding Numerical Simulation Issues
Certain configurations of physical modeling blocks can cause numerical
difficulties or slow down your simulation. When this happens, Simscape
solver issues a warning in the MATLAB workspace and, if it fails to
initialize, a Simscape error.
• In electrical circuits, common examples that can cause this behavior
include voltage sources connected in parallel with capacitors,
• inductors connected in series with current sources,
• Voltage sources connected in parallel, and
• current sources connected in series.
The cause of the numerical difficulty is for example that two voltage
sources in parallel must have identical voltage values; otherwise, the
ports connecting them would not be physical conserving ports. (In
practical circuits, topologies such as parallel voltage sources are possible,
2102209 MATLAB – Simscape 34/70
and small difference in their instantaneous voltages is possible due to
parasitic series resistance.)

There are two approaches to resolving these difficulties.


• The first is to change the circuit to an equivalent simpler one. In the
example of two parallel voltage sources, one source can be simply
deleted. The same applies to two series current sources, the deleted
one being replaced by a short circuit.
• The second approach is to include small parasitic resistances in the
component. In the Simscape Foundation library, the Capacitor and
Inductor blocks include such parasitic terms, so that you can connect
capacitances in parallel with voltage sources and inductors in series
with current sources. If your circuit does not have any such
topologies, then you can change the default parasitic terms to zero.

2102209 MATLAB – Simscape 35/70


Note that some blocks do not contain these parasitic terms, for
example, the Mutual Inductor.

Ex. If the capacitor C is set to have zero


series resistance, the model will run very
slowly and issues warnings about problems
with transient initialization and step size
control for transient solve.
The cause of the problems is that the circuit effectively connects the
voltage source in parallel with the capacitor. This is because an ideal op-
amp satisfies V+ = V- , where V+ and V- are the noninverting and
inverting inputs, respectively. This is an example where it is not possible
to replace the circuit with an equivalent simpler one, and a parasitic
small resistance has to be introduced.

2102209 MATLAB – Simscape 36/70


Grounding Rules
Each Domain Requires at Least One Reference Block
Within a physical network, each domain must contain at least one
reference block of the appropriate type.
For example, the
electromechanical
model shown in the
following diagram has
both Electrical
Reference and
Mechanical Rotational
Reference blocks
attached to the
appropriate circuits.
2102209 MATLAB – Simscape 37/70
Each Circuit Requires at Least One Reference Block
Each topologically distinct circuit within a domain must contain at least
one reference block. Some blocks, such as an Ideal Transformer,
interface two parts of the network but do not convey information about
signal levels relative to the reference block. In the following diagram,
there are two
separate electrical
circuits, and the
Electrical Reference
blocks are required
on both sides of the
Ideal Transformer
block.

2102209 MATLAB – Simscape 38/70


Domain-Specific Line Styles
• For improved readability of block diagrams, each
Simscape domain uses a distinct default color and
line style for the connection lines. Physical signal
lines also have a distinct style and color.
• Domain-specific line styles apply to the block icons
as well. If all the block ports belong to the same
domain, then the whole block icon assumes the line style and color
of that domain.
• If a block has multiple port types, such as the Rotational
Electromechanical Converter, then relevant parts of the block icon
assume domain-specific line styles and colors.

2102209 MATLAB – Simscape 39/70


2102209 MATLAB – Simscape 40/70
Connecting Simscape Diagrams to Simulink Sources
and Scopes
Simscape block diagrams use physical signals instead of regular Simulink
signals. Therefore, you need converter blocks to connect Simscape
diagrams to Simulink sources and scopes.

Simulink-PS Converter PS-Simulink Converter

2102209 MATLAB – Simscape 41/70


2102209 MATLAB – Simscape 42/70
2102209 MATLAB – Simscape 43/70
Solver Configuration Block
• Each physical network represented by a connected Simscape™ block
diagram requires solver settings information for simulation. The
Solver Configuration block specifies the solver parameters that your
model needs before you can begin simulation.
• Each topologically distinct Simscape block diagram requires exactly
one Solver Configuration block to be connected to it.

2102209 MATLAB – Simscape 44/70


2102209 MATLAB – Simscape 45/70
Recommended Blocks
Simscape models require certain blocks to be present in the model
configuration, such as a Solver Configuration block, or domain-specific
reference blocks. Other blocks,
such as Simulink-PS Converter
and PS-Simulink Converter
blocks are highly likely to be
needed. An easy way to start a
new Simscape model is by
typing ssc_new at the MATLAB
Command prompt, the
software creates a new model
prepopulated with certain
blocks.
2102209 MATLAB – Simscape 46/70
How Simscape Works
Model Validation
The Simscape solver first validates the model
configuration and checks your data entries from
the block dialog boxes.
• All Simscape blocks in a diagram must be
connected into one or more physical
networks.
• Each topologically distinct physical network in
a diagram requires exactly one Solver
Configuration block.

2102209 MATLAB – Simscape 47/70


Network Construction
After validating the model, the Simscape solver constructs the physical
network based on the following principles:
• Two directly connected Conserving ports have the same values for
all their Across variables (such as voltage or angular velocity).
• Any Through variable (such as current or torque) transferred along
the Physical connection line is divided among the multiple
components connected by the branches. For each Through variable,
the sum of all its values flowing into a branch point equals the sum
of all its values flowing out.

Equation Construction
Based on the network configuration, the parameter values in the block
dialog boxes, the Simscape solver constructs the system of equations for

2102209 MATLAB – Simscape 48/70


the model. These equations contain system variables of the following
types:
• Dynamic — Time derivatives of these variables appear in equations.
Dynamic, or differential, variables add dynamics to the system and
require the solver to use numerical integration to compute their values.
• Algebraic — Time derivatives of these variables do not appear in
equations. These variables appear in algebraic equations but add no
dynamics, and this typically occurs in physical systems due to
conservation laws, such as conservation of mass and energy.
The solver then performs the analysis and eliminates variables that are
not needed to solve the system of equations. After variable elimination,
the remaining variables get mapped to Simulink state vector of the
model.

Initial Conditions Computation


2102209 MATLAB – Simscape 49/70
The Simscape solver computes the initial conditions only once, at the
beginning of simulation (t = 0). The solver computes the initial conditions
by finding initial values for all the system variables that exactly satisfy all
the model equations.
The values you specify during variable initialization are not the actual
values of the respective variables, but rather their target values at the
beginning of simulation (t = 0). Depending on the results of the solve,
some of these targets may or may not be satisfied. The solver tries to
satisfy the high-priority targets first, then the low-priority ones.

Transient Initialization
After computing the initial conditions, the Simscape solver performs
transient initialization. Transient initialization fixes all dynamic variables
and solves for algebraic variables and derivatives of dynamic variables.

2102209 MATLAB – Simscape 50/70


The goal of transient initialization is to provide a consistent set of initial
conditions for the next phase, transient solve.

Transient Solve
Finally, the Simscape solver performs transient solve of the system of
equations. In transient solve, continuous differential equations are
integrated in time to compute all the variables as a function of time.
The solver continues to perform the simulation according to the results
of the transient until the end of simulation.

2102209 MATLAB – Simscape 51/70


Important Concepts in Physical Simulation
Variable-Step and Fixed-Step Solvers
• Variable-step solvers are the usual choice for design, prototyping,
and exploratory simulation. A variable-step solver automatically
adjusts its step size as it moves forward in time to adapt to how well
it controls solution error. You control the accuracy and speed of the
variable-step solution by adjusting the solver tolerance. You can also
limit the minimum and maximum time step size.
• Fixed-step solvers are required if you want to generate a code
version of your model, and to bound or fix simulation cost. With a
fixed-step solver, you specify the time step size to control the
accuracy and speed of your simulation. Fixed-step solvers do not
adapt to improve accuracy or to locate events. These limitations can
lead to significant simulation inaccuracies.
2102209 MATLAB – Simscape 52/70
Explicit and Implicit Solvers
The degree of stiffness and the presence of algebraic constraints in your
model influence the choice between an explicit or implicit solver. Explicit
and implicit solvers use different numerical methods to simulate a
system.
• If the system is a non-stiff ODE system, choose an explicit solver.
Explicit solvers require less computational effort than implicit solvers if
other simulation characteristics are fixed. To find a solution for each
time step, an explicit solver uses a formula based on the local gradient
of the ODE system.
• If the system is stiff, use an implicit solver. Though an explicit solver
may require less computational effort, for stiff problems an implicit
solver is more accurate and often essential to obtain a solution. Implicit
solvers require per-step iterations within the simulated time steps. An
implicit solver starts with the solution at the current step and iteratively
2102209 MATLAB – Simscape 53/70
solves for the solution at the next time step with an algebraic solver. An
implicit algorithm does more work per simulation step, but can take
fewer, larger steps.
• If the system contains DAEs, even if it is not stiff, use an implicit solver.
Such solvers are designed to simultaneously solve algebraic constraints
and integrate differential equations.

Making Optimal Solver Choices for Physical


Simulation
Simulating with Variable Time Step
When you first create a model, the default Simulink solver is
VariableStepAuto. Auto solver chooses a suitable solver.

2102209 MATLAB – Simscape 54/70


For Simscape models, the auto solver selection depends on the type of
the model.

2102209 MATLAB – Simscape 55/70


• For new models created in R2021a and beyond, if your model
contains Simscape blocks and Differential Algebraic Equations
(DAEs), auto solver selects daessc. For such models created prior
to R2021a, auto solver uses ode23t.
• If the system can be reduced to an ordinary differential equation
(ODE) and the model is stiff, auto solver selects ode15s.
• If the system can be reduced to an ordinary differential equation
(ODE) and the model is non-stiff, auto solver selects an explicit
solver, ode45.
Rather than relying on the auto solver selection, you can explicitly
choose a solver for your model.
The daessc variable-step Simulink solver is designed specifically for
physical modeling. Other variable-step solvers recommended for a
typical Simscape model are ode15s and ode23t. Of these two solvers:
• The ode15s solver is more stable but tends to damp out oscillations.
2102209 MATLAB – Simscape 56/70
• The ode23t solver captures oscillations better but is less stable.
With Simscape models, these solvers solve the differential and algebraic
parts of the physical model simultaneously, making the simulation more
efficient.

Troubleshooting and Improving Solver Performance


Consider the basic trade-off of speed versus accuracy and stability. A
larger time step or tolerance results in faster simulation, but also less
accurate and less stable simulation. If a system undergoes sudden or
rapid changes, larger tolerance or step size can cause major errors.
Consider tightening the tolerance or step size if your simulation:
• Is not accurate enough or looks unphysical.
• Exhibits discontinuities in state values.

2102209 MATLAB – Simscape 57/70


• Reaches the minimum step size allowed without converging,
usually a sign that one or more events or rapid changes occur
within a time step.
• Any one or all of these steps increase accuracy, but make the
simulation run more slowly.

2102209 MATLAB – Simscape 58/70


Data Logging Settings for New Model
• Using data logging is a best practice for Simscape models because it
provides access to important simulation and analysis tools.
Therefore, the ssc_new function automatically turns on data logging
for the whole model. It uses the default workspace variable name
simlog to store simulation data and limits the data to the last 10000
points to avoid slowing down simulation.

• The following example shows how to simulate systems that span


electrical and mechanical domains. You can use the motor model to

2102209 MATLAB – Simscape 59/70


assess motor performance in a given application by adding the
requisite mechanical load model.
Explore the Model
1 To open the Permanent Magnet DC Motor example model, type
ssc_dcmotor in the MATLAB Command Window.
Main Model
The model contains a DC Motor subsystem with two electrical and two
mechanical rotational ports.

2102209 MATLAB – Simscape 60/70


• For improved readability of block diagrams, each Simscape domain
uses a distinct default color and line style for the connection lines. In
this block diagram, for example, the electrical circuit is indicated by
the dark-blue color of the connection lines, while the connection
lines between the mechanical rotational ports are light-green.
Physical signal lines are brown.

• The electrical ports of the motor connect to the electrical circuit,


which consists of an Electrical Reference block, representing an
electrical ground, and a 1.5 V DC voltage source.
2102209 MATLAB – Simscape 61/70
• On the mechanical side, a Mechanical Rotational Reference block
represents a reference point for the other elements. The motor load
is represented by the block named Load Torque, which is an Ideal
Torque Source block. On one side it is connected to a Mechanical
Rotational Reference block and on the other side to the motor shaft.
The load torque is specified by the Step Input subsystem, connected
through a physical signal to the control port S of the Load Torque
block. The Step Input subsystem contains a regular Simulink Step
source, which provides the control signal. A Simulink-PS Converter

2102209 MATLAB – Simscape 62/70


block converts the control signal into a physical signal and applies it
to the control port of the Load Torque block through the Connection
Port block S.
• The diagram also contains a Solver Configuration block, which is
required in any Simscape model. It contains parameters relevant to
numerical algorithms for Simscape simulations.

2102209 MATLAB – Simscape 63/70


2 Double-click the DC Motor subsystem to open it.

DC Motor Subsystem
The motor consists of an electrical circuit and a mechanical rotational
circuit, connected by the Rotational Electromechanical Converter block.
The electrical circuit consists of a Resistor block and an Inductor block.
It contains two electrical ports, corresponding to the V+ and V- electric
2102209 MATLAB – Simscape 64/70
terminals of the motor. The mechanical circuit contains a Rotational
Friction block, an Inertia block, and two mechanical rotational ports, C
and R, corresponding to the motor case and rotor, respectively. Notice
how the C and R ports of the Rotational Friction block and the Rotational
Electromechanical Converter block are connected to the C and R ports
of the motor, to preserve the correct direction of variables in the
physical network.
Run the Model
1. Set the Configuration Parameters in Model Settings to log the
simulation results.

2102209 MATLAB – Simscape 65/70


2. Double-click the Motor RPM scope to open it. During simulation,
this window displays the shaft speed as a function of time.
3. Click to start the simulation. The Simscape solver evaluates the
model, calculates the initial conditions, and runs the simulation. This
2102209 MATLAB – Simscape 66/70
process might take a few seconds. The message in the bottom-left
corner of the model window provides the status.
4. Examine the simulation results in the Motor RPM scope window.

5. Explore the same results in Simscape Results Explorer window.

2102209 MATLAB – Simscape 67/70


2102209 MATLAB – Simscape 68/70
2102209 MATLAB – Simscape 69/70
2102209 MATLAB – Simscape 70/70

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy