20 Sim 41 Reference Manual
20 Sim 41 Reference Manual
Windows® Vista / XP
20-sim 4.1 Reference Manual
© 2009, Controllab Products B.V.
Author: Ir. C. Kleijn
Disclaimer
Controllab Products B.V. makes every effort to insure this information is accurate and reliable.
Controllab Products B.V. will not accept any responsibility for damage that may arise from using this
manual or information, either correct or incorrect, contained in this manual.
Information in this document is subject to change without notice. No part of this document may be
reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose,
without the express written permission of Controllab Products B.V.
Reference
Kleijn, C.
20-sim 4.1 Reference Manual
Enschede, Controllab Products B.V., 2009
ISBN 978-90-79499-05-2
Information
2 EDITOR 7
2.1 Introduction 7
2.2 Using Models 17
2.3 Compiling 36
2.4 Icon Editor 46
2.5 Interface Editor 48
2.6 Domains, Quantities and Units 52
3 SIMULATOR 59
3.1 Introduction 59
3.2 Running a Simulation 62
3.3 Run Properties 79
4 LANGUAGE REFERENCE 89
4.1 Introduction 89
4.2 Keywords 98
4.3 Types 106
4.4 Functions 109
4.5 Operators 151
4.6 Statements 163
4.7 Matrices and Vectors 179
4.8 181
4.9 Advanced Topics 182
iii
20-sim 4.0 Reference Manual
iv
Table Of Contents
Index 367
v
1 Installing
1.1 Versions and Licenses of 20-sim
20-sim is available in three versions: Viewer, Standard and Professional.
Viewer/Demonstration version: This is a freeware version that allows you to load and
run models and evaluate the package. Saving of models is not possible in this version.
Standard: This is the standard version of 20-sim. It has no limitations but only includes the
Frequency Domain Toolbox.
Professional: This is the full version of 20-sim with all toolboxes.
The table below shows in detail the options that are available in the three versions:
Library Models
v* v v
3D Mechanics Toolbox x v
v*
Animation Toolbox x v
v*
Control Toolbox x v
v*
Mechatronics Toolbox x v
v*
v = included
v* = included but no saving possible
x = not included
20-sim is installed, using an Installation Manager that will lock 20-sim to your computer. There are
three types of licenses available:
Free License: The demonstration version comes with a license that is not locked to your
computer. No actions have to be taken after installation of the program.
Single License: A single license locks 20-sim to a specific computer. After installation you
have to register to get a valid license.
Floating License: A floating license allows multiple users to work with 20-sim at the same
time. After installation you have to register to get a valid license.
1
20-sim 4.0 Reference Manual
1. Install 20-sim and start the program. If you do not have an installation version of the
program download it from the 20-sim website: www.20sim.com.
2
1. Installing
4. Select the license that you would like to receive (test or individual).
5. Copy the text to a text editor, fill in the missing data and send it by e-mail to
[email protected].
Within two working days, you will receive an e-mail message back with a license file that is unique
for your computer.
6. Overwrite the old license file (click the Locate License File button to find out where) with
the new one.
If you have purchased multiple licenses, perform step 1 to 5 for every computer on which 20-sim
should be installed.
3
20-sim 4.0 Reference Manual
1. Install 20-sim on a workstation and start the program. If you do not have an installation
version of the program download it from the 20-sim website: www.20sim.com.
Now the location where your license file has been stored is shown. By default this will be in the
C:\Program Files\20-sim 4.0\bin folder.
4. Copy the license file (20sim.lic) to a location that is open to all users, preferably on a server.
6. Change the location of the license file so that it points to the new location (i.e. on the server).
4
1. Installing
9. Copy the text to a text editor, fill in the missing data and send it by e-mail to
[email protected].
Within two working days, you will receive an e-mail message back with a license file that is unique
for your computer.
10. Overwrite the old license file (on the server) with the new one.
11. Make sure that this file is open for every user: Every user in the network should have read
and write permission for this license file.
For other workstations, the procedure is easy: Install 20-sim and use the Locate License File
button, to point to the shared license file (server).
5
20-sim 4.0 Reference Manual
6
2 Editor
2.1 Introduction
Editor
20-sim consists of two main windows and many tools. The first window is the Editor and the second
is the Simulator. The Editor is used to enter and edit models. The Editor opens automatically when
you start 20-sim:
7
20-sim 4.0 Reference Manual
Modeling
A modeling and simulation session in 20-sim can be visualized by the diagram shown below.
Creating a Model
A modeling session start by creating a model. Modeling in 20-sim can be performed using Equations,
Block Diagrams, Bond Graphs, Iconic Diagrams or a combination of these representations.
Compiling/Debugging
After the model has been successfully entered, it must be checked and compiled to generate
simulation code. This is done in 20-sim automatically when you open the Simulator or when you
check a model. In some cases the model contains errors which have to be solved by adapting the
model. Errors in 20-sim are presented in the Process tab at the bottom of the Editor.
8
2. Editor
1. Modes: 20-sim can operate in two modes: Debug Mode and Fast Mode. This is indicated by
the Mode button at the complete right in the toolbar which can either show for Debug
Mode or for Fast Mode. You can quickly change between these modes by clicking on the
Mode Button. In Debug Mode all possible checks will to performed and warnings will be
generated for possible model errors. Always start modeling in Debug mode!
2. Implementation: 20-sim supports modeling with Equations, Block Diagrams, Bond Graphs and
Iconic Diagrams. You can enter these models in the Graphical Editor or Equation Editor.
3. Hierarchy: To keep your models simple, you can group parts of the model together as a
submodel. The hierarchy of submodels is always shown in Model Browser.
4. Library: To create a graphical model, you may drag and drop predefined submodels from the
library. The library is shown in the Library tab.
5. Icon: Every model has its own drawing or icon. Icons are displayed and can be edited in the
Icon Editor.
6. Interface: Every model has an interface defining its ports and parameters. This interface is
displayed and can be edited in the Interface Editor.
7. Compiling: After our model is saved on file, we can let 20-sim check it to see if it is correct
and compile it. Checking and Compiling is done automatically when you open the Simulator.
8. Simulation: In the Simulator you can set options like start time, finish time, integration
method, plot variables etc. After that simulation can start and the results are shown in a plot.
9
20-sim 4.0 Reference Manual
Equation Editor
If you have opened an equation model, the right part of the Editor shows the Equation Editor. In the
Equation Editor you can enter and edit equation models.
Use
Put your mouse in the Equation Editor and start typing. If you click on the buttons of the taskbar,
sample code is inserted.
10
2. Editor
Graphical Editor
If you have opened a graphical model, the right part of the Editor shows the Graphical Editor. In the
Graphical Editor you can enter and edit block diagram models, iconic diagram models and bond
graphs.
Use
Select models from the Model Library and drag them to the Graphical Editor. You can us the buttons
of the taskbar, to connect the models and change their position.
11
20-sim 4.0 Reference Manual
Insert Terminals: (Icon Editor only) Click this button to insert terminals.
Connection Mode: (Graphical Editor only) Click this button create connections between
models.
Line: Click this button to draw lines.
Fill Color: click this button to set the fill color of a selected object.
Rotate and Mirror: click this button to rotate or mirror a selected object.
Arrange and Group: click this button to group objects, put them to the front etc.
Line Styles: click this button to select the line style of selected objects.
Zoom: click this button to select the zoom factor.
12
2. Editor
Editing
In the Graphical Editor and the Icon Editor you can edit objects (i.e. models, drawing objects, text)
as you would in any other drawing tool.
1. Select: Click the selection mode button of the taskbar. Then put the mouse pointer on top of
an object and click the left mouse button to select an object. After an object is selected you
can click the right mouse button to show the right mouse menu. This menu allows you to
show the properties of the selected object and other specific commands.
2. Move: Select the object you want to move and drag it to the desired position using the mouse
or keyboard arrows.
3. Fine Movement: Keep the Shift key pressed while using the keyboard arrows to move objects.
4. Copy, Cut, Paste, Delete and Duplicate: Use the Edit menu to copy, cut, paste, delete and
duplicate objects.
5. Group and Ungroup: Use the Drawing menu or the taskbar to group and ungroup objects.
6. Rotate and Mirror: Use the Drawing menu or the taskbar to group and ungroup objects.
7. To Front and To Back: Use the Drawing menu or the taskbar to put objects to the front or to
the back.
8. Center to Grid and Top Left to Grid: Use the Drawing menu to set an object with its center on
the grid or with its top left corner on the grid.
1. Line: Use the taskbar to draw straight lines. Two modes of drawing are supported:
Click the left mouse button and keep it pressed while dragging. If you release the
mouse button the lines is ready.
Click the left mouse button and start dragging. Every time you click the left mouse
again, an intermediate point is inserted. Finish the line by clicking the right mouse
button.
2. Spline: Use the taskbar to draw curved lines. One mode of drawing is supported:
Click the left mouse button and start dragging. Every time you click the left mouse
again, an intermediate point is inserted. Finish the spline by clicking the right
mouse button.
13
20-sim 4.0 Reference Manual
3. Rectangles and Ellipses: Use the taskbar to insert rectangles and ellipses.
4. Text: Use the taskbar to insert text. A text editor will open to enter the text. If you select
text, you can open the text editor by selecting Properties from the right mouse menu.
5. Bitmap: Use the taskbar to insert a bitmap. A file browser will open, allowing you to give the
location of the bitmap. If you select the bitmap, you can open the file browser by selecting
Properties from the right mouse menu.
6. Line Color and Fill Color: Use the taskbar to change the line color or fill color of an object.
7. Line Style: Use the taskbar to change the line style of an object.
Library
In 20-sim, creating models only takes you just a few mouse clicks. By dragging an element from the
library and dropping it in the graphical editor, your model is actually built the same way as you would
draw an engineering scheme. 20-sim supports various model representations, such as block
diagrams and iconic diagrams. These representations may be combined in one model.
Bond Graph
Se, Sf, MSe, MSf, ...
I, C, R, ...
TF, GY, MTF, MGY, ...
1, 0, ..
Iconic diagrams (Physical Components)
Electric
Various voltage and current sources
Inductors, resistors, capacitors, etc.
Diodes, op-amps and rectifiers
Hydraulic
Orifices and laminar resistances
Cylinders, accumulators, tanks
Pumps and motors
Valves
Flow, power and pressure sensors
Thermal
Heat capacity and heat flow
Convection and radiation elements
Sensors
Heat generators
Mechanical
Inertia's, springs, dampers, etc.
Bearings, backlash and clutch models
Advanced frictions models (LuGre, Dahl, KFM)
Belts, spindles, gears and differentials
Various types of sensors and encoders
All elements in the mechanical library are defined for the rotational as well as the translational
domain. Furthermore, there is a special library for 2D and 3D bodies with small rotations
14
2. Editor
15
20-sim 4.0 Reference Manual
Find
If you make the Editor wide enough, you will see at the top right a Find box. You can enter terms
here and search them throughout the model. The results are displayed in the Find tab at the bottom
of the Editor.
Scope: The search scope depends on which level of the model you are in. Only the current
submodel and all submodels below are searched. Select the top element in the Model
Browser (Model tab at the left of the Editor) to search the whole model.
Jump: The Find tab shows the found items with an orange hyperlink. Click on the hyperlink
to quickly jump to the corresponding model.
Find again (F3): Click the F3 button to quickly jump through the found items in the Find
tab.
Menu: You can also start a search from the menu: from the Edit menu select Find.
16
2. Editor
20-sim supports hierarchic model. The lowest model in the hierarchy is always an equation model.
You can inspect this in the Editor. If you click the Model tab at the left of the Editor, the Model
Browser shows complete model hierarchy: a tree like structure showing all the submodels that are
used in the model.
17
20-sim 4.0 Reference Manual
The Model Browser at the left of the Editor shows the complete model hierarchy.
To travel through the hierarchy, click any model in the tree. You can also select a model in the
Open Models
Models in 20-sim 4.0 are stored with the extension .emx. You can open an existing model in several
ways:
2. Click the Library tab and from the Library drag and drop your model to the Graphical
Editor.
3. Open a Windows Explorer. Drag and drop your model to the Graphical Editor.
You can open Packed Files with the Open dialog by selecting a file with the extension .emx.
18
2. Editor
Save Models
Models in 20-sim 4.0 are stored with the extension .emx. You can save an existing model in several
ways.
1. From the File menu, select Save: This will save the complete model. If no filename is known
a Save dialog is opened.
2. From the File menu, select Save As: This is essentially the same as the Save command but
now the Save dialog is opened even if a filename is known.
3. From the File menu, select Save Submodel: This will save the submodel that is selected in
your Editor.
4. From the File menu, select Save Encrypted: This will allow you to store a model using
encryption. If a submodel was selected, a menu is opened asking you to store the submodel
or the complete model.
Once a model is encrypted, you can not decrypt it anymore! So keep cautious that you always store
a non-encrypted original. Encrypted models are useful if you want others to use your 20-sim model,
without seeing the underlying equations. If encrypted model is load in 20-sim, the Go Down
command will does not work on that model.
Packed Files
To get a simulation running in 20-sim, the data stored in various files may be needed:
5. etc.
You can pack all these files into one zip-file, using the Pack command from the File menu. With this
command 20-sim will check all the files that are used and store them into a single zip-file. This
option is useful for archiving and sending models by e-mail.
Pack
1. When the Pack command is clicked, a Save As dialog appears asking you to enter a name.
Always save with the default extension .emxz because 20-sim uses this extension to recognize
packed files.
After the Save As dialog, a 20-sim Pack dialog appears, showing the collected files. In this dialog you
can select the files that should be packed.
2. Select the files that should be packed and click the OK button.
19
20-sim 4.0 Reference Manual
Unpack
You can open Packed Files using the Unpack command from the File menu.
1. When the Unpack command is clicked, an Open dialog appears asking you open a file. Open a
file with the extension .emxz because 20-sim uses this extension to recognize packed files.
After the Open dialog, a 20-sim Unpack dialog appears. In this dialog you can see the file that you
have selected to unpack and you can choose the method of unpacking.
2. If you want to unpack all files and put them in their original location, select the option
Unpack with full path.
3. If you want to unpack all files and to a specific directory, select the option Unpack to
directory.
4. Select Keep Relative Paths if you want to keep the original folder structure.
2. Select the submodel that you want to insert and drag and drop it in the Graphical Editor.
1. From the File menu, select Open Browser. The File Explorer appears.
2. Select the submodel of interest and drag and drop it in the Graphical Editor.
Connect Submodels
In 20-sim, submodels can be connected using the mouse. When a connection is created it will be
displayed using straight lines. When a connection has been made you can change it into a smooth
line using the right mouse menu. You can change the color of a connection using the colorbar at the
bottom of the Editor.
Straight Line
20-sim supports two types of mouse use. "Tapping Mode" and "Pressing Mode". In the Tapping Mode
you click the mouse button (do not keep it pressed but quickly "tap" the button) while making a
connection. In the Pressing Mode you keep the mouse button pressed while making a connection.
20
2. Editor
Tapping Mode
To connect two submodels using straight lines, you have to:
2. Put the mouse pointer on top of the first submodel and click the left mouse button (do not
keep it pressed but quickly "tap" the button).
3. Drag the mouse pointer towards the second submodel (you will see a connection drawn from
the first submodel towards the mouse pointer).
4. Put the mouse pointer on top of the second submodel and click the left mouse button again
(do not keep it pressed but quickly "tap" the button).
5. While dragging from the first submodel to the second, you can click the left mouse button (do
not keep it pressed but quickly "tap" the button) to create intermediate points.
Pressing Mode
To connect two submodels using straight lines, you have to:
You can toggle between connection mode and selection mode by pressing the space
bar.
21
20-sim 4.0 Reference Manual
Implode / Explode
Using the Implode command of the Editor menu you can quickly create a new submodel out of a
set of select submodels.
Using the Explode command of the Editor menu you can quickly open the contents of a selected
submodel in the current model layer.
2. Select a submodel.
Simplify Model
Use the Simplify Model command to simplify graphical models according to the following rules:
Block Diagrams
1. Combining splitters.
Bond Graphs
1. Eliminating junctions.
Iconic Diagrams
1. Eliminating nodes.
1. From the Model menu select the Check Complete Model command. Now the complete
model will be checked.
If any warnings or errors are found, they are displayed in the Process tab of the Editor.
22
2. Editor
20-sim will jump to the part where the error was caused. You can try to solve the error and check
again.
Model Properties
The properties of 20-sim models are shown in the Model Properties dialog. You can open the Model
Properties in various ways.
1. Select the proper model in the Model Browser and then click Properties from the Right
Mouse menu.
2. Select the model in the Graphical Editor and then click Properties from the Right Mouse
menu.
23
20-sim 4.0 Reference Manual
Submodel Properties
Depending if a submodel was selected or a main model, various tabs are visible:
Description
In this tab you can enter the name of the submodel and enter various fields to classify a model.
Description
Title
Keywords
Author
Manager
Project
Company
Department
Help Page
Library
In this tab you can find information on model file.
Filename: The location of the model file.
Version: The version of 20-sim that was used to create the model.
Library Path: You can define libraries in the General Properties.
Library File: The relative location of the submodel in the library
Created: The date of creation.
Main Model / Submodel: Shows if the model is a main model or submodel.
24
2. Editor
Allow model updates: Allow the Check for Model Updates command to check if there is an
update available for this model.
Replace parameters when this model is used to update another model: If you drag and drop
a model from the library on top of an existing model, it will be replaced. Select this option if
you want the original parameters to be replaced as well.
The description tab contains various fields that you can fill in text to classify a model.
Processing
This tab is only available for main models. 20-sim can operate in two modes: Debug Mode and Fast
Mode. In this tab you can define settings for both modes.
Warnings/Errors
Model contains algebraic variables: See the section on algebraic loops.
Model contains algebraic loops: See the section on algebraic loops.
Algebraic variables solved: See the section on algebraic loops.
Model contains constraint variables: See the section on constraints.
Constraint variables solved: See the section on constraints.
Model contains dependent states: The model contains differential equations which could not
be solved.
Dependent states are transformed: The model contains differential equations which were
solved.
Output is not used: Output signals that are not used for connections to other models.
Input is not used: Input signals that are not used for connections to other models (to make
such models simulate, a zero input value is applied to all not-connected inputs)
Port is not used: Ports that are not connected.
Parameter is not used: Parameters that are defined but not used.
Matrix is assigned a scalar: A matrix is assigned to a scalar.
Variable is not used: Variables that are defined but not used.
Variable Multiple set: Variables that are assigned a value more than once.
Variable is never given a value: Variables that are never assigned a value.
Variable is set but not used: The variable is assigned a value but never used.
Unit Conversion when SI disabled: Not relevant yet.
Unit Conversion when SI enabled: A unit conversion was found.
Unit missing for variable when SI disabled: Not relevant yet.
Quantities Mismatch: Variables with different quantities are compared.
Unit is unknown: A unit has been used that is not available in the Quantities and Units file.
Equations interpreted as code: Equations can only be valid when interpreted as sequential
code. For example when variables are assigned more then once.
Possible loss of data at type conversion: A type conversion has been found that may lead to
loss of precision digits.
Type conversion found: A type conversion has been found.
Conversion of booleans found: A type conversions involving booleans has been found.
25
20-sim 4.0 Reference Manual
Model optimization
Transform Dependents States: Try to solve differential equations.
Solve algebraic variables: Try to analytically solve algebraic loops.
Remove Redundant Equations: Try to remove equations that do not influence model
behavior.
Optimize Equation Structure: Try to separate equations into an input section, a dynamic
section and an output section.
Optimize Static Expressions: Move expressions with constant output throughout the
simulation to the static part of the model equations.
Optimize Duplicate Expressions: Calculate and expression only once and use the result
everywhere.
Optimize Divisions: Rewrite divisions as multiplications whenever possible.
Simulator
This tab is only available for main models.
Initialize variables at start of simulation: You can choose to set any variable that was not
given a proper value, to zero at the start of a simulation. You can also choose to set the
value to NaN to make detection more easy.
General Properties
The general properties of 20-sim models are shown in the General Properties dialog.
Editor
Fonts: Enter the default fonts used in graphical models (Editor) and equation models
(Equation Editor).
Syntax Highlighting Threshold: Select the number of characters that should be submitted for
color sytax highlighting. If this number is too large, the editor may become very slow.
Plots
You can choose the default settings for a simulation plot in this tab.
Default Line Thickness: Enter the default plot line thickness.
Folders
You can choose the location of libraries and files in the Folders tab.
Library Folders: Enter the library paths and corresponding library names here. The libraries
are shown in the Library tab.
C-code Folders: C-code can be generated for various targets. For each target a file
targets.ini defines how the C-code should be generated. You can enter the locations of ini-
files here.
Matlab-Code folders: 20-sim models can be exported to Matlab. Similar to C-code
generation, a file targets.ini defines how the code should be generated. You can enter the
locations of ini-files here.
Model Template Folders: You can enter the location of model templates.
26
2. Editor
1. Double click the error message, to jump to the submodel where the error was found and click
OK to close the message window.
This command is the same as Check Complete Model command but will generate extra variables:
Sumodelname\port.power: the net power flow of the port.
Sumodelname\summated_port_power: the net power flow into the model.
Sumodelname\summated_port_energy: the net energy of the model.
You can inspect these variables during simulation in the Variable Chooser.
Analyze Causality
Causal analysis is the procedure to get the model equations correct form. For Bond Graph models
this means that the direction of the efforts and flows of the bonds have to be determined. The result
of the analysis is displayed by causal strokes (denoted by |). For Iconic Diagrams this means that
the direction of the across and through variables of the connections have to be determined. The
result of the analysis is displayed by causal arrows (denoted by -> ).
27
20-sim 4.0 Reference Manual
1. From the Model menu select the Analyze Causality command. Now causality will be
assigned in the complete model.
Bond Graphs
Causal strokes are shown in Bond Graphs automatically.
Setting Causality can also be done by hand. Just select a bond and choose Properties from
the right mouse menu. A menu pops up in which you can set causality by hand. The
corresponding causal stroke is displayed in green (denoted by |).
If 20-sim fails to perform a causal analysis of the model (a causal conflict), the
corresponding bond is displayed red.
Some submodels have a preferred causality. If assignment of the preferred causality is not
possible (because of other constraints), the corresponding causal stroke is displayed in
orange (denoted by |).
To see the order in which automatic causality assignment has been performed, choose
Causality Info from the View menu.
Iconic Diagrams
Causality in Iconic Diagrams is only shown when you select the Causality Info command of
the View Menu.
28
2. Editor
If 20-sim fails to perform a causal analysis of the model (a causal conflict), the
corresponding connection is displayed red.
Implementations
A model may have implementations. It means that you can combine several versions or
implementations of a model and store them in one file. If you drag and drop a model with
implementations, 20-sim will ask which one to use.
Example
A fine example of a model with various implementations is the model SignalGenerator-Sweep.emx
from the Signal\Sources library. The model is a combination of three submodels:
Default: The standard sweep
Exponential: A sweep with exponential distribution of the frequencies
ZeroMean: A zweep with a zero mean.
When you drag and drop this model to the Graphical Editor you will be asked which implementation
to use. In the Model Browser, the chosen implementation is shown between brackets (Logarithmic
and ZeroMean in the picture above). If you hover the mouse above a sweep model, you also see the
chosen implementation between brackets. During simulation, you may decide to change the
implementation. This can easily be done by selecting this model and clicking the right mouse menu.
Choose Implementation and select the implementation that you want to use.
29
20-sim 4.0 Reference Manual
Use
You can easily change the chosen implementation:
2. From the right mouse menu choose Edit Implementation and select another
implementation.
Construction
You can easily make submodels with various implementations yourself:
2. From the right mouse menu choose Edit Implementation and Add New.
4. Store the submodel using the Save Submodel command of the File menu.
The advantage of multidimensional models is shown in the example below. On top two submodels
are connected by three (single) signals. The same submodels are also shown below, connected by
one multi-dimensional signal of size [3,1]. If these submodels have to be used a lot, multi-
dimensional signals or multi-signals, are easier to use. Multi-dimensional signals, bonds and
connections are shown in 20-sim by double lines.
30
2. Editor
2. If both ports have size one, a single signal, bond or connection will be drawn.
3. If both ports have a size larger then one, a multi-signal, multi-bond or multi-connection will
be drawn.
31
20-sim 4.0 Reference Manual
Use the matrix and vector notation to define the model equations.
Exporting Models
There are several methods to export 20-sim models:
3. Export to Clipboard.
4. Export to File.
5. Export to HTML.
6. Export to Bitmap.
32
2. Editor
33
20-sim 4.0 Reference Manual
You can choose to export a complete model or a submodel. In both cases, three m-files are
generated.
1. ModelName.m: A file containing the model equations and special 20-sim functions. The model
equations are directly translated from the equations that are shown with the Show Equations
command of the Model menu.
2. ModelName_run.m: An example file showing you how to run a simulation with the exported
model in 20-sim.
3. ModelName_print.m: This file contains a function that is used in the run file.
Simulink does not support powerports. Therefore the powertports in a 20-sim model are translated to
input and output ports. In the picture below, you see the result of an export of the 20-sim submodel
Scara (from the model ScaraRobot.emx) to Simulink.
To export 20-sim models to Simulink with an m-file description, from the Editor select the File menu
and then click Export to Matlab/Simulink command. This will open a Matlab-Code Generation dialog.
You can choose to export a complete model or a submodel. In both cases, two files are generated:
34
2. Editor
1. ModelName_.mdl: The exported 20-sim model based on a m-file that describes the model.
2. ModelName.m: An m-file that contains the model equations and special 20-sim functions. The
model equations are directly translated from the equations that are shown with the Show
Equations command of the Model menu.
If you select the OK button, ANSI C-Code will be generated and compiled into a dll-function. Some
files will be generated of which two are needed in Simulink:
1. ModelName_.mdl: The exported 20-sim model based on a dll-file that describes the model.
2. ModelName.dll: A dll-file that contains the model equations and special 20-sim functions. The
model equations are directly translated from the equations that are shown with the Show
Equations command of the Model menu.
35
20-sim 4.0 Reference Manual
2.3 Compiling
Compiling Models
When you enter a model and open the Simulator or when you select the Check Complete Model
command of the Model menu, the model will be compiled. During compilation, 20-sim will perform a
number of tasks.
Error Checking
1. Type checking: 20-sim will search for illegal type conversion and possible loss of data.
2. Unit Checking: Many models in 20-sim use units and quantities. 20-sim will check for a proper
use of these units and quantities.
Optimizing Model Structure
4. Solving Algebraic Loops: Algebraic loops are solved to their analytical solution, where possible.
5. Optimizing Equation Structure: Some equations have to be calculated only once during each
simulation step, because they do not influence the model dynamics. Depending on their
relation to the model dynamics (needed for or a result of) these equations are calculated
before the model dynamics (input equations) or after the model dynamics (output equations)
6. Remove redundant equations: A lot of model equations are just assignments like var1 = var2,
where one variable is already known. 20-sim reduces these equations from the model and
maps the unknown variables to known variables.
After these tasks a complete equation model is created, which can be inspected using the Show
Equations command of the Model menu. After the complete equation model has been created the
following tasks are applied:
Compiling
1. Find the correct order of execution: All equations will split up into their most simple form and
rewritten into the correct order of execution.
2. Interpreter Code: Create interpreter like code out of the equations. This is low level code that
can be understood by the simulation algorithms.
3. Machine Code: When you have the Built-In compiler option selected, the interpreter code is
compiled into into platform specific 32-bit machine code. This code uses the full power of
native Pentium and 486 instructions. The result is a dramatic increase of simulation speed:
100% to 400 %, depending on the kind of model used!
Simulation Code
The resulting code, either interpreter code or machine code, is used in the Simulator to perform
simulation runs with and therefore also know as simulation code. As we have learned, the simulation
code can be quite different from the original model equations. To denote the function of each original
model variable in the simulation code, 20-sim uses the following names:
independent rate
independent state
36
2. Editor
dependent rate
dependent state
algebraic loop in
algebraic loop out
interesting variable
hidden variable
Causal Form
Equations within 20-sim may be entered in random form. During compilation, 20-sim will
automatically try to rewrite equations into a causal form and set them in a correct order. I.e. a form
where all output variables are written as function of input variables. Consider for example the
following model:
variables
real u,z;
equations
u = sin(time);
u = cos(z);
Here the (input) variable u is given by the equation u = sin(time). Consequently the (output)
variable z should be written as a function of u. This is exactly what 20-sim will try to do while
compiling the model into simulation code. I.e. the function cos will be inverted and the model will be
rewritten to:
variables
real u,z;
equations
u = sin(time);
z = arccos(u);
Some functions cannot be inverted. Consequently not all equations can be rewritten. 20-sim will
report this to the user, during model checking.
Indifferent Causality
For some models the causal form is not known beforehand. For example the iconic diagram model
that describes a damper can be written as:
parameters
real d;
equations
p.F = d*p.v;
Here p.F denotes the force and p.v denotes the velocity of the powerport p. There is no preferred
input (force or velocity). This can be explicitly stated, by giving the powerport p an indifferent
causality. During compilation 20-sim will determine whether p.F or p.v is the input variable and
consequently rewrite the equations.
37
20-sim 4.0 Reference Manual
Preferred Causality
For some models there is a preferred causal form. For example the iconic diagram model that
describes a spring can be written as:
parameters
real k;
equations
p.F = (1/k)*int(p.v);
Here p.F denotes the force and p.v denotes the velocity of the powerport p. The equation is written in
integral form which is preferred. Consequently the preferred input is the velocity. Should the force be
the input, the equation must be rewritten to a differential form, which is leads to less efficient
simulation. This can be explicitly stated, by giving the powerport p an preferred causality. During
compilation 20-sim will try to keep the model in this preferred form. If this is not possible the
equations will be rewritten to the less preferred form.
Fixed Causality
For some models there is only one causal form. For example a simple iconic diagram model that
describes coulomb friction can be written as:
parameters
real Rc;
equations
p.F = Rc*abs(p.v);
Here p.F denotes the force and p.f denotes the velocity of the powerport p. The equation is cannot be
rewritten to a form where p.F is the input. This can be explicitly stated, by giving the powerport p an
fixed causality. During compilation 20-sim will try to keep the model in this fixed form. If this is not
possible an error message will be generated.
Setting Causality
For some models, the equations are too complex to analyze causality. To help 20-sim, using the right
causality, you can set causality for every port in the Interface Editor.
Integral Form
Consider the following first order linear model:
38
2. Editor
or
This is the same equation as the previous model! Apparently, both models are the same! Both
models can therefore be described by the dynamic equations:
We call the first equation the differential form (no integrals). The second equation is called the
integral form (no derivatives). In 20-sim models can be entered in integral form as well as the
differential form.
Solving Differential Equations
During compilation, 20-sim will automatically try to rewrite equations into the integral form, since
this leads to more efficient simulation. Sometimes an integral form cannot be found. Then algorithms
will be applied to solve the differential directly. For example an equation like:
output = ddt(sin(a*time))
will be replaced by the following equation (applying the chain rule and using the known derivative for
the sine function):
output = a*cos(a*time)
Sometimes a differential cannot be solved directly. Then only the Backward-Differentiation Methods
can be used for simulation.
39
20-sim 4.0 Reference Manual
Simulation Code
After compilation simulation code is generated. The equation in integral form:
and can be handled by all integration methods. The equation in differential form:
Algebraic loops
An algebraic loop in a model is a loop consisting of elements without "memory like" functions. To
calculate the variables in this loop, the variable values themselves are needed. Consider the following
example of an algebraic loop in an amplifier with negative feedback:
x = K*(u-x)
The variable x depends on its own value and must be solved by iteration. In 20-sim every
simulation algorithm is accompanied by an iteration routine.
Fortunately 20-sim is able to solve many algebraic loops at equation level. For this model this leads
to the analytic solution the system:
x = K*u/(1+K)
The best solution for these problems is to have a critical look at the model and change the order of
calculations in a model. Possible solutions are:
40
2. Editor
1. Algebraic Loops occur when the order of calculations is arbitrary. When an algebraic loop
occurs in an equation model or in a set of equation models, you may change the order of
calculation by rewriting the equations. The calculation order in bond graph models can be
changed by introducing hand-defined causality.
2. Introduce ‘parasitic’ energy storage elements (e.g. a small mass, a small capacitor etc.) to
break an algebraic loop. These elements introduce however, large poles in the state
equations, which might increase the simulation time considerably.
3. Delete elements in the algebraic loop which are not relevant for the model’s simulation output
(e.g. small dampers, very stiff springs etc.). Care should however be taken, since correct
deletions are not always possible and require considerable modelling skill and intuition.
4. Combine dual elements. Sometimes elements of the same type can be combined by adding
the parameter values (e.g. combining a mass m1 and a mass m2 to a mass m1 + m2). This
will in most cases decrease the amount of algebraic loops.
Order of Execution
Equations within 20-sim may be entered in random form. During compilation, 20-sim will
automatically try to rewrite equations into a correct order of execution. I.e. a form where all output
variables are written as function of input variables and output variables of previous lines. Consider
for example the following equations:
variables
real u,z;
equations
z = sin(u);
u = cos(time);
Here the (input) variable z is given as a function of u. Consequently u should be calculated first. This
is exactly what 20-sim will try to do while compiling the model into simulation code. I.e. the
equations will be executed as:
u = cos(time);
z = sin(u);
Code Blocks
Equations in a code block are not reordered. A code block is a set of equations inside a statement.
Suppose we have the following equations:
if condition then
code block 1
...
...
else
code block 2
...
...
end;
41
20-sim 4.0 Reference Manual
To prevent incorrect executions of the if-statement, the equations of the code blocks will not be
separated. Inside a code-block, equations can are not rewritten into an new order of execution. E.g.
the following equations:
Will be not be reordered and therefore not correctly executed! To get correct code, enter code
blocks in a correct order, e.g.:
parameters
real y = 8;
variables
real x1, x2, x3;
code
x1 = time;
x2 = sin(time);
x3 = y*x1;
Integration Steps
Some integration algorithms do more calculations before generating the next output value. These
calculations are called minor steps, the output generation is called a major step. During a minor step,
all model equations are executed. In most cases you will not notice this because only the results of
the major step are shown in the simulator. There are however, exceptions. The next topic will discuss
this in more detail.
42
2. Editor
Integration Steps
Some integration algorithms do more calculations before generating the next output value. These
calculations are called minor steps, the output generation is called a major step.
Euler 0
Adams-Bashford 2 0
Runge Kutta 2 1
Runge-Kutta 4 3
Runge-Kutta-Fehlberg variable
Execution of Equations
During a minor step, all model equations are executed. In most cases you will not notice this because
only the results of the major step are shown in the simulator. There is one exception. If you use
equations like
variables
real y;
initialequations
y = 0;
equations
y = y + 1;
you will find that the value of y depends on the integration method that is used. The reason is
obvious once your realize that the equations are executed during minor steps. If you use a Runge
Kutta 2 integration method, there is one minor step during which y is increased and one major step
during which y is increased again!
43
20-sim 4.0 Reference Manual
Major
To prevent an equation from being calculated during minor steps, you can us the predefined variable
major. This variable will return the boolean false when calculations are performed for a minor step
and will return true when calculations are performed during a major step.
Example:
parameters
real initial = 0.0;
variables
real prev, peak;
initialequations
peak = initial;
prev = 0;
output = initial;
code
if major then
peak = max([abs(input), peak]);
if (input > 0 and prev < 0) or (input < 0 and prev > 0) then
output = peak;
peak = 0;
end;
prev = input;
end;
Note that the initial values are set in the initialequations section, because we do no want the
variables to be set to zero at every integration step. Instead of an equations section, a code section
is used to prevent 20-sim from rewriting the equations in a different order.
Show Equations
During processing a complete set of equations is generated of each model. To inspect these
equations or copy them for use in other programs, you have to:
1. If the model was not checked before, from the Model menu select the Check Complete
Model command.
2. From the Model menu select the Show Equations command. Now a window is popped up
showing all the model equations.
44
2. Editor
3. You can copy the equations by selecting select all and copy from the right mouse menu.
45
20-sim 4.0 Reference Manual
The 20-sim Icon Editor can be used to create custom made model icons.
Open
1. In the Editor select the model that you want to give a new appearance.
4. or at the bottom right of the Editor click the Icon tab and in the Icon tab double click.
Use
1. Use the taskbar buttons or the menu commands to insert objects and edit these objects.
Terminals
Most submodels will contain ports (i.e an input signal, an output signal or a power port). If you are
creating submodel icons, you want to indicate the connection points of these ports. These connection
points are called terminals. In the Icon Editor you can define the position of the terminals.
46
2. Editor
3. Click with the mouse pointer on the position where you want to insert a terminal.
If you have multiple inputs, outputs or ports, a menu will open to ask you which input, output or port
should be selected.
5. Repeat the previous steps until al inputs, outputs and ports have been inserted.
The terminals are visible in the drawing as small rectangles. You can select them and from the right
mouse menu click Properties. This will open the Terminal Properties showing the name of the
input, output or port and the option to fixate the position. With a fixed position, the connections will
start or end exactly at the position of the terminal. Without a fixed position, the connections will
point to the center of the icon and start or end at the border of the icon.
47
20-sim 4.0 Reference Manual
The 20-sim Interface Editor can be used to define the model interface.
Open
1. In the Editor select the model of which you want to change the interface.
4. or at the bottom right of the Editor click the Interface tab and in the Interface tab double
click.
Use
48
2. Editor
2. Select a port from the list and change its properties (make it an input signal, output signals
and power ports etc.)
Port Properties
From the Edit menu select Add Port. A new port will now be added to the list. If you select the port in
the list you can change its properties
Name: Enter the name of the port.
Type: Select the port-type: Signal, Iconic Diagram or Bond Graph.
Signal
Size: If the signal is multi-dimensional, enter the number of rows and columns.
Orientation: Choose input signal or output signal.
Quantity: If the signal represents a physical quantity, you can choose the quantity from a
predefined list.
Unit: If the signal represents a physical quantity, you can choose the corresponding unit
from a predefined list.
Type: The default type of a signal is a real number. Choose out of real, integer or boolean.
Iconic Diagram
Size: If the port is multi-dimensional, enter the number of rows and columns.
Orientation: Choose an input or output orientation for the port.
Domain: Choose the physical domain of the port. The most general domain is power.
Depending on your choice you will see the two variables (Across and Through) associated
with the port.
Causality: Select the causality of the port.
Separate High/Low Terminals: You may choose this option for models with a velocity
difference, voltage difference etc.
Any Number of Terminals: You may choose this option for models with a variable number of
connections.
Bond Graph Port
Size: If the port is multi-dimensional, enter the number of rows and columns.
Orientation: Choose an input or output orientation for the port.
Domain: Choose the physical domain of the port. The most general domain is power.
Depending on your choice you will see the two variables (Effort and Flow) associated with
the port.
Causality: Select the causality of the port.
49
20-sim 4.0 Reference Manual
Orientation
In the Interface Editor you can set the orientation of a ports. In the Editor this orientation can be
made visible by setting the Orientation Info command from the View menu. Depending on the
type of port the orientation has a different meaning.
Signals: For signals the orientation indicates the direction of the associated variable : input
or output.
Bond Graphs: The orientation of a bond graph port is the direction of the half arrow at the
end of a bond. It indicates the direction of the positive power flow.
Iconic Diagrams: The orientation of an iconic diagram port also indicates the direction of the
positive power flow.
If you select the top of the list in the Interface Editor, you can choose the Port Relations tab to set
multiple port relations:
Equal / Not equal: The equal and not equal restrictions can be used to specify that a port p1
must have the same or opposite orientation as port p2.
Causality
A powerport (i.e. iconic diagram port or bond graph port) is always characterized by two variables.
One of these variables should be an input and one of these variables should be an output. The choice
of input and output variable is called causality. In the Interface Editor you can set the causality of the
various ports of a submodel. In the Editor this causality can be made visible by setting the Causality
Info command from the View menu.
Fixed out: The fixed out causality restriction indicates that one of the two variables is always
an output variable.
Preferred out: The preferred out causality restrictions indicate that one of the two variables
is preferably an output variable.
Indifferent: A powerport with an indifferent causality restriction can have both variables as
output.
Multiple Port Restrictions
If you select the top of the list in the Interface Editor, you can choose the Port Relations tab to set
multiple port restrictions:
Equal / Not equal: The equal and not equal restrictions can be used to specify that a
powerport p1 must have the same or opposite causality as powerport p2. This is denoted as
p1 equal p2 and p1 notequal p2 respectively.
One_out: The restriction One_out should only be used for bond graph ports. It is used to
indicate that at a one or zero junction, only one bond may have an effort out causality.
One_in: The constraint restriction One_in should only be used for bond graph ports. It is
used to indicate that at a one or zero junction, only one bond may have an effort in
causality.
50
2. Editor
fixed in orientation:
fixed in orientation:
with
51
20-sim 4.0 Reference Manual
You can start the Domains, Quantities and Units Editor by selecting the Units Editor command from
the Tools menu. In the editor a tree-like structure is shown indicating the available Domains,
Quantities and Units.
1. You can select every items in the tree for editing.
2. Use the Add or Delete button to add new items or delete existing item.
3. Use the Find button to find items in the tree.
Domains
In the Interface Editor every powertport (Iconic Diagram or Bond Graph) can be assigned a physical
domain. 20-sim will use this information to prevent that ports of different physical domains may be
connected. More popular: in this way you can never connect a translation model to an electric
component.
52
2. Editor
In the Interface Editor you can select the physical domain that you want to assign to a port. The
editor will show the corresponding port variables and the notation that should be used in the model
equations.
The tables below show the available domains and their respective port variables.
For the power domains the variables multiply to power. There are also some domains defined where
the variables do not multiply to power. These are called pseudo domains. The following pseudo
domains are defined.
53
20-sim 4.0 Reference Manual
You can enter new (pseudo) domains in the Domains, Quantities and Units Editor. If the port is
defined as a bond graph port, effort and flow are used to indicate the domain variables. The
corresponding tables are shown below.
54
2. Editor
In 20-sim a quantity can be expressed in every desired unit. To prevent conversion problems,
internal calculations are always performed in standard SI-units. Therefore non-SI units are stored
with a multiplication factor. When a variable has a unit, the unit can also have common
engineering prefixes. For example, a parameter m {kg} with a value of 0.1 can be selected in the
Parameters / Initial Values Editor. If you click on the unit, you can select other units to enter the
mass.
You can use the units in the Parameters / Initial Values Editor to select a desired unit.
You can enter new quantities and units in the Domains, Quantities and Units Editor.
Editing Domains
You can edit existing domains or add new domains in the Domains, Quantities and Units Editor.
55
20-sim 4.0 Reference Manual
In the Domains section you can add new domains or edit existing domains. Each domain has several
edit fields:
Domain name: If you click on a selected domain in the tree, you can edit the name.
Description: Enter a description of the domain.
Quantities: You can enter quantities of these variables in the quantities section.
Mechanical Domain: Select this button if your domain is part of the mechanical domain.
Pseudo Domain: Select this button if your domain is a pseudo domain.
Color: Double-click the color box to change the color of a domain.
In some domains the integrated effort/flow variables and differentiated effort/flow variables are of a
specific quantity. You can enter these quantities in the according edit fields. For some domains these
values have no meaning and you can leave the edit fields blank.
Editing Quantities
You can edit existing quantities or add new quantities in the Domains, Quantities and Units Editor.
In the Quantities section you can add new quantities or edit existing quantities. Each quantity has
several edit fields:
Quantity name: If you click on a selected quantity in the tree, you can edit the name.
Description: Enter a description of the quantity.
Variable name: This name is used for display purposes. For example if one of the variables
of a port p has the quantity length it will be denoted as p.x.
SI Symbol: Enter the official SI-symbol here. Enter combinations as nominator/denominator
(e.g. Electric Resistance: kg.m2/A2.s3)
Units: Every quantity can be expressed in several unique units (i.e. a unit can be assigned
to one quantity only). You can enter new units here or edit existing units that belong to the
selected quantity.
Unit Symbol: For display purposes every unit has a specific symbol. It is shown here in a
read-only field.
56
2. Editor
A quantity can have an alias name. Enter this alias as a subentry of the main quantity. This alias
name refers to the main quantity and therefore to the same associated units.
Editing Units
You can edit existing units or add new units in the Domains, Quantities and Units Editor.
In the Units section you can add new units or edit existing units. Each unit has several edit fields:
Unit name: If you click on a selected unit in the tree, you can edit the name.
Description: Enter a description of the unit.
Quantity: Choose the quantity to which the unit should be associated. A unit can be
associated to one quantity only.
Symbol: For display purposes every unit has a specific symbol.
Multiplications: A quantity can be expressed in several units. To prevent conversion
problems, internal calculations are always performed in standard SI-units. Therefore non-SI
units are stored with a multiplication factor. You can enter the multiplication factor here.
Allow Symbol Prefixes: Some units can be expressed with symbol prefixes. Select the check
box to allow the use of prefixes. 20-sim supports the following prefixes:
prefix symbol value
femto f 10-15
pico p 10-12
nano n 10-9
micro u 10-6
milli m 10-3
kilo k 103
mega M 106
giga G 109
tera T 1012
57
20-sim 4.0 Reference Manual
58
3 Simulator
3.1 Introduction
Simulator
20-sim consists of two main windows and many tools. The first window is the Editor and the second
is the Simulator. The Editor is used to enter and edit models. The Simulator is used to simulate and
analyze the models. The Simulator is opened in the Editor by clicking the Start Simulator button from
the Model menu.
The Simulator is used to carry out simulations, show the results and analyze them.
59
20-sim 4.0 Reference Manual
Simulation
A modeling and simulation session in 20-sim can be visualized by the diagram shown below.
Compiling/Debugging
After the model has been successfully entered, it must be checked and compiled to generate
simulation code. This is done in 20-sim automatically when you open the Simulator or when you
check a model. In some cases the model contains errors which have to be solved by adapting the
model. Errors in 20-sim are presented in the Process tab at the bottom of the Editor.
Settings
After a successful compilation of a model that is created in the Editor you can open the Simulator. In
the Simulator you have to enter specific settings:
Parameters / Initial Values.
Run Properties.
Plot Properties.
Running
After the settings have been entered you can run the simulation.
Plotting
Simulation results can be shown in 20-sim as:
Numerical Plots:
Time Domain (default)
Frequency Domain (FFT Analysis & Linearization)
Animation in a Graphical Model
60
3. Simulator
3D Animation
Debugging
If you experience problems during simulation you have to resolve them in a debugging session.
Analysis
After a successful simulation you can analyze your model using various tools:
Parameter Sweeps
Curve Fitting
Optimization
Sensitivity Analysis
Monte Carlo Analysis
Variation Analysis
FFT Analysis
Linearization
Message Log
The bottom of the Simulator shows a tab named Output. This tab contains the Message Log which
shows all the messages, warnings and errors, that are generated during a simulation.
61
20-sim 4.0 Reference Manual
The parameter items (Name, Value, Quantity, Unit, Description, Kind, Arithmetic Type, Value) of the
parameters and initial values are listed in right part of the window. The list of parameters and initial
values that is displayed depends on the selected submodel in the left part of this window.
Items
Model Hierarchy: The left part displays the complete model hierarchy. At each level of the
hierarchy, submodels can be selected. The right part of the window then shows the
parameters and initial values of that submodel. To see all parameters and initial values,
select the top level of the hierarchy, i.e. the main model listed on top.
Parameters and Initial Values: The order of the parameters or initial values in the list
depends on the order in which the submodels were originally entered in the Editor. Click on
the name box to make the order to alphabetical. Drag the name box to change the width of
the parameters list.
Value: You can change the default value of a parameter or initial value in the value list.
Select the parameter or initial value (mouse) and enter the desired value. Use the Enter key
to quickly run through a list of parameters.
Unit: If available, select the desired Unit from the drop down list.
From Matlab / To Matlab: Use the buttons to import or exports parameter values from or to
Matlab.
Import: Use this button to import the parameter values from another model.
62
3. Simulator
Note
All equations in 20-sim are calculated using standard SI-units. You can however enter
parameters, using whatever Unit you like. In the Parameters/Initial Values Editor, you can
change the unit using the little drop down list next to the Value box.
The description of a parameter can be specified in the parameters part of the equation
description of a model.
To see a global parameter, select the top level of the hierarchy, i.e. the main model listed
on top.
Hidden parameters are not visible in the Variables Chooser.
Run Properties
The Run Properties Editor can be used to choose the integration method used for simulation. An
integration method is the algorithm that calculates the model equations during each simulation and
generates the output values for the simulation plots. The default integration method is the Backward
Differentiation Formula (BDF). To open the Run Properties Editor, you have to:
Initially, the fields in the Run Properties Editor contain default values if no experiment was loaded.
Two or more tabs can be selected:
Simulator: This tab shows the general simulation settings.
Discrete Systems: This tab is only visible when discrete systems are part of your model. It
contains the settings for the sample frequency.
Algebraic Relations Solver: This tab is only visible when your model contains algebraic loops
that could not be solved during processing.
Integration Method: The last tab contains the specific settings for the selected integration
method.
63
20-sim 4.0 Reference Manual
Plot Properties
The Plot Properties Editor can be used to enter the plot specifications. To open the Plot Properties
Editor, you have to:
The editor shows three tabs which can be used to set the properties of the plot and the x and y
variables.
Plot Properties Tab
The Plot Properties Tab shows the general settings that accompany a plot. A preview is shown in the
lower part of the tab.
Plot Title: Select this option to add a title to the plot. In the text box you can type the
desired title. Use the radio buttons to display the title to the left, in the middle or to the
right of the plot.
Colors: Click the Background, Plot and Grid buttons to select the background, plot and grid
colors.
Grid: Select this option to show the grid.
Background
Windows Default: Select this option to get the default Windows background.
3D Look: Select this option to get a plot with 3D Look (sunken edges).
Axes:
Select the options Logarithmic X and Logarithmic Y to show logarithmic plots.
Show X-Values: Use this option to show or hide the X-axis values.
Show Legend: Use this option to show to show a legend.
Fonts: Click the Title, Values and Labels buttons to select the font options for the title,
values and labels.
64
3. Simulator
X-Axis Tab
The X-Axis Tab can be used to specify the variable plotted along the X-axis.
Variable Name: Either time or one of the dynamic variables of the model can be chosen as
the X-axis variable. Click the button on the right (Choose) to open the Variable Chooser and
select the desired variable.
Label: Enter the label that should be printed below the X-axis.
Show Unit: Select this option to display the unit of the chosen variable.
Scaling
Manual: Fix the scale of the X-axis by selecting a minimum and maximum value in the From
and To boxes.
Post: During the simulation run, the scale for the variable along the axis is fixed. When the
run is finished or has been interrupted by the user, the minimal and maximal scale values
are automatically updated and the plot is redrawn to make sure all calculated points are
displayed.
Automatic: When a variable reaches the end of the scale, during simulation, the the minimal
and maximal scale values are automatically updated and the plot is redrawn to make sure
all calculated points are displayed.
Clip to Bounds: When a variable reaches the end of the scale, during simulation, the the
minimal and maximal scale values are automatically updated and the plot is redrawn to
make sure all calculated points are displayed. When the run is finished or has been
interrupted by the user, the minimal and maximal scale values are automatically updated to
show the plot at maximum scope.
Show Values: Use this option to show or hide the X-axis values.
65
20-sim 4.0 Reference Manual
Y-Axis Tab
The Y-Axis Tab is used to specify the curves that should be shown in the plot. For each selected
curve, a tab is shown, displaying the settings of that curve.
Curves
Add Curve: Add a new tab to specify a new curve to be displayed in the plot.
Delete Curve: Delete the selected tab. As a result, the curve specified in the tab will not be
displayed in the plot, and the settings are lost.
Variable Name: Use this box to connect a variable to a curve. One of the dynamic variables
of the model can be selected. Click the button on the right (Choose) to open the Variable
Chooser and select the desired variable.
Label: Enter the name of the curve. This label is also printed next to the the Y-axis.
Show Unit: Select this option to display the unit of the chosen variable.
Line Properties
Line Style: Select the desired line style of the curve.
Thickness: Select the desired line thickness of the curve.
Color: Select the desired line color of the curve.
Order: In the plot a line is drawn from plot point to plot point. You can choose the line to be
of two orders of interpolation:
Zero: the line consists only of horizontal and vertical parts.
First: the line consists of straight parts.
Tick Style Properties
Tick Style: Each calculated point of a curve, can be displayed by a special marker. Select
here the desired marker.
66
3. Simulator
Min. Distance (pixels): To prevent markers from being drawn on top of each other, you can
set the minimum distance between markers. Points that are to close to a previous marker
are not drawn with a marker.
Color: Select the marker.
Scaling: Scaling can be selected for each curve individually or combined for all curves.
Shared Y Axes: Select this option to use one Y-axis scale for all curves.
Strip Charted: Select this option to display each curve in a separate plot.
Manual: Fix the scale of the variable by selecting a minimum and maximum value in the
From and To boxes.
Post: During the simulation run, the scale for the variable along the axis is fixed. When the
run is finished or has been interrupted by the user, the minimal and maximal scale values
are automatically updated and the plot is redrawn to make sure all calculated points are
displayed.
Automatic: When a variable reaches the end of the scale, during simulation, the the minimal
and maximal scale values are automatically updated and the plot is redrawn to make sure
all calculated points are displayed.
Clip to Bounds: When a variable reaches the end of the scale, during simulation, the the
minimal and maximal scale values are automatically updated and the plot is redrawn to
make sure all calculated points are displayed. When the run is finished or has been
interrupted by the user, the minimal and maximal scale values are automatically updated to
show the plot at maximum scope.
Show Values: Select or de-select this option to show or hide the name and scale of a curve.
Separate X-Axis: If you want another x-axis than specified in the X-axis tab, click the
Choose button to select the desired variable.
Running a Simulation
After specification of the Parameters/Initial Values, the Run Properties and Plot Properties you can
start a simulation run by choosing the appropriate command from the Simulation menu.
Run: Select the Run command to start or continue a simulation run. Once a run is started,
the Stop command becomes active. The run can be interrupted by selecting this command.
Stop: Use the Stop command to interrupt a simulation. Once a simulation has stopped it can
be continued by selecting the Start Simulation command.
Clear
All Runs: Select the Clear All Runs command to clear all runs that were performed, from the
graphical screen and from the computer memory.
Last Run: Select the Clear Last Run command to clear the run that was performed last, from
the graphical screen and from memory.
Previous Runs: Select the Clear Previous Runs command to clear all runs, but the last, from
the graphical screen and from memory.
One Step: Use the One Step command to calculate one new simulation point. Using this
command repeatedly, allows you to run a simulation step by step.
Brute Force: Using the Brute Force command, curves are displayed after complete
calculation of a simulation run. This saves time (re)drawing curves during calculations and
therefore considerably speeds up simulation.
Multiple Run: Select the Multiple Run command to start multiple runs needed for analysis
that was designed in the Multiple Run Wizard. Runs can be interrupted by selecting the Stop
command.
67
20-sim 4.0 Reference Manual
Replay
3D Animation: Any 3D Animation that was performed during a simulation run, can be
quickly replayed using this option.
Real Time 3D Animation: Any 3D animation that was performed during a simulation run, can
be replayed in real time (i.e. frames are skipped if necessary) using this option.
Read Datafile: Use the Read Data File command to read previously stored simulation runs
from file.
Copy States: With the Copy States command the current independent state variables can be
imported as new initial values. Current state variables are the state variables at the end of a
simulation run or at the point where a simulation run was interrupted.
Numerical Values
Select the Numerical Values command of the View menu to inspect the numerical values of a
simulation plot. The Numerical Values window will pop up and display the numerical values of all
plotted variables as a function of time. The last variable shown is always the X-axis variable (usually
time). The Numerical Values window, can also be popped up by clicking the left mouse button, while
pointing the mouse at a curve in the plot.
Run Number: The run number indicates the run of which the numerical values are shown.
The highest number indicates the last run simulated. Lower numbers are used for previous
runs. To select another run number, type in the number of interest or point in the plot at
the curve of interest.
List: The list shows all variables that are shown in the plot and their corresponding X-values
and Y-values. The variable that is currently selected is pointed out by an arrow in the plot.
Scroll-bar: Use the scroll-bar to change the selected x-axis variable value (usually time).
Find: With the Find button, the global maximum etc. of the selected variable can be found.
The following functions can be selected:
Global Maximum
Global Minimum
Next Local Maximum
Next Local Minimum
68
3. Simulator
Variable Chooser
The Variable Chooser can be used to select and inspect any dynamic variable of the loaded model.
The names, kinds, types, values, quantities, units and descriptions of the variables of the loaded
model are listed in right part of the window. The list of dynamic variables displayed, depends on the
selected (sub)model in the left part of this window. The left part displays the complete model
hierarchy.
Items
Model Hierarchy: The model hierarchy shows several keys:
Model: At each level of the hierarchy, submodels can be selected and inspected. The right
part of the window then shows the variables that are part of that submodel. To see all
variables including time, select the top level of the hierarchy, i.e. the main model listed on
top. Click on one of the variable items (Name, Value, Quantity, Unit, Description, Kind,
Arithmetic Type, Value) to order the variables alphabetically.
Input Probes/Output Probes: In the Frequency Response dialog pairs of input variables and
output variables can be selected for linearization. If input variables have been selected they
are shown under the input probes key. If output variables have been selected they are
shown under the output probes key.
Favorites: variables that are used a lot can be added to the favorites key for easy use.
Variables: Select the desired variable from the list (use your mouse pointer), select the
desired Unit from the drop down list and click OK to close the window.
69
20-sim 4.0 Reference Manual
Unit Selection: If a quantity was assigned to the selected variable with multiple units (e.g.
position -> m , mm , inch , etc.) you can switch units by the unit selection at the
bottom of the variable list.
Expand Vectors/Matrices: Select complete vectors and matrices or only their elements.
To Matlab: Use the button to export a variable value to Matlab. You will be asked to
enter a Matlab variable. Data will be exchanged between this Matlab variable and the
variable that is selected in 20-sim.
Show Variables: Select the specific kind of variables (Variables, States/Rates,
Dependent/Algebraic) that should be displayed in the Variables list.
Actions
If you select a variable in the list and use the right mouse menu several actions can be performed:
Add to Favorites: add the selected variable to the favorites list.
Add to Input Probes: Add the variable to the list of inputs for linearization. This list is used
in the Frequency Response dialog.
Add to Output Probes: Add the variable to the list of outputs for linearization. This list is
used in the Frequency Response dialog.
Copy: copy the variable value to clipboard.
Copy with Unit: copy the variable value and corresponding value to clipboard.
Copy Specified: Specify the items that should be copied and then copy to clipboard.
Tips
1. All equations in 20-sim are calculated using standard SI-units. You can however display the
results, using whatever Unit you like. In the Variable Chooser, you can change the unit
using the little drop down list just above the Show Variables section.
2. To see global variables, select the top level of the hierarchy, i.e. the main model listed on
top.
3. To quickly find some variables out of the list, add the keyword interesting in the equation
description. In the Variables list, de-select States, Rates, Algebraic Loops, Dependent States
and Dependent Rates. Then only the interesting variables are shown.
4. When using large models, opening the Variable Chooser may take some time. Use the
General Properties window to set the maximum number of variables that should be shown.
5. To hide variables from the list, add the keyword hidden in the equation description. Hidden
variables are not visible in the Variable Chooser.
Debugging
20-sim has various tool to help you to pinpoint and resolve problems that may occur during a
simulation.
Switch to Debug Mode: 20-sim is operating in Debug Mode when you see the Debug Mode
button . If your Simulator or Editor is in Fast Mode click on the button to change to
Debug Mode.
Recompile your model: In the editor select Check Complete Model from the Model menu.
This will recompile your model in Debug mode and show a maximum of warnings. If any
warning looks suspicious, solve this first.
Breakpoints: Set breakpoints to monitor time or conditions between variables.
70
3. Simulator
Run to the breakpoint: Use the Run command from the Simulation menu to run the
simulation to a breakpoint. As soon as the breakpoint has been reached, the simulation will
halt. The Output tab will display which breakpoint was active.
Simulate Step-by-Step: Use the command One Step from the Simulation menu to simulate
do one simulation step for the complete model.
Inspect the Results: After each step, open the Variable Chooser to inspect the various
variables of the model. You can also switch to the Editor to inspect results at model level:
Submodels: Select a specific submodel and choose parameters or variables to inspect the
parameters and variables of that submodel.
Equation submodels: Put the mouse pointer on top of an equation and point to a variable or
parameter of interest. A box will appear, showing the numerical value associated with that
variable or parameter.
Graphical submodels: Put the mouse pointer on top of a signal, bond or connection. A box
will appear, showing the numerical value associated with that signal, bond or connection.
71
20-sim 4.0 Reference Manual
Breakpoints
20-sim allows you define stops in a simulation called breakpoints. You can set breakpoints using the
Breakpoint Editor. This editor can be opened by selecting the Breakpoints command from the
Properties menu in the Simulator.
Setting Breakpoints.
You can run a simulation from breakpoint to breakpoint, using the Continue command from the
Simulation menu.
Breakpoints are useful when problems occur during simulation. By defining an appropriate breakpoint
and using the Run command, you can run a simulation until the point where the problem occurs. You
can continue the simulation using single steps or just running it again.
Items
Add/Delete: Use the Add and Delete buttons to add or delete breakpoints. When you add a
breakpoint, an editor will be opened to enter the breakpoint conditions.
Breakpoints: The Breakpoints list shows the entered breakpoints.
Enter the ... skip before stopping: A breakpoint may occur more than once before it should
stop the simulation run. Enter here the number of times to skip the breakpoint.
When: A breakpoint may occur more than once during a simulation run. With this option you
can select the breakpoint to be active only once or always.
Active: Use this option to make a breakpoint effective or not.
Edit Condition: When a breakpoint is selected in the breakpoints list, you can edit it, using
the Edit Condition button. This will open an editor which helps you to enter the breakpoint
condition.
Import: Import breakpoints from another model.
Note
Breakpoints are only active when 20-sim is operating in Debug Mode!
72
3. Simulator
Every plot will have a menu bar and buttons to allow you to enter the settings for the plot and
running a simulation.
Resample Curves
Select the Resample Curves command from the View menu to sample a simulation run with a fixed
sample time. This is useful if you want to use your simulation results in other programs that need
data with a fixed time step. An example is given below where a curve (red dots) is shown that is
simulated with a variable step integration method. Resampling with a sample time of 0.001 s will
result in a curve with only the blue dots.
73
20-sim 4.0 Reference Manual
Use the Resample Curves command to get equidistant timing in the plot.
Selection of the Resample Curves command of the View menu pops up the Resample Curves dialog.
You can enter the amount of data that you want to resample and the sample time or frequency.
74
3. Simulator
Note
To get simulation data with a fixed time step, using a fixed step integration method is not enough,
because this data may contain additional steps generated by time or state events. Only the
Resample Curves command will guarantee fixed time step data!
Copy States
To get the same model behavior, compared to the end of the previous run, we have to copy the
states of a model to the initial values.
When you use the Copy States command of the Simulation menu, 20-sim overwrites the initial
values of the functions ddt, int, limint and resint with their current output states. This can be done at
the end of a simulation run or at any point where a simulation run was interrupted.
Tip
For some models, behavior at some operating point or "steady state" is of interest. Use the Copy
States command to create simulation that directly starts at working level:
1. Run a simulation from t = 0 [s] until the operating point is reached. Use the Copy States
command to store the states as new initial values. Now save the experiment using some
special name.
2. Now each time you open this experiment, simulations directly start at operating point.
States
Consider the following first order linear model:
with:
75
20-sim 4.0 Reference Manual
When we start to simulate this model at t = 0 [s] the value of the integral is zero. The state is
therefore equal to the initial value int(0):
state(0) = int(0)
At the end of a simulation, the integral may be unequal to zero. The state is therefore equal to:
In other words, the value of the state is characteristic for the behavior of the model. To start a new
simulation with the same behavior, we have to change the initial value to:
int(0) = state(end)
This is valid for all dynamic models: The states of a model are characteristic for its behavior. To get
the same behavior, compared to the end of a previous run, we have to copy the states to the initial
values.
Exporting Simulations
There are several methods to export simulation results:
76
3. Simulator
Tip
You can use the Export Data To File command to store simulation results of time consuming
simulations. For later use you can use the Import From Data File command to read the result from
file.
Importing Simulations
There are several methods to import simulation results:
1. Import experiment.
If the file contains a header describing the variables inside, they will be shown in the variables dialog.
Filename: You can select an existing filename using the browse button or type one.
File Format: Data can be read as plain text file or as binary format. Use binary format when
you do not need to use data in other programs (writing and reading binary format is much
faster).
Read Header: Select this button if you want extra information (variable names etc.) to be
read from the data file.
77
20-sim 4.0 Reference Manual
Variables: The variables box shows the number of columns that were found in the data file.
Each column must be matched with a variable that is shown in the plot. Click with the
mouse on a column number to select it. Then click the Match Variable button. This opens a
Variable Chooser in which you can select a variable. When a header was used when storing
the data file, this matching is done automatically.
Match Variable: Use this button to select a matching variable for each column in the
variables box.
Plot Variables: Use the Delete button to delete a selected variable
Plot Variables: Use this button to put the same variables as shown in the plot into the
columns of the variables box.
Up/Down: Use the Up and Down buttons to change the order of the variables shown in the
list.
Tip
You can use the Export Data To File command to store simulation results of time consuming
simulations. For later use you can use the Import From Data File command to read the result from
file.
78
3. Simulator
Items
Timing (seconds):
Start: the start time of a simulation run (default: 0)
Finish: the finish time of a simulation run (default: 10)
Event delta: the accuracy for spotting state events. This option can only be selected if a
model contains state events.
Integration Methods: 8 numerical integration methods are available, each with its own
parameters. The parameters can be changed by clicking the Set Properties button or
selecting the tab on top of the editor.
Euler
Backward Euler
Adams-Bashford 2
Runge Kutta 2
Runge-Kutta 4
Runge Kutta Dormand Prince 8
Runge-Kutta-Fehlberg
Vode Adams
Backward Differentiation Formula (BDF)
Modified Backward Differentiation Formula (MBDF)
79
20-sim 4.0 Reference Manual
Output After Each: This is the plot interval. Use this option to generate output only after
each equidistant time interval has passed. For each interval, the exact simulation point is
used (if available) or the nearest point is used (if not available, for example when using
variable step algorithms).
Related Options
BreakPoints: Click this button to open the Breakpoints Editor.
General Properties: Click this button to open the General Properties Editor.
More: Click this button to set advanced options:
Endless: Select this option if you do not want the simulation to stop.
Attempting Real-Time simulation: Select this option if you want the simulation to run as fast
as the real time. You can choose the option Catch up with lost time and set the Maximum
allowed lost time.
Items
Identified with: Each discrete system in a model is assigned a unique identifier. 20-sim
detects discrete systems by looking for discrete functions and variables:
1. sample
2. hold
3. next
4. previous
5. sampletime
80
3. Simulator
When a function has been found, the elements of the corresponding discrete system are identified
by propagation of the equations. In order of appearance in the model, the discrete system is
assigned a unique identifier:
1. sample -> the variable that is assigned to the output of the sample function.
2. hold -> the variable that is assigned to the output of the hold function.
3. previous -> the discrete state corresponding with the previous function.
4. next -> the discrete state corresponding with the next function.
Timing (Standard): Each discrete system has a default sample frequency of 1 Hz. You can
change this frequency to any desired value:
Discrete Time Interval (s): The sample interval (in s) of the discrete system
Frequency (Hz): The sample frequency (in Hz) of the discrete system.
Timing (Advanced): For discrete-time control loops that interact with physical continuous-
time systems through sensors (analog to digital) and actuators (digital to analog) the
specific timing is important. Click the Advanced button to specify this timing.
1. In the Simulator from the Properties menu, click Run to open the Run Properties Editor.
2. Select the Discrete System tab and click the Advanced Settings button.
In the Advanced Discrete System Settings dialog you can specify the timing of control loops with a
fixed sampletime (click Global Time) and control loops with a variable sampletime (click Previous
Sample Event Time).
81
20-sim 4.0 Reference Manual
Fixed Sampletime
When you click the Global Time option the following window appears.
The window shows the timing diagram for a fixed sampletime control loop. The loops starts with an
clock interrupt from a timer. It will take some time before the interrupt is handled and generally
some calculations are performed before the sensor signals (sample) are read. This delay is
represented by the sample delay which is divided in a fixed time and a variable time part. The control
loop will proceed and perform the necessary calculations to generate the actuator output (hold).
These calculations will take some time, which is represented by the fixed time hold delay. After this
action the control loops will come to a halt until the next clock interrupt is generated.
If the control loops is properly designed it will know the task it is performing when a clock interrupt is
getting in. E.g. if it is still calculating the actuator outputs when clock interrupt is getting in, an error
will be generated, specifying that the sampletime is too small to perform all necessary calculations.
Items
Sample Delay:
Fixed: Enter the fixed sample delay here.
Variable: Enter the variable delay here. You can chose from two distributions:
Uniform: The delay is uniformly distributed between the given minimum and maximum.
Gaussian: The delay has a given mean and standard deviation.
Hold Delay: Enter the fixed hold delay here.
Action on Sample Missed: An error will be generated when the total delay is larger than the
sampletime or when the total delay is negative.
82
3. Simulator
Variable Sampletime
When you click the Previous Sample Event Time option the following window appears.
The window above shows the timing diagram for a variable sampletime control loop. It performs the
same tasks as a fixed sampletime control loop, but will start the next loop as soon as the previous
loop was finished. The variable sampletime control loop does not use a clock interrupt!
Items
Sample Delay:
Fixed: Enter the fixed sample delay here.
Variable: Enter the variable delay here. You can chose from two distributions:
Uniform: The delay is uniformly distributed between the given minimum
and maximum.
Gaussian: The delay has a given mean and standard deviation.
Hold Delay: Enter the fixed hold delay here.
Action on Sample Missed: Only an error will be generated when the total delay is negative.
83
20-sim 4.0 Reference Manual
Euler
This is the explicit Euler method. It is a single-step explicit method, which needs one model
calculation per time step. The size of the time step is fixed. This simulation algorithm requires 1
parameter to be specified:
Step Size: the step time of the integration algorithm (default: 0.01).
Backward Euler
This is a combination of the implicit Backward Euler method and the explicit Forward Euler method. It
is a single-step implicit method, which needs one model calculation per time step. With the
parameter alpha the combination is defined:
alpha combination
-1 100% Forward Euler explicit
0 50% Forward Euler, 50 % Backward Euler explicit
1 100% Backward Euler implicit
Step Size: the step time of the integration algorithm (default: 0.01).
Relative Tolerance: Relative tolerance for the rootfinding in the Backward Euler method.
Alpha: Choose between Forward Euler (alpha = -1), Trapezoidal (alpha = 0) and Backward
Euler (alpha = 1).
84
3. Simulator
Adams-Bashford
This is the trapezoidal rule. It is a single-step explicit method, which needs only two model
calculations per time step. The size of the time step is fixed. This simulation algorithm requires 1
parameter to be specified:
Step Size: the step time of the integration algorithm (default: 0.1).
Runge-Kutta 2
This is an explicit single-step second-order derivatives method which needs 2 model calculations per
time step. It is the simple form of the classical Runge-Kutta method. The size of the time step is
fixed. This simulation algorithm requires 1 parameter to be specified:
Step Size: the step time of the integration algorithm (default: 0.01).
Runge-Kutta 4
This is an explicit single-step fourth-order derivatives method which needs 4 model calculations per
time step. It is the classical Runge-Kutta method. The size of the time step is fixed. This simulation
algorithm requires 1 parameter to be specified:
Step Size: the step time of the integration algorithm (default: 0.01).
Runge-Kutta-Fehlberg
This is an explicit variable-step 4/5-order derivatives method, primarily designed to solve non-stiff
and mildly stiff differential equations. Because the method has very low overhead costs, it will usually
result in the least expensive integration when solving problems requiring a modest amount of
accuracy and having equations that are not costly to evaluate. This simulation algorithm has 4
parameters:
Integration Error (required)
Absolute: The absolute integration error, valid for every state variable (default: 1e-6).
Relative: The relative integration error, valid for every state variable (default: 1e-6).
Step Size (not required)
Initial: The step size for the first simulation step (default: 0.01).
Maximum: The maximum size of a simulation step (default: 1).
85
20-sim 4.0 Reference Manual
Vode Adams
This is the explicit variable-step stiff integration algorithm of Cohen and Hindmarsh. This method is
specially suited for explicit models that combine high and low frequency vibrations with little damping
(so called "stiff" models). This simulation algorithm has 4 parameters:
Integration Error (required)
Absolute: The absolute integration error, valid for every state variable (default: 1e-6).
Relative: The relative integration error, valid for every state variable (default: 1e-6).
Maximum Step Size (not required): The maximum size of a simulation step (default: 1).
Multistep Method (required): The variable step integration method that is used. A BDF
method is default and best suited for stiff systems.
Iteration Type (required): The method used for iteration loops (algebraic relations). The
Newton method is default and best suited for stiff systems.
86
3. Simulator
Note
This is the only method that supports the use of the constraint function.
The MeBDFi method cannot handle contraints that do not influence the model. Therefore 20-
sim will check at the beginning of the simulation if contraints have been properly defined.
The contraints that do not influence the model are set to zero automatically. If you do not
want to use this check, deselect the Smart Contraint Solving option.
Undamped models are not simulated properly with this method.
The default values are suitable for problems with time constants of order of magnitude of
0.1 to 1. Initial Step Size and Maximal Step Size influence the behavior of the method and
should be tuned with care.
87
20-sim 4.0 Reference Manual
88
4 Language Reference
4.1 Introduction
Language Reference
Every (sub)model has an implementation. This can be a composition of lower level submodels, which
themselves are composed of lower level submodels etc. At the bottom of this hierarchy the
submodels consist of a set of mathematical equations (equation submodel). These submodels are
therefore known as equation submodels.
All equations used in 20-sim are described in the language SIDOPS+. A simple equation model
written in SIDOPS+ is shown below:
89
20-sim 4.0 Reference Manual
You will find out that in most cases the SIDOPS+ language is equal to standard mathematical
notation. Regardless of your modeling background, you can learn quickly to build your own equation
models. 20-sim comes with over 80 built-in functions that do most of the work for you. To learn
more about equation models, have a look at the following sections:
1. Model Layout
3. Data Types
4. Operators
5. Functions
6. Statements
Model Layout
The general layout of an equation model is:
constants
//enter your constants here, for a description see constants
parameters
//enter your parameters here, for a description see parameters
variables
//enter your variables here, for a description see variables
initialequations
// enter your initial equations here, for a description see initialequations
code
// enter your equations here, for a description see code
equations
// enter your equations here, for a description see equations
finalequations
// enter your final equations here, for a description see finalequations
Only the equations section is required. The other sections are optional.
Equations
The body of an equation model consists of the keywords initialequations, code, equations and
finalequations, each followed by one or more equations. Equations are relations between variables
indicated by an equal (=) sign:
y = x + 1;
z + y = sin(time*2*pi*f);
g = ddt(g + z, g_initial);
90
4. Language Reference
1. An equation may span more than one line but must always be finished by a semicolon (;).
u = sin(time*f*2*3.1415 + (a + b)/c );
4. Extensions like .e or .f are used to indicate the effort and the flow variables of powerports.
These extensions are not allowed for any other type of identifier (i.e. inputs, outputs,
constants, parameters or variables).
7. Errors are shown automatically after checking in the Process tab. Double clicking on the error
text will make 20-sim jump to the error, which is then colored red.
Execution
1. Equations within 20-sim may be entered in random form. During compilation, 20-sim will
automatically try to rewrite equations into a correct order of execution.
2. Some integration algorithms do more calculations before generating the next output value.
These calculations are called minor steps, the output generation is called a major step.
During a minor step, all model equations are executed. In most cases you will not notice
this because only the results of the major step are shown in the simulator, but in some
cases this may cause unwanted results.
Equation Sections
In 20-sim equations can be divided in four sections: initialequations, equations, code and
finalequations.
Initialequations
The initialequations section should contain all equations that should calculated before the simulation
run. The equations are calculated once. The equations in this section form a code block, i.e. the
equations themselves and the order of the equations are not rewritten during compilation and
executed sequentially. The results of the initialequations section are not shown in the simulator plots
and can therefore not be inspected in the Numerical Values window!
91
20-sim 4.0 Reference Manual
Example
The initialequations section is used in the library model Spring Damper (stiffness):
parameters
real k = 10.0 {N/m};
real m = 1.0 {kg};
real b = 0.05 {};
variables
real x {m};
real d {damping,N.s/m};
initialequations
d = 2*b*sqrt(k*m);
equations
x = int (p.v);
p.F = k * x + d*p.v;
As you can see in the initialequations section the damping d is calculated out of the relative damping
b, mass m and stiffness k.
Equations
The equations section contains all standard equations. They do not have to be entered in a sequential
form. They are rewritten during compilation to get the correct order of execution. The resulting code
is calculated every simulation step. You can see the use of the equations section in the example
above.
Code
The code section contains a code block. A code block contains all equations that must be calculated
sequentially, i.e. the equations themselves and the order of the equations are not rewritten during
compilation. The resulting sequential code is calculated every simulation step.
Example
The code section is used in the library model Spring Damper (stiffness):
parameters
real initial = 0.0;
variables
real prev, peak;
initialequations
peak = initial;
prev = 0;
output = initial;
code
if major then
peak = max([abs(input), peak]);
if (input > 0 and prev < 0) or (input < 0 and prev > 0) then
output = peak;
peak = 0;
end;
prev = input;
end;
92
4. Language Reference
Finalequations
The finalequations section should contain all equations that should calculated after a simulation run.
The equations are calculated once. The equations in this section form a code block, i.e. the equations
themselves and the order of the equations are not rewritten during compilation and executed
sequentially. The results of the finalequations section are not shown in the simulator plots and can
therefore not be inspected in the Numerical Values window!
Example
The finalequations section is used in the library model DoMatlab-Final:
parameters
string command = '';
finalequations
// send the command to the workspace
doMatlab (command);
As you see you can give the parameter command any value, which is then exported to Matlab at the
end of the simulation run.
93
20-sim 4.0 Reference Manual
Power ports
Power ports describe the flow of power and are always characterized by two variables. For bond
graph ports the extensions .e and .f are used to indicate these variables. For iconic diagram ports
many aliases are known. You can use these variables in equations by typing the port name followed
by a dot and the extension.
You can always find the correct extensions by opening the Interface Editor and selecting a port. The
example below, shows the library model Friction.emx. In the Interface Editor, one power port is
defined with the name p. As shown, the correct description of both variables is p.v and p.F.
Double clicking in the Interface tab will open the Interface Editor.
94
4. Language Reference
The equation description of this model (see below) shows the use of the variables p.v and p.F.
In the equations the port variables p.F and p.v are used.
Reserved Words
While entering equations, the 20-sim Editor will automatically detect reserved words. You can
recognize reserved words, because they will be shown with a different color:
element color
keywords black
data types black
functions blue
statements black
predefined variables blue
- , * , .* , ./ , .^ , / , ^ , + , < , <= , <> , == , > , >= , abs , adjoint , Adjoint , algebraic , and ,
antisym , arccos , arccosh , arcsin , arcsinh , arctan , arctanh , atan2 , boolean , by , ceil , code ,
collect , columns , constants , constraint , cos , cosh , cross , data , ddt , delta , det , diag , direct ,
discrete , div , dll , dlldynamic , dly , do , doMatlab , effortincausality , else , end , equal , equations ,
event , eventdown , eventup , exp , exp10 , exp2 , export , externals , eye , false , finalequations ,
first , floor , flowincausality , for , frequencyevent, from , fromMatlab , gauss , global , hidden , hold ,
homogeneous , if , import , initialequations , inner , int , integer , interesting , inverse , inverseH,
95
20-sim 4.0 Reference Manual
limint , limit , log , log10 , log2 , major , max , min , mod , msum , mul , next , nonlinear , norm ,
norminf , not , or , parameters , previous , ramp , ran , random , real , repeat , resint , resint ,
return , round , rows , sample , sampletime , sign , sin , sinh , skew , sqr , sqrt , step ,
stopsimulation , string , sum , sym , table , tan , tanh , tdelay , then , tilde , time , timeevent , to ,
toMatlab , trace , transpose , true , trunc , type , types , until, variables , warning , while , xor
White Space
Like C and other programming languages, 20-sim does not recognize white space (spaces and tabs,
carriage returns) except in a string. We recommend that you use white space to make your model
easier to follow. For example, the following model is dense and difficult to read:
variables
real y,u;
equations
y = step(1);
u = -step(1);
if time > 5 then y = -ramp(1); u = ramp(1);
else y = ramp(1); u = -ramp(1); end;
Adding white space with indentation makes the same code much easier to read:
variables
real y;
real u;
equations
y = step(1);
u = -step(1);
Writing Comments
20-sim gives you several options to create comments in a model. You can use each option add
explanatory text to your model or to exclude ("comment out") certain parts of your model for testing
and debugging purposes.
96
4. Language Reference
Programming (/*...*/)
You can enclose a block of text between the constructs /* and */. This method is used often in
programming and also allows to write a comment over multiple lines:
You can begin comments anywhere in a model. 20-sim will automatically recognize comments and
color it green.
97
20-sim 4.0 Reference Manual
State Events
Sometimes the integration algorithm must iterate to find the next calculation step. This is called a
state event. The following functions cause state events.
function description
event Forces the integration algorithm to find the exact point where the input crosses zero.
eventup Forces the integration algorithm to find the exact point where the input crosses zero
from a negative to a positive value.
eventdown Forces the integration algorithm to find the exact point where the input crosses zero
from a positive to a negative value.
limint Forces the integration algorithm to find the exact point where the output become
larger or smaller than the minimum and maximum parameters.
resint Forces the integration algorithm to find the exact point where the input becomes
zero.
To find the exact point where simulation should be performed iteration is used. The accuracy of the
iteration can be set by the event delta parameter in the Run Properties window.
4.2 Keywords
Keywords
Before the actual equations, three sections can be entered denoted by the keywords constants,
parameters and variables. This is shown in the example below:
constants
real basefrequency = 60;
real pi = 3.14159265;
parameters
real amplitude = 1;
variables
real plot;
equations
plot = amplitude * sin (basefrequency*2*pi * time);
The order of appearance of these sections must always be: (1) constants, (2) parameters and (3)
variables. The sections are optional. If you do not use constants parameters or variables, these
sections may be omitted.
98
4. Language Reference
Constants
Constants are symbolic representations of numerical quantities that do not change during or in
between simulation runs. Constants must be defined in 20-sim, using the constants keyword. After
the keyword, lines with constant declarations can be entered. Every line must be finished by a
semicolon (;). An example is given below:
constants
real V = 1 {volume, m3}; // the volume of barrel 1
real hidden D = 0.5 {length, m}; // the length of part 1
...
Types
20-sim currently supports four types of constants: boolean, integer, real and string. These types
must be specified explicitly. The use of the type real is shown in the example above.
Hidden
To prevent users from inspecting constants, the keyword hidden can be applied. This keyword should
follow the data type.
Constant names
Constant names can consist of characters and underscores. A constant name must always start with
a character. Constant names are case-sensitive. No reserved words may be used for constants. If a
reserved word is used, an error message will pop-up while checking the model. In the example above
the names V and D are used.
Constant Values
It is advised to assign every constant a value. Otherwise 20-sim will assign a default value (0, false
or an empty string), which can easily lead to misinterpretations. Unlike parameter values, constant
values cannot be overridden in the Simulator.
Quantity and Unit
If a constant is known to represent a physical value, you can define the corresponding quantity and
unit. 20-sim will use this information to do a unit check on equations. The use of quantities and units
is optional. In the example above the quantities volume and length are used with the units m3 and
m.
Examples
constants
real pi = 3.14159265359;
real two pi = 6.28318530718;
integer i = 10 {length,m}; // vehicle length
integer j = 1 {time,s};
constants
string filename = 'data.txt';
integer i = 1;
real state = 0.0;
boolean t = true, f = false;
99
20-sim 4.0 Reference Manual
Tip
You can easily enter constants by using the Add button in the Equation Editor Taskbar.
You can easily select quantities and units by using the Units button of the Equation
Editor Taskbar.
Predefined Constants
Some constants in 20-sim have a predefined value. These constants do not have to be declared in
the constants section of a model. You can add your own predefined constants in the file Constants.ini
in the 20-sim bin-directory.
Standard
pi 3.1415926535897932384626433832795
exp1 2.71828182845904523536028747135266
twopi 6.28318530717958647692528676655901
sqrt2 1.41421356237309504880168872420969
log2 0.6931471805599453094172321214581766
Physics
g_n 9.80665 {m/s2} Standard acceleration of gravity
G 66.7259e-12 {N.m2/kg2} Newtonian constant of gravitation
c_0 299.792458e6 {m/s} Speed of light (vacuum)
mu_0 1.2566370614359172953850573533118e- Permeability (vacuum)
6 {H/m}
epsilon_0 8.854188e-12 {F/m} Permittivity (vacuum)
h 6.6260755e-34 {J.s} Planck constant
m_p 2.17671e-08 {kg} Planck mass
l_p 1.61605e-35 {m} Planck length
t_p 5.39056e-44 {s} Planck time
e 1.60217733e-19 {C} Elementary charge
R_H 25812.8056 {Ohm} Quantized Hall resistance
mu_B 9.2740154e-24 {J/T} Bohr magneton
mu_N 5.0507866e-27 {J/T} Nuclear magneton
Ry 10973731.534 {1/m} Rydberg constant
a_0 5.29177249e-11 {m} Bohr radius
N_A 6.0221367e+23 {1/mol} Avagadro constant
m_u 1.6605402e-27 {kg} Atomic mass constant
F 96485.309 {C/mol} Fraday constant
k 1.380658e-23 {J/K} Boltzmann constant
100
4. Language Reference
Conversion
Constants
eV 1.60217733e-19 {J}	 Electron volt
u 1.6605402e-27 {kg} Atomic mass unit
atm 101325 {Pa} Standard atmosphere
deg 0.0174532925199432957692369076848861 Angular degree
{rad}
Parameters
Parameters are symbolic representations of numerical quantities which can only be changed after
simulation has been stopped. They can therefore be changed in between of simulation runs, or after
the user has (temporarily) stopped the simulation.
Parameters must be defined in 20-sim, using the parameters keyword. After the keyword, lines with
parameter declarations can be entered. Every line must be finished by a semicolon (;) and may be
followed by comment with a description of the parameter. An example is given below:
parameters
real V = 1 {volume, m3}; // the volume of barrel 1
real hidden D = 0.5 {length, m}; // the length of part 1
...
Types
20-sim currently supports four types of parameters: boolean, integer, real and string. These types
must be specified explicitly. The use of the type real is shown in the example above.
Hidden
To prevent users from inspecting parameters or decreasing the list of parameters, the keyword
hidden can be applied. This keyword should follow the data type.
Global
To use the same parameter in other submodels, the keyword global can be applied. This keyword
should follow the data type.
101
20-sim 4.0 Reference Manual
Parameter Names
Parameter names can consist of characters and underscores. A parameter name must always start
with a character. Parameter names are case-sensitive. No reserved words may be used for
parameters. If a reserved word is used, an error message will pop-up while checking the model. In
the example above the names V and D are used.
Parameter Values
Parameters can be assigned default values. These values can be overridden in the Simulator using
the Parameters command.
Quantity and Unit
If a parameter is known to represent a physical value, you can define the corresponding quantity and
unit. 20-sim will use this information to do a unit check on equations. The use of quantities and units
is optional. In the example above the quantities volume and length are used with the units m3 and
m.
Comment
If comment is added at the end of the parameter declaration, it is shown in the Variable Chooser to
facilitate the selection between variables.
Examples
parameters
real p1 = 12,p2, state = 1.1;
integer i = 10 {length,m}; // vehicle length
integer j = 1 {time,s};
parameters
string filename = 'data.txt'; // This comment appears as a description in the
Parameters/Initial values editor.
integer i = 1; // Just a parameter
real state; // Initial velocity [m/s]
boolean t = true; // T = true
Tip
You can easily enter parameters by using the Add button in the Equation Editor Taskbar.
You can easily select quantities and units by using the Units button of the Equation
Editor Taskbar.
Variables
Variables are symbolic representations of numerical quantities that may change during simulation
runs. Variables must be defined in 20-sim, using the variables keyword. After the keyword, lines with
variable declarations can be entered. Every line must be finished by a semicolon (;). An example is
given below:
variables
real interesting V {volume, m3}; // the volume of barrel 1
real hidden D {length, m}; // the length of part 1
...
102
4. Language Reference
Types
20-sim currently supports four types of variables: boolean, integer, real and string. These types must
be specified explicitly. The use of the type real is shown in the example above.
Interesting
By adding the keyword interesting after the variable type, a variable will be given special focus in the
Variable Chooser. The Variable Chooser shows the complete list of variables of a model and is used
to select variables for plotting. The keyword interesting is shown in the variable list, making it easier
to find variables of special interest.
Hidden
To prevent users from inspecting variables or decreasing the list of variables, the keyword hidden
can be applied. This keyword should follow the data type.
Global
To use the same variable in other submodels, the keyword global can be applied. This keyword
should follow the data type.
Variable Names
Variable names can consist of characters and underscores. A variable name must always start with a
character. Variable names are case-sensitive. No reserved words may be used for variables. If a
reserved word is used, an error message will pop-up while checking the model.
Variable Values
Variables cannot be assigned default values.
Quantity and Unit
If a variable is known to represent a physical value, you can define the corresponding quantity and
unit. 20-sim will use this information to do a unit check on equations. The use of quantities and units
is optional. In the example above the quantities volume and length are used with the units m3 and
m.
Comment
If comment is added at the end of the variable declaration, it is shown in the Variable Chooser to
facilitate the selection between variables.
Predefined Variables
20-sim has some predefined variables which have a special meaning.
Examples
variables
real interesting p1,p2,state;
integer i;
integer j;
variables
string filename;
integer interesting i;
real interesting state;
boolean t,f;
103
20-sim 4.0 Reference Manual
Predefined Variables
Some variables in 20-sim have a predefined value. These variables do not have to be declared in the
variables section of a model.
time
The variable time is equal to the simulated time. It can for example be used in functions such as:
u = sin(time*f*2*3.1415);
sampletime
The variable sampletime is equal to the sampletime. It is only meaningful when it is used in an
equation model that is part of a discrete loop in your model. 20-sim will automatically detect, which
loop the model belongs to and assign the proper value to the variable sampletime.
random
The variable random will yield a random variable uniformly distributed in the interval [-1,1]. E.g.:
u = random;
true
The variable true will return the boolean value true.
false
The variable false will return the boolean value false.
major
Some integration algorithms, will perform model calculations at one or more intermediate points
before calculating the next output value. To prevent equations being calculated, at these
intermediate steps, you can use the variable major. This variable will return the boolean false when
calculations are performed for an intermediate step and will return true when calculations are
performed for the output values.
Example:
....
if major then
sim_steps = sim_steps + 1; // this equation is not evaluated at intermediate points
end;
....
The best way to describe the use of global parameters and variables is by an example model. You
can find this model in the 20-sim demonstration library (Demo\Tips And Tricks\Global
Parameters and Variables.emx). The model exists of three submodels. In the first submodel two
104
4. Language Reference
global parameters (f and A) are assigned and one variable (sinewave). The variable is assigned a
value in the equations section and connected with the output (out1).
submodel1
parameters
real global f = 100 {Hz};
real global A = 1 {none};
variables
real global sinewave;
equations
sinewave = A*sin(f*2*pi*time);
out1 = sinewave;
In the second submodel, the two global parameters are use to connect them with two outputs (out1
and out2).
submodel 2
parameters
real global f {Hz};
real global A {none};
variables
real global sinewave;
equations
out1 = f;
out2 = A;
In the third submodel, the global variable is connected with an output (out1).
submodel 3
variables
real global sinewave;
equations
out1 = sinewave;
To prevent conflicts global parameters may be assigned a default value only once. The same goes for
global variables: they may be assigned a value in the equation section only once.
105
20-sim 4.0 Reference Manual
4.3 Types
Data Types
For all parameters, variables, initial conditions etc. 20-sim supports the following data types:
1. Boolean
2. Integer
3. Real
4. String
The declaration of data types can be done in the constants, parameters and variables sections of the
model. E.g.:
parameters
real a = 1
integer B[2,2];
variables
string c;
boolean yesno;
parameters
real hidden a = 1
integer hidden B[2,2];
variables
string hidden c;
boolean hidden yesno;
Interesting
To allow for a quick selection of variables in the Variable Chooser, the keyword interesting can be
applied for variables. This keyword should follow the data type. For example:
parameters
real a = 1
integer B[2,2];
variables
string interesting c;
boolean interesting yesno;
106
4. Language Reference
Interesting variables are shown, even when al options are deselected in the Variable Chooser. This
make it possible to quickly select variables out of a large list.
Boolean
Either true (1) or false (0). Variables of this type should not be used to store any other values. Like
C++, 20-sim evaluates non-zero values as true; only the value of zero is evaluated as false.
Normally, the value of one is used to indicate true.
Examples
boolean a;
boolean b = true;
boolean c = false;
boolean D[2,2] = [true,true;false;false];
a = b and c;
Limitations
When used in standard functions, booleans are treated as reals with value 0 or 1. An equation like:
boolean a = true;
real c;
c = sin(a);
would yield c equal to 0.8415. Try to avoid these constructions, since they lead to confusions.
Integer
Signed four-byte integer. It can hold any value between -2147483648 and +2147483647. Integer is
the recommended data type for the control of program loops (e.g. in for-next loops) and element
numbering.
Examples
parameters
integer i = 1,j = 2;
real B[2,2] = [1,2;3,4]
real b;
equations
b = B[i,j];
for i := 1 to 10 do ....end;
Limitations
When used in standard functions, integers are treated as reals. An equation like:
parameters
integer c;
equations
c = 10*sin(time);
107
20-sim 4.0 Reference Manual
would yield c equal to 0.8415. Try to avoid these constructions, since they lead to confusions. Us the
round function instead:
parameters
integer c;
equations
c = round(10*sin(time));
Real
Signed 64 bit floating point number. The maximum representable number is
1.7976931348623158e+308. The minimum positive value unequal to zero is 2.2250738585072014e-
308. If reals exceed this range during simulation, the numerical values window will display the values
1.#INF (positive infinite) or -1.#INF (negative infinite).
Examples
real a = 0.0;
real b = 1.04e-31,c = -3198.023e-64;
real B[2,2] = [1.2,22.4;3.0e3,-4.023e-6];
Limitations
In practice, during simulation, real should not exceed 1e-100 .. 1e100 to prevent instability in the
integration algorithms.
String
A string is an array of characters. There is no limit to the amount of characters a String may contain.
Simple string concatenation (e.g. concatenation that can be done during processing) is allowed.
Strings must always be entered between single quotes ('). A single quote can be escaped with a
second quote, so if a single quote should be part of the string, it needs to be typed twice.
Examples
parameters
string c = 'C:\data.txt';
string b = 'This is a string with a '' single quote';
variables
real d;
string name;
equations
if time > 10 then stopsimulation (b); end;
d = table(c,1);
name = c + ' // file';
toMatlab (d, name)
Limitations
Strings may only be used as input for some special functions (e.g. table).
108
4. Language Reference
4.4 Functions
Functions
In 20-sim you can use all kind of functions to describe your equations. They are classified according
to the list below.
1. Arithmetic
2. Discrete
3. Event
4. Expansion
5. Extern
6. Matrix
7. Port
8. Source
9. Trigonometric
algebraic
Syntax
y = algebraic(x);
Description
y becomes equal to x. This function forces the integration algorithm to find a solution by using the
algebraic loop solver. Normally when algebraic loops occur in a model, 20-sim will itself will break the
algebraic loop using the algebraic loop solver internally. You can use this function to break an
algebraic loop at a user-defined position.
Examples
u = sin(time);
a = algebraic(y);
y = K*(u - a);
Note
Be very careful with this function. In most cases the symbolic engine of 20-sim will find and exact
solution which will lead to much faster simulation!
abs
Syntax
Y = abs(X);
Description
Returns the absolute value of X or the elements of X.
109
20-sim 4.0 Reference Manual
Examples
X abs(X)
1 1
2.1 2.1
-2.6 2.6
-1e-102 1e-102
[1.1,2.7;-3.6,-4] [1.1,2.7;3.6,4]
Limitations
X and Y must have the same size.
For scalars, the abs function can also be written as: Y = |X|;
ceil
Syntax
Y = ceil(X);
Description
Rounds X or the elements of X to the nearest integers greater than or equal to X.
Examples
X ceil(X)
1 1
2.1 3
-2.6 -2
3.4 4
[1.1,-2.7;3.5,-4.1] [2,-2;4,-4]
Limitations
X and Y must have the same size.
constraint
Syntax
y = constraint(x);
Description
This function iteratively assigns a value to y such that x approaches zero within a given error margin.
It only works in combination with the MBDF simulation method! The function is very useful for
entering constraints in physical systems and inverse dynamics.
Examples
This example makes a velocity vm equal to a reference velocity vs:
110
4. Language Reference
ddt
Syntax
y = ddt(x,init);
Description
Returns the derivative value of x with respect to the time. The initial value of y is equal to the value
of init.
Method
20-sim will always try to rewrite equations in such a way that only integrals are used (integral form).
This is done automatically and means all integration methods can be applied. Sometimes an integral
form cannot be found. Then only the Backward-Differentiation Method can be used for simulation.
Examples
equation integral form integration
Limitations
When no integral form can be found, the use of the derivative function can introduce noisy signals or
may even cause signals to exceed the data range.
dly
Syntax
y = dly(x,init);
Description
y is equal to the value of x, one simulation-time step delayed. The initial value of y is equal to init
Examples
x = sin(time*0.3);
y = dly(x);
Limitations
x,y and init must be scalars.
exp
Syntax
Y = exp(X);
Description
Returns the exponential function of X or the elements of X.
y = ex;
111
20-sim 4.0 Reference Manual
Examples
X exp(x)
1 2.718282 (= e1)
2.1 8.166170 (= e2.1)
-2.6 0.074274 (= e-2.6)
[1,2.1;-2.6,1] [2.718282,8.166170;0.074274,2.718282]
( = [e1,e2.1;e-2.6,e1] )
Limitations
X and Y must have the same size.
exp10
Syntax
Y = exp10(X);
Description
Returns the exponential function (base 10) of X or the elements of X.
y = 10x;
Examples
X exp10(x)
1 10 (= 101)
2.1 125.89 (= 102.1)
-2.6 0.00251 (= 10-2.6)
[1,2.1;-2.6,1] [10,125.89;0.00251,10]
( = [101,102.1;10-2.6,101] )
Limitations
X and Y must have the same size.
112
4. Language Reference
exp2
Syntax
Y = exp2(X);
Description
Returns the exponential function (base 2) of X or the elements of X.
y = 2x;
Examples
X exp2(x)
1 2 (= 21)
2.1 4.8709 (= 22.1)
-2.6 0.16494 (= 2-2.6)
[1,2.1;-2.6,1] [2,4.8709;0.16494,2]
( = [21,22.1;2-2.6,21] )
Limitations
X and Y must have the same size.
floor
Syntax
Y = floor(X);
Description
Rounds X or the elements of X to the nearest integers less than or equal to X.
Examples
X floor(X)
1 1
2.1 2
-2.6 -3
3.4 3
[1.1,-2.7;3.5,-4.1] [1,-3;3,-5]
Limitations
X and Y must have the same size.
113
20-sim 4.0 Reference Manual
int
Syntax
y = int(x,init);
Description
Returns the integral of x with respect to the time. The initial value of y is equal to the value of init.
This initial value is optional. If no value is entered, a default initial value of 0 is used.
Examples
y = int(x,0);
z = int( sin(time*w + p) - cos(time*x + z) , b);
limint
Syntax
y = limint(x,min,max,init);
Description
Returns the integral of x with respect to the time. The initial vallue of y is equal to the value of init.
The output of this integral is limited between a maximum and minimum bound given by the
parameters min and max.
This function forces the integration algorithm to find the exact point where the gets saturated. If the
integral is in saturated condition and the input changes sign, the output wanders away from the
bounds immediately.
The limitedIntegrator block is used for the prevention of wind-up in PI and PID controllers in control
applications. It is also used in kinematics, electrical circuits, process control, and fluid dynamics.
Examples
x = 10*sin(time*10);
y = limint(x,-1,1,0);
114
4. Language Reference
limit
Syntax
y = limit(x,a,b);
Description
This function limits the signal x between a minimum of a and a maximum of b.
Examples
x = 10*sin(time);
y = limit(x,-5,5);
Limitations
a,b,x and y must be scalars. a must be smaller than b.
log
Syntax
y = log(x);
Description
Returns the natural logarithm of X or the elements of X.
Examples
X log(X)
1 0
2.1 0.6931
4 1.3863
[1,2.1;4,1] [0,0.6931;1.3863,0]
-2.6 not allowed!
Limitations
X and Y must have the same size. X or the elements of X must be larger than zero.
115
20-sim 4.0 Reference Manual
log10
Syntax
Y = log10(X);
Description
Returns the base 10 logarithm of X or the elements of X.
Examples
X log10(X)
1 0
50 1.6990
100 2
[1,50;100,1] [0,1.6990;2,0]
-2.6 not allowed!
Limitations
X and Y must have the same size. X or the elements of X must be larger than zero.
log2
Syntax
Y = log2(X);
Description
Returns the base 2 logarithm of X or the elements of X.
Examples
X log2(X)
1 0
2.1 1.0704
4 2
[1,2.1;4,1] [0,1.0704;2,0]
-2.6 not allowed!
Limitations
X and Y must have the same size. X or the elements of X must be larger than zero.
116
4. Language Reference
resint
Syntax
y = resint(x,newoutp,reset,init);
Description
Returns the integral of x with respect to the time. The initial value of y is equal to the value of init.
The output of this integral is reset to the value of newoutp when the boolean argument reset is
TRUE.
Examples
x = 1;
reset = event(sin(time));
y = resint(x,0,reset,0);
or
x = 1;
reset = if y > 10 then true else false end;
y = resint(x,0,reset,0);
round
Syntax
Y = round(X);
Description
Rounds X or the elements of X to the nearest integer.
Examples
X round(X)
1 1
2.1 2
-2.6 -3
3.7 4
[1.1,-2.7;3.5,-4.1] [1,-3;4,-5]
Limitations
X and Y must have the same size.
117
20-sim 4.0 Reference Manual
sign
Syntax
Y = sign(X);
Description
Returns the sign of X or the elements of X.
X = < 0 : Y = -1
X = 0: Y = 0
X > 0: Y = 1
Examples
X sign(X)
1 1
2.1 1
-2.6 -1
0 0
[1,2.1;-2.6,0] [1,1;-1,0]
Limitations
X and Y must have the same size.
sqr
Syntax
Y = sqr(X);
Description
Returns the square of X or the elements of X.
Examples
X sign(X)
1 1 (= 12 )
2.1 4.41 (= 2.12 )
-2.6 6.76 (= -2.62 )
0 0 (= 02 )
[1,2.1;-2.6,0] [1,4.41;6.76,0]
( = [12,2.12;-2.62,02] )
Limitations
x and y must be scalars.
118
4. Language Reference
sqrt
Syntax
X = sqrt(Y);
Description
Returns the square root of X or the elements of X.
Examples
X sqrt(X)
1 1
2.1 1.44913
4 2
[1,2.1;4,1] [1,1.44913;2,1]
-1 not allowed!
Limitations
X and Y must have the same size. X or the elements of X must be larger than or equal to zero.
tdelay
Syntax
y = tdelay(x,delaytime);
Description
Returns the (continuous) signal x delayed for an absolute time (given by delaytime). The initial value
of y for time = 0 to delaytime is equal to zero. This block is intended to model a continuous delay in
a continuous simulation. Use the Unit Delay block to model a digital delay.
Examples
x = 10*sin(time*10);
y = tdelay(x,2);
Limitations
x,y and delaytime must be scalars. delaytime must be a positive constant value.
119
20-sim 4.0 Reference Manual
trunc
Syntax
Y = trunc(X);
Description
Rounds X or the elements of X towards zero (i.e. the function trunc removes the fraction) .
Examples
X trunc(X)
1 1
2.1 2
-2.6 -2
3.4 3
[1.1,-2.7;3.5,-4.1] [1,-3;3,-5]
Limitations
X and Y must have the same size.
hold
Syntax
y = hold(x,init);
Description
The hold function implements a zero order hold function operating at a specified sampling rate. It
provides a mechanism for creating a continuos output signal y out of a discrete input signal x. The
initial value of y is equal to the value of init.
Examples
x = sin(time*0.3);
y = sample(x);
z = previous(y);
u = hold(z,-1);
Limitations
x and y must be scalars. x be a discrete signal. y is a continuous signal. 20-sim will automatically
detect the existence of discrete signals. Each chain of discrete signals will be assigned a specific
sampletime. You can set this sample time to any desired value in the Simulator (choose Properties,
Simulation and Discrete System).
120
4. Language Reference
next
Syntax
y = next(x,init);
Description
The next function allows you to make constructs like:
where k is the kth sample. Using the next function, this can be entered in 20-sim as:
next(x,0) = x - 0.1 + u;
Limitations
x and y will become discrete signals. 20-sim will automatically detect the existence of discrete
signals. Each chain of discrete signalswill be assigned a specific sampletime. You can set this sample
time to any desired value in the Simulator (choose Properties, Simulation and Discrete System).
previous
Syntax
y = previous(x,init);
Description
The previous function delays the input signal x and holds it for one sample interval. It is equivalent to
the z-1 discrete time operator.
Examples
x = sin(time*0.3);
y = sample(x);
z = previous(y);
u = hold(z);
Limitations
x and y will become discrete signals. 20-sim will automatically detect the existence of discrete
signals. Each chain of discrete signalswill be assigned a specific sampletime. You can set this sample
time to any desired value in the Simulator (choose Properties, Simulation and Discrete System).
121
20-sim 4.0 Reference Manual
sample
Syntax
y = sample(x,init);
Description
The sample function implements a sample and hold function operating at a specified sampling rate. It
provides a mechanism for discretizing a continuous input signal. The initial value of y is equal to the
value of init. This initial value is optional. If no value is entered, a default initial value of 0 is used.
Examples
x = sin(time*0.3);
y = sample(x);
z = previous(y);
u = hold(z);
Limitations
x and y must be scalars. x represents a continuous signal and y represents a discrete signal.
y will become a discrete signals. 20-sim will automatically detect the existence of discrete
signals. Each chain of discrete signals will be assigned a specific sampletime. You can set
this sample time to any desired value in the Simulator (choose Properties, Simulation and
Discrete System).
event
Syntax
y = event(x);
Description
y becomes true when x is zero. This function forces the integration algorithm to find the exact point
where the input crosses zero. This is called a state event.
Examples
x = sin(time*omega +phi);
y = event(x);
Limitations
y must be a boolean, x must be an expression yielding a scalar.
122
4. Language Reference
eventdown
Syntax
y = eventdown(x);
Description
y becomes true when x is zero. This function forces the integration algorithm to find the exact point
where the input crosses zero from a positive to a negative value. This is called a state event.
Examples
x = sin(time*omega +phi);
y = eventdown(x);
Limitations
y must be a boolean, x must be an expression yielding a scalar.
eventup
Syntax
y = event(x);
Description
y becomes true when x is zero. This function forces the integration algorithm to find the exact point
where the input crosses zero from a negative to a positive value. This is called a state event.
Examples
x = sin(time*omega +phi);
y = eventup(x);
Limitations
y must be a boolean, x must be an expression yielding a scalar.
frequencyevent
Syntax
y = frequencyevent(p,o);
Description
y becomes true every time when p [s] have passed. The function starts after an offset of o [s]. The
offset parameter is optional. This function is a time event function.
Examples
parameters
real period = 0.1 {s};
real offset = 0.005 {s};
variables
boolean y,z;
equations
y = frequencyevent(1); // y = true every second
z = frequencyevent(period,offset); // z = true at 0.005 s, 0.105 s, 0.205 s etc.
Limitations
y must be a boolean, p and o must be a parameter or a constant.
123
20-sim 4.0 Reference Manual
timeevent
Syntax
y = timeevent(x);
Description
y becomes true when time is equal to x. This functions forces the integration algorithm to do a
caluculation when time y becomes true. This is a time event function
Examples
The example code below forces the integration algorithm, to do a calculation at the start of the step:
x = step(start_time);
y = timeevent(start_time);
Limitations
y must be a boolean, x must be an expression yielding a scalar.
equal
Syntax
equal([x1,x2, ...,xn]);
Description
This function is used to make all elements of a matrix equal. It returns the equations x2 = x1, x3 =
x1, .. , xn = x1. During processing the equations will be automatically reshaped into a proper causal
form. This function is created for use in library models that use a matrix with unknown size which
results from the collect function.
Examples
Suppose we have m bonds connected to a submodel, collected in a port p. We could then use the
function:
collect(p.e);
[p.e1;p.e2;...;p.n];
equal(collect(p.e));
equal([p.e1;p.e2;...;p.n]);
p.e2 = p.e1;
p.e3 = p.e1;
124
4. Language Reference
..
p.en = p.e1
Limitations
This function is designed for a special class of models and should be used by experienced users only!
mul
Syntax
y = mul([x1,x2, ...,xn]);
Description
This function is used for multiplication of variables of which one may be unknown. It returns the
equation y = x1 * x2 * .. * xn. During processing this equation will be automatically reshaped into a
causal form.
This function is created for use in library models that have unknown inputs such as MultiplyDivide
model. Try to avoid the use of this function!
Examples
equations after reshaping (processing)
x1 = 1; x1 = 1;
x2 = 2; x2 = 2;
1 = mul([x1,x2,x3]); x3 = (1/x1)/x2;
y = sin(time); y = sin(time);
x2 = 2; x2 = 2;
y = mul([x1,x2]); x1 = y/x2;
Limitations
This function is designed for a special class of models and should be used by experienced users only!
y, x1, x2, ..,xn must be scalars. n may be 1 or higher1
125
20-sim 4.0 Reference Manual
sum
Syntax
y = sum([x1,x2, ...,xn]);
Description
This function is used for summation of variables of which one may be unknown. It returns the
equation y = x1 + x2 + .. xn. During processing this equation will be automatically reshaped into a
causal form.
This function is created for use in library models that have unknown inputs such as PlusMinus model.
Try to avoid the use of this function!
Examples
equations after reshaping (processing)
x1 = 1; x1 = 1;
x2 = 2; x2 = 2;
0 = sum(x1,x2,x3); x3 = x1 + x2;
y = sin(time); y = sin(time);
x2 = 2; x2 = 2;
y = sum(x1,x2); x1 = y - x2;
Limitations
This function is designed for a special class of models and should be used by experienced
users only! y, x1, x2, ..,xn must be scalars. n may be 1 or higher.
Use the function msum if you want to use a standard summation of multiple variables.
126
4. Language Reference
data
Syntax
y = data(filename,column);
Description
This function generates an output by linear interpolation of data read from file. The data on file is
stored in columns. The first column contains the time values (t) and the second column contains the
corresponding output values (y).
The time data of the first column needs to be monotonically increasing.
Discontinuities are allowed, by providing the same time point twice in the table.
Values outside of the range, are computed by linear extrapolation of the last two points.
The first argument (filename) of this function must be a parameter of the type string and is used as
a reference to a filename. This reference can be specified using the complete path or relative to the
model directory. The second argument (column) of this function must be a parameter of the type
integer denoting a whole number. It is used to denote the column number.
table (example):
0 -0.5
0.5 -1
2.5 -1
3.5 0
4.5 1
5.5 1.75
7 2.5
8 2.5
The input file must be an ASCII (text) file and should consist at least two columns of data. The first
column (number 0) should always contain the time values. The other columns (number 1, 2, 3, etc.)
should contain the corresponding data values. The parameter column is used to specify which column
is used for as output data.
The various values must be separated by a space or a tab. Each new set of time and data values
must start on a new line. No comment or other text may be part of the file. The filename of the input
file can be specified using the complete path (e.g. c:\data\data.tbl ). When no path is given, the file
is assumed to be in the experiment directory.
Examples
parameters
string filename = 'data.txt';
integer col = 1;
variables
real y;
equations
y = data(filename,col);
Limitations
y must be a scalar. from_file must be string parameter. x must be an integer parameter.
127
20-sim 4.0 Reference Manual
dll
Syntax
Y = dll(filename,functionname,X);
Description
Given a function (functionname) of a dll (filename), the dll function returns the output values (X) for
a given input (Y).
Users can write their own source code using a native compiler such as Visual C++ or Borland C++.
With these compilers it is possible to create DLL’s with user defined functions that have an input-
output relation which can be embedded in simulation code.
Examples
parameters
string filename = 'example.dll';
string function = 'myFunction';
variables
real x[2],y[2];
equations
x = [ramp(1);ramp(2)];
y = dll(filename,function,x);
Limitations
filename and functionname must be string parameters. Note that the size of Y and X (scalars or
matrices) must correspond with the size that is expected for the given dll-function.
Search Order
20-sim uses the following search order for the dll-file:
The simplest place to put the dll-file is the bin directory, but it is always possible to give a complete
path for the dll filename.
128
4. Language Reference
dlldynamic
Syntax
Y = dlldynamic(filename,functionname,X);
Description
Given a function (functionname) of a dll (filename), the dll function returns the output values (X) for
a given input (Y). Users can write their own source code using a native compiler such as Visual C++
or Borland C++. With these compilers it is possible to create DLL’s with user defined functions that
have an input- output relation which can be embedded in simulation code.
Examples
parameters
string dllName = 'demoDynamicDll.dll';
string functionName = 'SFunctionCalculate';
variables
real x[2],y[2];
equations
x = [ramp(1);ramp(2)];
y = dlldynamic(dllName,functionName,x);
Limitations
The filename and functionname must be string parameters. Note that the size of Y and X (scalars or
matrices) must correspond with the size that is expected for the given dll-function.
Search Order
20-sim uses the following search order for the dll-file:
The simplest place to put the dlldynamic-file is the bin directory, but it is always possible to give a
complete path for the dll filename.
129
20-sim 4.0 Reference Manual
table
Syntax
y = table(file_name,x);
Description
This model uses a one-dimensional table with data points to calculate the output y = f(x) as a
function of the input x. The output y is calculated using linear interpolation between the table data
points.
The input data x of the first column needs to be monotonically increasing.
Discontinuities are allowed, by providing the same input point twice in the table.
Values outside of the table range, are computed by linear extrapolation of the last two
points.
The first argument (file_name) of this function must be a parameter of the type string and is used as
a reference to a filename. This reference can be specified using the complete path or relative to the
model directory. The second argument (x) should be a real variable.
table (example):
-2.5 -0.5
-2 -1
0 -1
1 0
2 2
3 3.0
5 4
6 4.0
A table must be stored as an ASCII (text) file and should consist two columns of data. The first
column consists of the x-values and the second column of the corresponding y-values. Each line of
the file may only contain one x- and one corresponding y-value. The two values must be separated
by a space or a tab. Each new set of x- and y-values must start on a new line. No comment or other
text may be part of the table-file.
Examples
parameters
string filename = 'data.txt';
variables
real y;
real x;
equations
x = ramp(1);
y = table(filename,x);
Limitations
x and y must be scalars. from_file must be string parameter.
130
4. Language Reference
Adjoint
Syntax
A = Adjoint(H);
A = Adjoint(R,P);
Description
Returns the adjoint matrix [6,6] of a homogeneous matrix [4,4]:
or returns the adjoint matrix [6,6] of a a rotation matrix R[3,3] and position vector P[3]:
The Adjoint function is useful for dynamics described by twists and wrenches.
Examples
Limitations
H must be of size [4,4], R must always be of size[3,3] , P must have the size [3,1] and A must have
size [6,6].
131
20-sim 4.0 Reference Manual
adjoint
Syntax
Y = adjoint(T);
Y = adjoint(W,V);
Description
Returns the adjoint matrix [6,6] of of a twist or wrench vector T [6,1]:
or returns the adjoint matrix [6,6] of an angular velocity vector W [3,1] and a velocity vector V
[3,1]:
The adjoint function is useful for dynamics described by twists and wrenches.
Examples
W = [w1 ; w2 ; w3];
V = [v1 ; v2 ; v3];
Y = adjoint(W,V);
Limitations
Y must be of size [6,6], W must always be of size[3,1] , V must have the size [3,1] and T must have
size [6,1].
132
4. Language Reference
antisym
Syntax
y = antisym(A);
Description
Returns an anti-symmetric matrix. This function is equal to:
y = (A - transpose(A))/2;
Examples
A = [1,2;3,4];
Y = antisym(A);
Limitations
A must be a square matrix. Y and A must be of the same size.
columns
Syntax
y = columns(A);
Description
Returns the number of columns of A.
Examples
A = [1,2;3,4;5,6];
y = columns(A);
Limitations
y must be a scalar.
cross
Syntax
Y = cross(A,B);
Description
This functions returns the vector cross product of the vectors A and B. That is Y = A × B or:
133
20-sim 4.0 Reference Manual
det
Syntax
y = det(A);
or
Y = |A|;
Description
Returns the determinant of the square matrix A.
Examples
A = [1,2;3,ramp(1)];
y = det(A);
Limitations
A must be a square matrix, y must be a scalar.
Diag
Syntax
Y = diag(x);
Description
Fills the diagonal elements of the matrix Y with the elements of the columvector x.
Example
variables
real x[3];
real Y[3,3];
equations
x = [1;2;3];
Y = diag(x);
Limitations
Y must be a matrix of size [n,n]. x must be a columnvector of size n.
eye
Syntax
Y = eye(n);
Description
Returns the the n-by-n identity matrix.
Example
Y = eye(3);
Limitations
Y must be a matrix of size [n,n]. n must be an integer value.
134
4. Language Reference
homogeneous
Syntax
H = homogeneous(R,P);
Description
Returns the homogenous matrix [4,4] of a rotation matrix R[3,3] and position vector P[3]:
The homogeneous matrix gives a full coordinate transformation from one reference frame to another.
It can be used for 3D dynamics.
Examples
Limitations
R must always be of size[3,3] , P must have the size [3,1] and H must have size [4,4].
inner
Syntax
y = inner(A,B);
Description
Returns the scalar product of the column vectors A and B. A and B must be vectors of the same
length. Inner(A,B) is the same as transpose(A)*B.
Example
A[3] = [1;2;3];
B[3,1] = [4;5;6];
y = inner(A,B);
Limitations
A and B must be vectors of the same size [n,1] or [n]. y must be a scalar.
135
20-sim 4.0 Reference Manual
inverse
Syntax
Y = inverse(A);
Description
Returns the inverse of square non-singular matrix A.
Examples
A = [1,0;0,1+ramp(1)];
Y = inverse(A);
Limitations
A must be a non-singular square matrix. Y must have the same size as A.
inverseH
Syntax
Y = inverseH(H);
Y = inverseH(R,P);
Description
Returns the inverse of a homogeneous matrix H [4,4]. The homogeneous matrix can be entered
directly or by a rotation matrix R[3,3] and position vector P [3,1].
This function uses the special nature of a homogeneous matrix. I.e the inverse can be computed
directly instead of the numerical approach of the standard inverse function.
Examples
or
136
4. Language Reference
linsolve
Syntax
x = linsolve(A,b [,method]);
Description
This function solves the equation
A*x = b;
Where A is a square matrix of arbitrary size n and x and b are vectors of size n.
Returns the inverse of square non-singular matrix A.
The last argument is a string that specifies the desired method to use.
method description
lu LU decomposition (default method)
qr QR factorization
cholesky Cholesky factorization
gmres Generalized Minimum Residual
The gmres method allows further steering of the method by specifying method parameters:
method parameter description
tol Set the desired tolerance to use
maxiter Set the maximum number of iterations to use
ortho Set the method of Gramm-Schmidt orthogonalization:
1 modified Gramm-Schmidt
2 iterative Gramm-Schmidt
3 classical Gramm-Schmidt
4 iterative classical Gramm-Schmidt
Examples
A = [1,2;0,1+ramp(1)];
b = [1;5];
x = linsolve(A,b);
x2 = linsolve (A, b, 'qr');
x3 = linsolve (A, b, 'gmres tol=1e-8 ortho=4');
Limitations
A must be a non-singular square matrix.
Note
The following equations
A*x = b;
x = inverse(A)*b;
x = (A^-1)*b;
137
20-sim 4.0 Reference Manual
all lead in the calculation of the inverse of A and will give the same result as
x = linsolve(A,b);
For the inverse calculation, Cramers rule is used. This is a method which is fast for small matrix
sizes. The linsolve function with the gmres method is superior to Cramers rule for larger matrix sizes.
max
Syntax
y = max(A);
Description
Returns the value of the largest matrix element of A.
Examples
A = [1,2;3,ramp(1)];
y = max(A);
Limitations
y must be a scalar.
min
Syntax
y = min(A);
Description
Returns the value of the smallest matrix element of A.
Examples
A = [1,2;3,ramp(1)];
y = min(A);
Limitations
y must be a scalar.
msum
Syntax
y = msum(A);
Description
Returns the sum of the matrix elements of A.
Examples
A = [1,2;3,4;5,6];
y = msum(A);
Limitations
y must be a scalar.
138
4. Language Reference
norm
Syntax
y = norm(A);
or
Y = ||A||;
Description
Returns the square root of the sum of the squared matrix elements of A:
Examples
A = [1,2;3,ramp(1)];
y = norm(A);
Limitations
y must be a scalar.
norminf
Syntax
y = norminf(A);
Description
Returns the largest row sum of A with a row sum equal to:
Examples
A = [1,2;3,ramp(1)];
y = norminf(A);
Limitations
y must be a scalar.
rows
Syntax
y = rows(A);
Description
Returns the number of rows of A.
Examples
A = [1,2;3,4;5,6];
y = rows(A);
Limitations
y must be a scalar.
139
20-sim 4.0 Reference Manual
skew
Syntax
Y = skew(X);
Description
Returns the vector product:
Examples
Limitations
X must be a vector of size n. Y must be a matrix of size [n,n].
sym
Syntax
y = sym(A);
Description
Returns a symmetric matrix. This function is equal to:
y = (A + transpose(A))/2;
Examples
A = [1,2;3,4];
Y = sym(A);
Limitations
A must be a square matrix. Y and A must be of the same size.
140
4. Language Reference
tilde
Syntax
H = tilde(T);
H = tilde(W,V);
Description
Returns the twist matrix [4,4] of a twist or wrench vector T [6,1]:
Or returns the twist matrix [4,4] of an angular velocity vector W [3,1] and a velocity vector V [3,1]:
The tilde function is useful for dynamics described by twists and wrenches.
Examples
W = [w1 ; w2 ; w3];
V = [v1 ; v2 ; v3];
H = tilde(W,V);
Limitations
H must be of size [4,4], W must always be of size[3,1] , V must have the size [3,1] and T must have
size [6,1].
trace
Syntax
y = trace(A);
Description
Returns the sum of the diagonal elements of the matrix A.
Examples
A = [1,2,3;4,ramp(1),6];
y = trace(A);
Limitations
y must be a scalar.
141
20-sim 4.0 Reference Manual
transpose
Syntax
Y = transpose(A);
Description
Returns the transpose of the matrix A.
Examples
A = [1,2;3,ramp(1)];
Y = transpose(A);
Limitations
With the A matrix of size[n,m] , Y must have the size [m,n].
collect
Syntax
y = collect(p.e);
y = collect(p.f);
y = collect(m);
For example the PlusMinus model can have n signals that must be added and m signals that must be
subtracted. 20-sim treats them as an array plus and an array minus with:
To assign an array of unknown length, the collect function is used. It creates an array with port
variables or signals. This function is created for use in library models that have an unknown amount
of bonds or signals connected. Try to avoid the use of this function!
Examples
Suppose we have m bonds connected to a submodel, collected in a port p. We could then use the
equation:
Y = collect(p.e);
Y = [p.e1;p.e2;...;p.n];
Suppose we have a submodel with n input signals connected. We could then write the equation:
y = sum(collect(input));
142
4. Language Reference
y = sum([output1;output2;...;outputn]);
direct
Syntax
y = direct(p.e);
y = direct(p.f);
(with p.e and p.f powerportvariables)
Description
This function is equal to the collect function, but utilizes the direction of the bonds connected to the
submodel to sign the powerportvariables. This function is created specially for the bond graph
submodels OneJunction.emx and ZeroJunction.emx. Try to avoid the use of this function!
Examples
Suppose we have 4 bonds connected to a 0-junction, collected in a port p. p1 and p4 are pointing
towards the junction and p2 and p3 are pointing from the 0-junction. We could then use the
equation:
Y = direct(p.f);
Y = [p.f1;-p.f2;-p.f3,p.f4];
sum(Y) = 0;
143
20-sim 4.0 Reference Manual
first
Syntax
y = first(p.e);
y = first(p.f);
y = first(m);
The function first returns the value of the first element of an array of unknown length. This function
is created for use in library models that have an unknown amount of bonds or signals connected. Try
to avoid the use of this function!
Examples
Suppose we have m bonds connected to a submodel, collected in a port p. We could then use the
equation:
y = first(p.e);
y = p.e1;
Limitations
This function is designed for a special class of models and should be used by experienced users only!
The function is only valid when used in a submodel.
144
4. Language Reference
gauss
Syntax
y = gauss(x,s);
Description
Returns gaussian noise with uniform distribution and variance x and seed s. The seed parameter is
optional. When omitted, the default value (0) is used.
Examples
x = 20;
y = gauss(x);
z = gauss(x,450);
Limitations
x and y must be scalars.The seed s must be a number in the region <0,65535>.
ramp
Syntax
y = ramp(x);
Description
Returns a ramp signal with start time x:
time < x: y = 0
time >= x: y is time - x
Examples
x = 20, amplitude = 10;
y = amplitude*ramp(x);
Limitations
x and y must be scalars.
ran
Syntax
y = ran(x,s);
Description
Returns uniformly distributed noise in the interval [-x,x] with seed s. The seed parameter is optional.
When omitted, the default value (0) is used.
Examples
x = 20;
y = ran(x);
z = ran(x,450);
Limitations
x and y must be scalars. The seed s must be a number in the region <0,65000>.
145
20-sim 4.0 Reference Manual
seed
20-sim generates a sequence of random numbers for each simulation differently depending upon the
value of the seed parameter. The random noise function and gaussian noise function are affected by
this. The default value of the seed is 0. The maximum value is 65535.
default value (0)
When the seed value is 0 (default value), 20-sim generates a new sequence of random numbers for
each simulation and for each new random function. E.g. when two random functions with default
seed value (0) are used in one model, they will generate different sequences of random numbers
during a simulation.
other values (>0)
When the seed value is chosen larger than zero, 20-sim generates the same sequence of random
numbers for each simulation. Moreover 20-sim will generate the same sequence of random numbers
for each random function that uses the same seed parameter (>0). E.g. when two random functions
with seed value 50, are used in one model, they will generate the same sequence of random
numbers during a simulation.
step
Syntax
y = step(x);
Description
Returns a step signal with start time x:
time < x: y = 0
time >= x: y = 1
Examples
x = 20, amplitude = 10;
y = amplitude*step(x);
Limitations
x and y must be scalars.
arcsin
Syntax
Y = arcsin(X);
Description
Returns the arcsine of the elements of X.
Examples
b = cos(time);
a = arcsin(b);
X = [0.5*cos(time);0.75*cos(time)];
Y = arcsin(X);
Limitations
Y and X must have the same size. The elements of X must be in the range [-1 ,1].
146
4. Language Reference
arccos
Syntax
Y = arccos(X);
Description
Returns the arccosine of the elements of X.
Examples
b = sin(time);
a = arccos(b);
X = [0.5*sin(time);0.75*sin(time)];
Y = arccos(X);
Limitations
Y and X must have the same size. The elements of X must be in the range [-1 ,1].
arccosh
Syntax
Y = arccosh(X);
Description
Returns the hyperbolic arccosine of the elements of X.
Examples
b = sin(time);
a = arccos(b);
X = [0.5*sin(time);0.75*sin(time)];
Y = arccosh(X);
Limitations
Y and X must have the same size.
arcsinh
Syntax
Y = arcsinh(X);
Description
Returns the hyperbolic arcsine of the elements of X.
Examples
b = cos(time);
a = arcsin(b);
X = [0.5*cos(time);0.75*cos(time)];
Y = arcsinh(X);
Limitations
Y and X must have the same size.
147
20-sim 4.0 Reference Manual
arctan
Syntax
Y = arctan(X);
Description
Returns the arctangent of the elements of X.
Examples
b = ramp(1);
a = arctan(b);
X = [ramp(1);-0.5*ramp(9)];
Y = arctan(X);
Limitations
Y and X must have the same size.
arctanh
Syntax
Y = arctanh(X);
Description
Returns the hyperbolic arctangent of the elements of X.
Examples
b = ramp(1);
a = arctan(b);
X = [ramp(1);-0.5*ramp(9)];
Y = arctanh(X);
Limitations
Y and X must have the same size.
atan2
Syntax
Y = atan2(A,B);
Description
This is the four quadrant arctangent of the elements of A and B.
Examples
a = sint(time);
b = cos(time);
y = atan2(a,b);
A = [ramp(0);ramp(1)];
B = [1;1];
Y = atan2(A,B);
Limitations
y, a and b must have the same size.
148
4. Language Reference
cos
Syntax
Y = cos(X);
Description
Returns the cosine of the elements of X.
Examples
b = ramp(2.5);
a = cos(b);
X = [ramp(0);ramp(1)];
Y = cos(X);
Limitations
Y and X must have the same size.
cosh
Syntax
Y = cosh(X);
Description
Returns the hyperbolic cosine of the elements of X.
Examples
b = ramp(2.5);
a = cos(b);
X = [ramp(0);ramp(1)];
Y = cosh(X);
Limitations
Y and X must have the same size.
sin
Syntax
Y = sin(X);
Description
Returns the sine of the elements of X.
Examples
b = ramp(2.5);
a = sin(b);
X = [ramp(0);ramp(1)];
Y = sin(X);
Limitations
Y and X must have the same size.
149
20-sim 4.0 Reference Manual
sinh
Syntax
Y = sinh(X);
Description
Returns the hyperbolic sine of the elements of X.
Examples
b = ramp(2.5);
a = sin(b);
X = [ramp(0);ramp(1)];
Y = sinh(X);
Limitations
Y and X must have the same size.
tanh
Syntax
Y = tanh(X);
Description
Returns the hyperbolic tangent of the elements of X.
Examples
b = ramp(2.5);
a = tan(b);
X = [ramp(0);ramp(1)];
Y = tanh(X);
Limitations
Y and X must have the same size.
tan
Syntax
Y = tan(X);
Description
Returns the tangent of the elements of X.
Examples
b = ramp(2.5);
a = tan(b);
X = [ramp(0);ramp(1)];
Y = tan(X);
Limitations
Y and X must have the same size.
150
4. Language Reference
4.5 Operators
Operators
In 20-sim you can use the following operators equations:
Operator Description
* Multiplication
+ Addition
- Subtraction
.* ArrayMultiplication
./ ArrayDivision
.^ ArrayPower
/ Division
div Integer division
% or mod Modulus operator
^ Power
and Boolean and
or Boolean or
xor Boolean exclusive or
< Less than
<= Less than or equal
<> Not equal
== Equal
>= Larger than or equal
> Larger than
- Prefix Minus Sign
+ Prefix Plus Sign
not Prefix Boolean Not
| .. | Absolute / Determinant / Norm
151
20-sim 4.0 Reference Manual
Multiplication (*)
Syntax
A*B
Description
A * B multiplies A with B. For nonscalar A and B, the number of columns of A must equal the number
of rows of B. If C = A*B then the elements of C can be calculated out of the matrix elements of A
and B as:
Limitations
For nonscalar A and B, the number of columns of A must equal the number of rows of B.
Addition (+)
Syntax
A+B
Description
A + B adds A and B. A and B must have the same size, unless one is a scalar. A scalar can be added
to a matrix of any size.
152
4. Language Reference
Examples
A B A+B
1 3 4
2.1 -3.2 -1.1
[1,2;3,4] [1,1;5,5] [2,3;8,9]
2 [1,2;3,4] [3,4;5,6]
[1,2;3,4] 4 [5,6;7,8]
[1,2;3,4] [5,6;7,8;9,10] not allowed!
Limitations
If A and B are matrices, they must have the same size.
Subtraction (-)
Syntax
A-B
Description
A - B subtracts B from A. A and B must have the same size, unless one is a scalar. A scalar can be
subtracted from a matrix of any size.
Examples
A B A-B
5 3 2
-4.2 5.5 -9.7
[4,5;6,7] [1,1;5,5] [3,4;1,2]
[4,5;6,7] 4 [0,1;2,3]
4 [4,5;6,7] not allowed!
Limitations
A and B must have the same size.
153
20-sim 4.0 Reference Manual
Limitations
A and B must have the same size.
Limitations
A and B must have the same size.
154
4. Language Reference
Division (/)
Syntax
A/B
Description
A / B divides A by B. For a nonscalar B, A/B equals A*inverse(B). For a nonscalar A, each element of
A is divided by the scalar B.
Examples
A B A/B
15 3 5
-40.5 5 -8.1
2 [1,2;3,4] [-4,2;3,-1]
[1,-2;-3,4] 4 [0.25,-0.5;0.75,1]
[2,0;0,2] [1,2;3,4] [-4,2,3,-1]
1 0 not allowed!
1 [1,2,3;4,5,6] not allowed!
Limitations
If A and B are matrices, they must have the same size. If B is a matrix and it becomes singular,
simulation is stopped.
Limitations
a and b must be scalars.
155
20-sim 4.0 Reference Manual
Limitations
a and b must be scalars.
Power (^)
Syntax
A^b
Description
A ^ B raises A to the power B. For a nonscalar A and integer B, A^B is computed by repeated
multiplication of A. If B is negative A is inverted first. If B is zero, A^B is the identity matrix. For
other values of B, it is rounded to its nearest integer value. Making B a nonscalar is not allowed.
Examples
A b A^b
5 3 125
4 -2.1 0.054409
5.5 0 1
3 2.1 10.04511
[2,0;0,2] 4 [16,0;0,16]
[1,2,3,4] -2.1 [5.5,-2.5;-3.75,1.75]
[1,2,3,4] 0 [1,0;0,1]
[1,2,3,4] [1,2;3,4] not allowed!
Limitations
b must be a scalar. For a matrix A, b is rounded to the nearest integer value value.
156
4. Language Reference
Limitations
a and b must be scalars.
Boolean Or (or)
Syntax
a or b
Description
a or b performs a logical OR between a and b. If a or b are not booleans, 0 represents a logical false
and any nonzero value represents a logical true. The truth table for this operator is shown below.
Table
a b a or b
false false false
false true true
true false true
true true true
Limitations
a and b must be scalars.
157
20-sim 4.0 Reference Manual
Limitations
a and b must be scalars.
Limitations
a and b must be scalars.
158
4. Language Reference
Limitations
a and b must be scalars.
Limitations
a and b must be scalars.
159
20-sim 4.0 Reference Manual
Equal (==)
Syntax
a == b
Description
The == operator compares two arguments and yields a boolean. If a is equal to b, then a==b yields
true. If a is not equal to b, then a==b yields false. It is typically used in an if-statement.
Example
a b a == b
1 1 true
1.01e2 101.0 true
31 1 false
true false false
Note
The normal equal sign (=) should only be used for equations. The equal sign (=) makes the left side
of an equation equal to the right side. This is different to the equal statement (==) which compares
two arguments and yields a boolean.
Limitations
a and b must be scalars.
160
4. Language Reference
Limitations
a and b must be scalars.
Limitations
a must be a boolean.
161
20-sim 4.0 Reference Manual
162
4. Language Reference
4.6 Statements
Statements
Statements are important to guide the flow of information in equation models. 20-sim supports the
following statements:
1. For to Do
2. If Then
3. If Then Else
5. Repeat Until
6. Switch Case
7. Stopsimulation
8. Warning
9. While Do
10. toMatlab
11. fromMatlab
12. doMatlab
13. Effortincausality
14. Flowincausality
163
20-sim 4.0 Reference Manual
If Then
Syntax
if condition then
equation;
....
end;
Description
The simplest if statement evaluates a condition and performs the specified equation(s) if the
condition is true. If the condition is not true, 20-sim ignores the equation(s).
Examples
b = false;
y = ramp(1);
u = -ramp(1);
if time > 5 then
y = -ramp(1); // equations to be executed if condition is true,
u = ramp(1); // these are not executed if condition is false
end;
if time == 10 then // note the use of the equal operator ==
b = true; // equations to be executed if condition is true,
end;
Limitations
1. The output of the condition must be a boolean.
2. If needed, always use the equal operator (==) in the condition.
Note
1. Take care when using event functions in if-then-else statements. In if-then-else statements
only the equations of the true parts are evaluated, so event functions may not always be
triggered!
2. Equations within an if statement have to be written in the correct order of execution, i.e.
they are not rewritten into a causal form but executed sequentially.
164
4. Language Reference
If Then Else
Syntax
if condition then
equation;
...
else
equation;
...
end;
Description
The if-then-else statement evaluates a condition and performs the first set of equation(s) if the
condition is true and the second set of equation(s) if the condition is false. If the condition is true,
20-sim ignores the second set of equation(s). If the condition is false, 20-sim ignores the first set of
equation(s).
Nesting
If-then-else statements may be nested as many times as desired. Do not forget to included the word
"end;" to finish every nested statement!
Examples
y = step(1);
u = -step(1);
if time > 5 then
y = -ramp(1); // equations to be executed if condition is true,
u = ramp(1); // these are not executed if condition is false
else
y = ramp(1); // equations to be executed if condition is false,
u = -ramp(1); // these are not executed if condition is true
end;
//Nesting
if time < 5 then
a = 1;
b = sin(time*1);
else
if time == 5 then
a = 2;
b = sin(time*2);
else
a=3
b=sin(time*3);
end;
end;
Limitations
1. The output of the condition must be a boolean.
2. If needed, always use the equal operator (==) in the condition.
165
20-sim 4.0 Reference Manual
Note
1. Take care when using event functions in if-then-else statements. In if-then-else statements
only the equations of the true parts are evaluated, so event functions may not always be
triggered!
3. Equations within an if statement have to be written in the correct order of execution, i.e. they
are not rewritten into a causal form but executed sequentially.
// Nesting:
x = if time < 1 then
1
else
if time < 2 then
2
else
if time == 2 then
1
else
0
end
end
166
4. Language Reference
end;
Limitations
1. The output of the condition must be a boolean.
2. If needed, always use the equal operator (==) in the condition.
Note
1. Take care when using event functions in if-then-else expressions. In if-then-else expressions
only the equations of the true parts are evaluated, so event functions may not always be
triggered!
3. Equations within an if statement have to be written in the correct order of execution, i.e. they
are not rewritten into a causal form but executed sequentially.
167
20-sim 4.0 Reference Manual
For To Do
Syntax
for variable = start to stop by step do
equation;
equation;
....
end;
Description
The for statement is designed to execute equation(s) a fixed number of times. It begins with the
keyword for and an expression that specifies the number of times the equations within the for
statement should be executed. The for statement ends with the keyword end. The default increment
in a for statement is one (1), but you can use the keyword by to adjust the increment.
The equations within the for statement are always executed once. The for statement stops when the
variable has exceeded the stop value.
Examples
variables
real i,y[10];
equations
for i = 1 to 2 do
// executed 2 times: y[1] and y[2]
y[i] = ran (1);
end;
for i = 2 to 4.1 by 2 do
// executed 3 times: y[2], y[4] and y[6]
y[i] = ran (1);
end;
Limitations
1. The start, stop and step values must be scalars. The step value is optional. There are no
limitations to the number of equations that can be used within the for statement.
2. Equations within an for statement have to be written in the correct order of execution, i.e.
they are not rewritten into a causal form but executed sequentially.
168
4. Language Reference
While Do
Syntax
while condition do
equation;
equation;
....
end;
Description
The while statement is designed to execute equation(s) repeatedly, as long as the condition is true.
The condition is evaluated before the equations are executed.
It is the user's responsibility to guarantee that the execution of the while statement finishes by
making the condition become false at a certain time.
Examples
variables
real i,y[10];
equations
i = 1;
while i < 3 do
// executed 2 times: y[1] and y[2]
y[i] = ran (1);
// i is incremented to guarantee a stop of the loop
i = i+1;
end;
Limitations
1. The output of the condition must be a boolean. If the boolean does not become false, the loop
never ends! There are no limitations to the number of equations that can be used within the
while statement.
2. Equations within an while statement have to be written in the correct order of execution, i.e.
they are not rewritten into a causal form but executed sequentially.
169
20-sim 4.0 Reference Manual
Repeat Until
Syntax
repeat
equation;
equation;
....
until condition;
Description
The repeat statement is designed to execute equation(s) repeatedly, as long as the condition is true.
The condition is evaluated after the equations are executed.
It is the user's responsibility to guarantee that the execution of the repeat statement finishes by
making the condition become false at a certain time.
Examples
variables
real i,y[10];
equations
i = 1;
repeat
// executed 2 times: y[1] and y[2]
y[i] = ran (1);
// i is incremented to guarantee a stop of the loop
i = i+1;
until i > 2;
Limitations
1. The output of the condition must be a boolean. If the boolean does not become false, the
loop never ends! There are no limitations to the number of equations that can be used
within the repeat statement.
2. If needed, always use the equal operator (==) in the condition.
3. Equations within an repeat statement have to be written in the correct order of execution,
i.e. they are not rewritten into a causal form but executed sequentially.
170
4. Language Reference
Switch Case
Syntax
switch variable
case condition1 do
equations;
case condition2 do
equations;
default do
equations;
end;
Description
The switch case statement is designed to execute equation(s) based on the condition of a variable.
Only the equations of the valid branch are executed. If non of the branches is valid, the equations of
the default branch are executed.
Limitations
1. The switch variable should not be changed inside one of the branches.
2. Equations within an switch case statement have to be written in the correct order of
execution, i.e. they are not rewritten into a causal form but executed sequentially. Therefore
it is advise only to use this statement in a code section.
171
20-sim 4.0 Reference Manual
Stopsimulation
Syntax
stopsimulation ('string');
Description
The stopsimulation function stops the simulation as soon as it comes to action. It is useful when used
in combination with an if statement. As soon as the simulation stops, the log window will appear
showing the string that is used in the function.
Examples
if x == 0 then
stopsimulation('division by zero: y could not be calculated');
else
y = 1/x;
end;
Warning
Syntax
warning ('string',boolean);
Description
The warning function displays a message in the the log window. You can choose to display the string
once (boolean = true) or every simulation step (boolean = false). It is advised to use the warning
function in combination with an if-then statement or event-function.
Examples
172
4. Language Reference
toMatlab
Syntax
toMatlab(<20-sim variable>)
toMatlab(<20-sim variable>, 'string')
Description
The toMatlab statement allows you to pass a variable from 20-sim to Matlab. If no string is passed
the variable will be assigned the name of the 20-sim variable. If a string is passed the variable name
will be equal to the string.
Example
// this example shows how a variable can be transferred to matlab during simulation
variables
real x;
// at the start of the simulation
initialequations
// create an empty array a
doMatlab ('a = []; ');
// create an variable
doMatlab ('b=0; ');
// during simulation
equations
// calculate x
x = sin (time);
// send it to Matlab
toMatlab (x,'x');
// and add it to array a
doMatlab ('a = [ a x ]; ');
// in Matlab add 2 to x
doMatlab ('b = x + 2;');
// read b
fromMatlab(y,'b');
// at the end of the simulation
finalequations
// plot the resulting array in Matlab
doMatlab (' plot (a); ');
Note
Matlab is automatically started when this statement is called for the first time. If Matlab does not
start up check if you have specified the Matlab path properly in the General Properties Editor.
173
20-sim 4.0 Reference Manual
doMatlab
Syntax
doMatlab()
Description
The doMatlab statement allows you to pass a command line string to Matlab.
Example
// this example shows how a variable can be transferred to matlab during simulation
variables
real x;
// at the start of the simulation
initialequations
// create an empty array a
doMatlab ('a = []; ');
// create a variable
doMatlab ('b=0; ');
// during simulation
equations
// calculate x
x = sin (time);
// send it to Matlab
toMatlab (x);
// and add it to array a
doMatlab ('a = [ a x ]; ');
// in Matlab add 2 to x
doMatlab ('b = x + 2;');
// read b
fromMatlab(y,'b');
// at the end of the simulation
finalequations
// plot the resulting array in matlab
doMatlab (' plot (a); ');
Note
Matlab is automatically started when this statement is called for the first time. If Matlab does not
start up check if you have specified the Matlab path properly in the General Properties Editor.
174
4. Language Reference
fromMatlab
Syntax
fromMatlab(<20-sim variable>)
fromMatlab(<20-sim variable>, 'string')
Description
The toMatlab statement allows you to pass a variable from 20-sim to Matlab. The fromMatlab
statement allows you to pass a variable from Matlab to 20-sim. If no string is passed a variable will
be passed with the name of the 20-sim variable. If a string is passed the variable will be passed that
is named equal to the string.
Example
// this example shows how a variable can be transferred to matlab during simulation
variables
real x;
// at the start of the simulation
initialequations
// create an empty array a
doMatlab ('a = []; ');
// create an variable
doMatlab ('b=0; ');
// during simulation
equations
// calculate x
x = sin (time);
// send it to Matlab
toMatlab (x);
// and add it to array a
doMatlab ('a = [ a x ]; ');
// in Matlab add 2 to x
doMatlab ('b = x + 2;');
// read b
fromMatlab(y,'b');
// at the end of the simulation
finalequations
// plot the resulting array in matlab
doMatlab (' plot (a); ');
Note
1. Matlab is automatically started when this statement is called for the first time. If Matlab does
not start up check if you have specified the Matlab path properly in the General Properties
Editor.
175
20-sim 4.0 Reference Manual
Effortincausality
Syntax
effortincausality (portname) then
equation;
equation;
...
else
equation;
equation;
...
end;
Description
The effortincausality statement evaluates if a port has causality effort in and performs the first set of
equation(s) if the condition is true and the second set of equation(s) if the condition is false. If the
condition is true, 20-sim ignores the second set of equation(s). If the condition is false, 20-sim
ignores the first set of equation(s).
Depending on the domain you are working in, effort and flow correspond to particular variables. The
table below shows the variables for the domains that are currently supported in 20-sim.
Examples
effortincausality p then
R = if p.u > 0 then Ron else Roff end; // executed if causality of port p is effort (u) in
else
R = if p.i > 0 then Ron else Roff end; // executed if causality of port p is flow (i) in
end;
p.i = p.u/R;
176
4. Language Reference
Note
1. Take care when using event functions in effortincausality statements. In this statement only
the equations of the true parts are evaluated, so event functions may not always be
triggered!
3. Equations within an effortincausality have to be written in the correct order of execution, i.e.
they are not rewritten into a causal form but executed sequentially.
Flowincausality
Syntax
flowincausality (portname) then
equation;
equation;
...
else
equation;
equation;
...
end;
Description
The effortincausality statement evaluates if a port has causality flow in and performs the first set of
equation(s) if the condition is true and the second set of equation(s) if the condition is false. If the
condition is true, 20-sim ignores the second set of equation(s). If the condition is false, 20-sim
ignores the first set of equation(s).
Depending on the domain you are working in, effort and flow correspond to particular variables. The
table below shows the variables for the domains that are currently supported in 20-sim.
177
20-sim 4.0 Reference Manual
Examples
flowincausality p then
R = if p.i > 0 then Ron else Roff end; // executed if causality of port p is flow (i) in
else
R = if p.u > 0 then Ron else Roff end; // executed if causality of port p is effort (u) in
end;
p.u = p.i*R;
Note
1. Take care when using event functions in effortincausality statements. In this statement only
the equations of the true parts are evaluated, so event functions may not always be
triggered!
2. There is also an effortincausality statement.
3. Equations within an effortincausality have to be written in the correct order of execution, i.e.
they are not rewritten into a causal form but executed sequentially.
178
4. Language Reference
parameters
real A[3,3], B[3,3];
integer C[2,2] = [1,3;5,7];
real K[4] = [1;2;3;4];
variables
real K[4],L[4],D[4,5];
integer M[2,2],N[2,2];
Matrix Notation
Matrix sizes in 20-sim are always denoted by [n,m] where n is the numbers of rows and m is the
numbers of columns. Elements can separately be denoted with commas (,) distinguishing between
row elements and semicolons (;) distinguishing between rows.
Column vectors are matrices with only one column. Consequently the column size may be omitted in
the notation.
column size column form 20-sim notation
[4] 1 [1;3;5;7]
3
5
7
179
20-sim 4.0 Reference Manual
Matrix Use
Matrices and Vectors can be used in equations just like scalars. If possible, the element notation can
be left out. If equations get ambiguous, element notation must be used!
Whole matrix or vector
K = 1; // Make all elements of K equal to 1.
M = C; // Make matrix M equal to matrix C (sizes have to be equal).
N = D*inverse(L); // Make matrix N equal to the matrix product of D
// and the inverse of L (sizes of N, D and L have to be equal).
Matrix and vector elements
N = [sin(time),cos(time);cos(time),-sin(time)]; // Make elements of N equal to functions.
L[4] = time; // Make element 4 of columned L equal to time.
D[2,5] = A[2,2]*B[1,1]; // Declare one element
Multiple elements (ranges)
To prevent multiple equations for assigning matrix elements, ranges can be assigned using a colon.
E.g. 1:5 means element 1 to 5, 7:8 means element 7 and 8. Backward counting ranges (like 10:1)
are not allowed!
variables
real v[3],p[6,6];
equations
v = p[4:6,6]; // v[1] = p[4,6], ... , v[3] = p[6,6]
Operators
Some scalar operators can also be used for matrices and vectors. Depending on the specific operator,
the meaning may differ for scalars, vectors and matrices.
Operator Description
* Multiplication
+ Addition
- Subtraction
.* ArrayMultiplication
./ ArrayDivision
.^ ArrayPower
/ Division
^ Power
- Prefix Minus Sign
+ Prefix Plus Sign
| .. | Absolute / Determinant / Norm
180
4. Language Reference
Functions
A lot of special matrix and vector functions are supported in 20-sim:
Function Description
Adjoint
adjoint
Antisym
Columns
Cross
Determinant
Diag
Eye
Homogeneous
Inner
Inverse
InverseH
Linsolve
Max
Min
Msum
Norm
Norminf
Rows
Skew
Sym
Tilde
Trace
Transpose
4.8
181
20-sim 4.0 Reference Manual
x = K*(u-x)
The variable x depends on its own value and must be solved by iteration. In 20-sim every
simulation algorithm is accompanied by an iteration routine.
Fortunately 20-sim is able to solve many algebraic loops at equation level. For this model this leads
to the analytic solution the system:
x = K*u/(1+K)
The best solution for these problems is to have a critical look at the model and change the order of
calculations in a model. Possible solutions are:
182
4. Language Reference
1. Algebraic Loops occur when the order of calculations is arbitrary. When an algebraic loop
occurs in an equation model or in a set of equation models, you may change the order of
calculation by rewriting the equations. The calculation order in bond graph models can be
changed by introducing hand-defined causality.
2. Introduce ‘parasitic’ energy storage elements (e.g. a small mass, a small capacitor etc.) to
break an algebraic loop. These elements introduce however, large poles in the state
equations, which might increase the simulation time considerably.
3. Delete elements in the algebraic loop which are not relevant for the model’s simulation output
(e.g. small dampers, very stiff springs etc.). Care should however be taken, since correct
deletions are not always possible and require considerable modelling skill and intuition.
4. Combine dual elements. Sometimes elements of the same type can be combined by adding
the parameter values (e.g. combining a mass m1 and a mass m2 to a mass m1 + m2). This
will in most cases decrease the amount of algebraic loops.
Causal Form
Equations within 20-sim may be entered in random form. During compilation, 20-sim will
automatically try to rewrite equations into a causal form and set them in a correct order. I.e. a form
where all output variables are written as function of input variables. Consider for example the
following model:
variables
real u,z;
equations
u = sin(time);
u = cos(z);
Here the (input) variable u is given by the equation u = sin(time). Consequently the (output)
variable z should be written as a function of u. This is exactly what 20-sim will try to do while
compiling the model into simulation code. I.e. the function cos will be inverted and the model will be
rewritten to:
variables
real u,z;
equations
u = sin(time);
z = arccos(u);
Some functions cannot be inverted. Consequently not all equations can be rewritten. 20-sim will
report this to the user, during model checking.
183
20-sim 4.0 Reference Manual
Indifferent Causality
For some models the causal form is not known beforehand. For example the iconic diagram model
that describes a damper can be written as:
parameters
real d;
equations
p.F = d*p.v;
Here p.F denotes the force and p.v denotes the velocity of the powerport p. There is no preferred
input (force or velocity). This can be explicitly stated, by giving the powerport p an indifferent
causality. During compilation 20-sim will determine whether p.F or p.v is the input variable and
consequently rewrite the equations.
Preferred Causality
For some models there is a preferred causal form. For example the iconic diagram model that
describes a spring can be written as:
parameters
real k;
equations
p.F = (1/k)*int(p.v);
Here p.F denotes the force and p.v denotes the velocity of the powerport p. The equation is written in
integral form which is preferred. Consequently the preferred input is the velocity. Should the force be
the input, the equation must be rewritten to a differential form, which is leads to less efficient
simulation. This can be explicitly stated, by giving the powerport p an preferred causality. During
compilation 20-sim will try to keep the model in this preferred form. If this is not possible the
equations will be rewritten to the less preferred form.
Fixed Causality
For some models there is only one causal form. For example a simple iconic diagram model that
describes coulomb friction can be written as:
parameters
real Rc;
equations
p.F = Rc*abs(p.v);
Here p.F denotes the force and p.f denotes the velocity of the powerport p. The equation is cannot be
rewritten to a form where p.F is the input. This can be explicitly stated, by giving the powerport p an
fixed causality. During compilation 20-sim will try to keep the model in this fixed form. If this is not
possible an error message will be generated.
Setting Causality
For some models, the equations are too complex to analyze causality. To help 20-sim, using the right
causality, you can set causality for every port in the Interface Editor.
184
4. Language Reference
Integral Form
Consider the following first order linear model:
or
This is the same equation as the previous model! Apparently, both models are the same! Both
models can therefore be described by the dynamic equations:
We call the first equation the differential form (no integrals). The second equation is called the
integral form (no derivatives). In 20-sim models can be entered in integral form as well as the
differential form.
Solving Differential Equations
During compilation, 20-sim will automatically try to rewrite equations into the integral form, since
this leads to more efficient simulation. Sometimes an integral form cannot be found. Then algorithms
will be applied to solve the differential directly. For example an equation like:
output = ddt(sin(a*time))
185
20-sim 4.0 Reference Manual
will be replaced by the following equation (applying the chain rule and using the known derivative for
the sine function):
output = a*cos(a*time)
Sometimes a differential cannot be solved directly. Then only the Backward-Differentiation Methods
can be used for simulation.
Simulation Code
After compilation simulation code is generated. The equation in integral form:
and can be handled by all integration methods. The equation in differential form:
Order of Execution
Equations within 20-sim may be entered in random form. During compilation, 20-sim will
automatically try to rewrite equations into a correct order of execution. I.e. a form where all output
variables are written as function of input variables and output variables of previous lines. Consider
for example the following equations:
variables
real u,z;
equations
z = sin(u);
u = cos(time);
Here the (input) variable z is given as a function of u. Consequently u should be calculated first. This
is exactly what 20-sim will try to do while compiling the model into simulation code. I.e. the
equations will be executed as:
u = cos(time);
z = sin(u);
186
4. Language Reference
Code Blocks
Equations in a code block are not reordered. A code block is a set of equations inside a statement.
Suppose we have the following equations:
if condition then
code block 1
...
...
else
code block 2
...
...
end;
To prevent incorrect executions of the if-statement, the equations of the code blocks will not be
separated. Inside a code-block, equations can are not rewritten into an new order of execution. E.g.
the following equations:
Will be not be reordered and therefore not correctly executed! To get correct code, enter code
blocks in a correct order, e.g.:
parameters
real y = 8;
variables
real x1, x2, x3;
code
x1 = time;
x2 = sin(time);
x3 = y*x1;
187
20-sim 4.0 Reference Manual
Integration Steps
Some integration algorithms do more calculations before generating the next output value. These
calculations are called minor steps, the output generation is called a major step. During a minor step,
all model equations are executed. In most cases you will not notice this because only the results of
the major step are shown in the simulator. There are however, exceptions. The next topic will discuss
this in more detail.
Show Equations
During processing a complete set of equations is generated of each model. To inspect these
equations or copy them for use in other programs, you have to:
1. If the model was not checked before, from the Model menu select the Check Complete
Model command.
2. From the Model menu select the Show Equations command. Now a window is popped up
showing all the model equations.
3. You can copy the equations by selecting select all and copy from the right mouse menu.
188
5 3D Mechanics Toolbox
5.1 Introduction
Introduction
With the 3D Mechanics Editor you can create 3D dynamic models of mechanical structures. The
resulting 3D mechanical model can be connected with other 20-sim components. In the example
shown below (Getting Started\3D Mechanics Toolbox\ScaraRobotSimulation.emx), you see a robot
model that has been generated with the 3D Mechanics Editor. The model has two actuated rotation
joints and one actuated translation joint. The rotation joints are directly coupled to gearboxes. The
translation joint is coupled via a spindle.
In 20-sim you can use plots to show the simulation results and use the 3D Animation Toolbox to
show an animation of the 3D model.
1. In the 20-sim Editor from the Tools menu select 3D Mechanics Toolbox and 3D Mechanics
Editor.
Now a masked model is inserted in the Editor and the 3D Mechanics Editor will be opened.
189
20-sim 4.0 Reference Manual
If you select a 3D Mechanics model and select Go Down, the 3D Mechanics Editor will be
automatically opened.
The first time you start 20-sim 3D Mechanics Editor the following screen will appear.
190
5. 3D Mechanics Toolbox
1. Open the 20-sim model that contains a submodel that was generated by the 3D Mechanics
Editor (make sure you have stored an emergency copy).
The star shaped model was created using the 3D Mechanics Editor of 20-sim 4.0.
2. Select the model that was generated by the 3D Mechanics Editor and select Go Down.
191
20-sim 4.0 Reference Manual
The first line tells 20-sim which editor should be opened. The second line shows the location of the
corresponding 3D Mechanics configuration file. Enter the path and name of your own file here.
The comment at the top tells 20-sim which editor should be opened and the corresponding
configuration file.
The next time you select the model and select Go Down the 3D Mechanics Editor will be opened with
the proper 3D Mechanics model.
Edit Window
In the center of the 3D Mechanics Editor the Edit window is visible. At the start a reference frame
and a base plane is shown. In the Edit window, you can insert components and assemble you model.
192
5. 3D Mechanics Toolbox
Model Tab
One of the two tabs at the left of the 3D Mechanics Editor is the Model tab. The Model tab contains a
tree of all the components of in your current model. This tree can be used to select components and
edit their properties.
Library Tab
One of the two tabs at the left of the 3D Mechanics Editor is the Library tab. The Library tab
contains predefined components, which you can use to construct your model with. The components
in the library tree can be dragged into the Edit window.
Selection Properties
Below the Bodies/Library tabs the properties of the selected component are shown. When no
components are selected the selection properties are empty.
When a component is selected, the edit button will be enabled. You can click the button to change
the component properties.
193
20-sim 4.0 Reference Manual
3D Representation
Below the Selection Properties, the 3D representation of the selected component is shown. When no
components, the 3D Representation is empty.
When a component is selected, the edit button will be enabled. You can click the button to change
the 3D Representation of the component.
A component may be composed of several representations. Using the Add Representation and Delete
Representation commands of the Actions menu you can add more representations or remove
representations.
Output
In the Output part of the 3D Mechanics Editor, messages will be shown during analysis of the model.
Edit Modes
At the right of the 3D Mechanics Editor you will find the Edit Mode buttons. You can select them to
enter several edit modes.
Translation Mode In this mode you can translate components.
Connection Mode In this mode you can make connections between components.
Camera Mode In this mode you can change the camera position and
orientation. I.e. the way you look at your model.
Ghost Modes
At the right of the 3D Mechanics Editor you will find the Ghost Mode buttons. You can use these
buttons to make components transparent. This is useful when components are hidden inside other
components.
Ghost Mode for Bodies Make every body transparent.
194
5. 3D Mechanics Toolbox
View Modes
In the button bar of the 3D Mechanics Editor you will find the View Mode buttons. You can select
them to select different views.
3D View Default view.
X-Y plane View perpendicular to the x-y plane. You can only move objects
along the x-y plane.
X-Z plane View perpendicular to the x-z plane. You can only move objects
along the x-z plane.
Y-Z plane View perpendicular to the y-z plane. You can only move objects
along the y-z plane.
All A combination of the all the views.
Model Settings
The model Settings command of the Tools menu will open the Model Settings dialog. In this dialog
you can change some general settings such as the size of the reference frames or the amount of
gravity.
195
20-sim 4.0 Reference Manual
Items
Gravity: You can set the gravitational acceleration to any desired value.
Hard Coded: choose this option if you want to optimize for speed.
As Parameter: Use a gravity parameter, allowing you to change the value before the start of
a simulation run.
As Input Signal: get the gravity value from an input signal, allowing you to change the value
during simulation.
Spring Dampers for Constraint Joints: Choose this option if you want to use spring dampers
for closed kinematic chains.
Rotation Spring: Set the desired stiffness for the rotational spring.
Rotation Damper: Set the desired rotational damping.
Rotation Spring: Set the desired stiffness for the translation spring.
Translation Damper: Set the desired translation damping.
Reference Frames: Choose the size and thickness of the reference frames.
Grid: Set the grid.
Angle Representation: 20-sim uses SI-units for the model equations (e.g. radians). You can
choose to show them in non-SI-units like degrees or grads.
Power Port Type: Choose Iconic Diagram power ports or bond Graph power ports.
Constraint Solver: set the accuracy of the constraint solver.
Camera Settings
At the start of a model session, in the Edit window, a default camera is used. You can change camera
settings by clicking Camera Settings from the Tools menu.
In the Camera Settings dialog you can change the range (front and back plane) and zooming of the
camera, use a perspective view or orthographic and select the point to look at.
196
5. 3D Mechanics Toolbox
If a path from any body through a joint to another body and so on returns to the starting body we
have a closed chain mechanism. Closed chain mechanisms are generally more difficult to simulate.
20-sim uses a special feature to simulate closed chain mechanisms. At an arbitrary place a joint is
removed to create an open chain mechanism. Then the open chain is closed again using a spring
damper joint or a constraint joint. You can choose which joint to use in the Model Settings Dialog.
Spring Damper Joint
A spring damper joint is a joint where all rigid connections are replaced by spring dampers. If weak
spring dampers are used a certain amount of (unwanted) displacement will be possible. By increasing
the stiffness and damping, the displacement can be decreased. You can set the spring stiffness and
damping in the Model Settings Dialog.
Constraint Joint
The constraint joint works exactly like the original joint but uses constraint forces to do the job.
Constraint forces can only be simulated with special integration methods. In 20-sim the Modified
Backward Differentiation Method is able to calculate constraint forces.
197
20-sim 4.0 Reference Manual
The concept of constraint forces is quite easy to understand if we look at the open chain mechanism
below. At the tips of the mechanism a force is applied. If we apply a force that keeps the tips at the
same position at each time step, it will effectively work as a rotation joint. That is exactly what
constraint forces do. At every simulation step, an iterative procedure is run to find exactly that force
that keeps the position offset at zero.
Constraint Force.
This iterative procedure is not standard for most integration methods. In 20-sim only the Modified
Backward Differentiation Method supports it. In the 3D Mechanics Editor you do not have to worry
about closed chain mechanisms. If necessary, standard joints are replaced automatically by
constraint joints. You only have to realize that simulation of a mechanism with constraint joints in
20-sim should be performed using the Modified Backward Differentiation Method.
198
5. 3D Mechanics Toolbox
A standard model will at least consist of some bodies and joints. The bodies have to be connected
with the joints to define the degrees of freedom of the model. The connecting of joints and bodies
can be done in the connection mode. By clicking on a body and then on a joint a connection is
defined.
199
20-sim 4.0 Reference Manual
If all connections are defined, you can test the possible motions of your model. Return to the
translation mode and click on a body. You will see arrows that indicate the possible motion of the
connected joint. By dragging the mouse you can make the body move.
When the model is ready you can check it. When no errors are found you can update it to 20-sim.
200
5. 3D Mechanics Toolbox
20-sim Model
As you may know from the Joint Properties dialog, all joints have an initial value. During analysis of
your model, some joints may have been twisted. You can use the current (twisted) configuration to
generate a 20-sim model for, or reset it to its initial values first.
Additional Outputs
For advanced users, some additional outputs may be useful. First time users are advised not to select
these outputs.
Output Filename
Use the Browse button to select a folder and a filename for the generated 20-sim model.
201
20-sim 4.0 Reference Manual
20-sim Scenery
In 20-sim you can use the 3D Animation Toolbox to show an animation of the mechanical structure.
You can export the structure to a scenery file, which can be loaded in the 3D Animation Toolbox.
Don't Generate Joint Representations: Each joint is represented in the 3D Animation as
autonomous component with variables to denote the potion and orientation. For large
models you can save memory space by not exporting the joints.
Submodel Name to be used in 20-sim: The 3D Animation will use 20-sim submodel names
to identify the movements of object. You have to enter the submodel name, that you will
use for the 3D dynamic model in 20-sim.
Scenery Filename: Use the Browse button to select a folder and a filename for the
generated scenery file.
202
5. 3D Mechanics Toolbox
5.3 Library
Library
The Library Tab shows all components that can be used to create your 3D Dynamic model.
Bodies
Joints
Sensors
Actuators
Bodies
Position
When you drag and drop a body into the Edit window, its position (i.e. the position of its reference
frame) will be defined with respect to the base reference frame. You can change the position with the
mouse pointer. From the View menu click Mode and Translation or click the button to go to
translation mode. If you put the mouse pointer on top of the body, you can change its position by
pressing the left mouse button. If you pressing the Ctrl-button at the same time, the body will move
up and down.
You can also set the position manually by double clicking the body. This will open the Body Properties
dialog.
203
20-sim 4.0 Reference Manual
204
5. 3D Mechanics Toolbox
The orientation of a body is specified by the orientation of its reference frame. You can define this
orientation using various representations.
Direction Up Vector: Using the Direction Up vector method you have to specify the Y-axis
(Direction) and Z-axis (Up) of the body reference frame.
Bryant angles: Using Bryant angles we start with the initial body reference frame. First we
rotate around the X-axis of the body reference frame, then we rotate around the Y-axis of
the body reference frame en finally around the Z-axis of the body reference frame. Bryant
angles are also known as X-Y-Z relative Euler angles or Cardan angles.
X-Y-X Euler: Using X-Y-X Euler angles we start with the initial body reference frame. First
we rotate around the X-axis of the body reference frame, then we rotate around the Y-axis
of the body reference frame en finally around the X-axis of the body reference frame.
Euler Parameters: Using Euler parameters we start with the initial body reference frame and
rotate this frame around a vector K [X,Y,Z] about an angle theta.
Rotation Matrix: Using a 3x3 rotation matrix, you can enter 9 elements that will transform
the initial orientation of the body reference frame to the new orientation.
Inertia Properties
Each body has a mass and rotational inertia. The mass indicates the resistance of the body to a
change in position. Given a fixed force, a body with a large mass will accelerate more slowly. This
property is the same for all directions. Therefore the mass can be indicated by a single parameter.
The rotational inertia indicates the resistance of a body to a rotation. Given a fixed torque, a body wit
a large rotational inertia will start to rotate more slowly. The rotational inertia is not the same for all
orientations. Generally, for any body three axes can be identified that indicate a stable rotation. The
rotational inertia for these three principal axes of rotation is sufficient to describe the motion of a
body. The connection of these three principal axes of rotation is generally known as the center of
mass.
Any body, indifferent of its shape, which has the same mass, the same principal axes of rotation and
the same rotational inertia, will show the same dynamic behavior. That is why you can change the
representation of a body to any size, it will not change its dynamic properties.
205
20-sim 4.0 Reference Manual
If you open the Body Properties Dialog you can click the Edit button to change the inertia
properties. You can set mass and the rotational inertias for each of the principle inertia axis.
The center of mass does not necessarily have to coincide with the body reference frame and the
orientation of the principal inertia axes do not have to coincide with the orientation of the body
reference frame.
You can enter set the offset position of the center of mass and the orientation of the principal inertia
axes, by clicking the offset button.
More Options
If you click the More button in the Body Properties dialog, options are shown which form a shortcut
for the normal way of building models. They are meant for experienced users.
First a list of connection points are shown and some buttons to edit these points. Connection points
are used to indicate at which point a joint or other element is connected with the body. Connection
Points are explained in more detail in the next section.
At the bottom two options are shown. If you choose the Generate Power Interaction Port option, a
power port will be added to the body, which allows you to insert forces and torques onto the body,
from other 20-sim submodels.
The Output Absolute H-matrix option, will create an 4x4 output signal that gives the position and
orientation of the body, using an H-matrix. This signal can be connected to other 20-sim submodels.
206
5. 3D Mechanics Toolbox
Joints
Properties
In order to make two bodies move with respect to each other, we have to connect them by joints.
Joints do not have any mass or rotational inertia. They only constrain the motion of bodies. The
position of a joint is indicated by its reference frame. Because the joint position and orientation is
completely determined by the bodies that are connected, you do not have to specify any position or
orientation parameters. These are automatically derived when you make connections.
Connections
Making connections is not difficult when you understand how frames work. We will explain this with a
simple example. Suppose we have two bodies and a rotational joint. The initial positions of the
bodies and joints are indicated by their reference frames.
Now we have to define for each of the two bodies the offset to the joint. This can be done using
connection points. A connection point is in fact a new frame with an offset from the body reference
frame. As you can see, in the picture below, we have defined ConnectionPoint1 with an offset of [x =
1, y = 1, z = -1] with respect to the Body1 and we have defined ConnectionPoint2 with an offset of
[x = 1, y = -1, z = -0.3] with respect to Body2.
Now the bodies and the joint can be assembled by changing the body positions in such a way that
the frames of the connection points coincide with the reference frame of the joint exactly.
207
20-sim 4.0 Reference Manual
Suppose that Body1 is set as the reference body. Now the whole assembly will be moved until Body1
has its original position.
Creating Connections
In the 3D Mechanics Editor most of the assembly of joints and bodies is automated. You simply have
to make connections between joints and bodies. To make a connection you have to drag and drop
bodies and a joint to the Edit window. Then change to Connection mode ( ). First click a body and
then the joint it should be connected to.
208
5. 3D Mechanics Toolbox
The Create Connection dialog will pop to ask you for the location of the connection point. In the
connection dialog you can set the offset (both the position as well as rotation) from the body
reference frame to the connection point.
After the dialog is closed the body will automatically assemble with the joint. When two bodies are
assembled with a joint, you can view their constrained motions.
Joint Properties
When you want to change the Connection Points after the connection has been made, you have to
double clicking the joint. This will open the Joint Properties Dialog.
You can change the name, position, orientation, and the rotation axis of the connection points. You
can also change the joint type and the initial rotation or translation of the joint. If you lock the joints,
it will not move when you want to show the possible motions of the system.
209
20-sim 4.0 Reference Manual
Advanced Properties
At the bottom of the Joint Properties you can click the More button to see the advanced properties.
210
5. 3D Mechanics Toolbox
Join Restrictions
If you click the More button to see the Advanced Joint Properties, you can click the Spring Damper
button. This will allow you to add damping to a joint or a spring and define end-stops.
Has Spring: choose this option to define a spring parallel to the joint.
Has Damping: select this option to define the damping (linear with the velocity).
Has Minimum: set an endstop at the minimum joint rotation/extension.
Has Minimum: set an endstop at the maximum joint rotation/extension.
Joint Types
Several types of joints are available in the library:
Rotation Joints (Non-Actuated)
joint description
XYZ-Rotation Joints which rotate around the principal axes.
Hinge XYZ-Rotation Same as XYZ-Rotation but with a different representation.
Balljoint XYZ-connection Balljoints with orientations of the principal axes.
211
20-sim 4.0 Reference Manual
joint description
XYZ-Translation Joints which rotate around the principal axes.
Other Joints
joint description
Weld joint A joint that welds two bodies together.
Free Moving Joint Opposite of the weld joint. In practice this joint will only be
used to give a body a fixed starting position with respect to
another body.
Sensors
Sensors are components that indicate the position or velocity of bodies as output signals.
Connecting Sensors
Sensors have to be connected with bodies, just like joints.
The position of the sensor is indicated by its connection point. The connection point is shown
automatically when you make a connection between a body and a sensor. First change to
Connection mode ( ), then click the body and then click the sensor.
212
5. 3D Mechanics Toolbox
The Create Connection dialog will pop to ask you for the location of the connection point. In the
connection dialog you can set the offset (both the position as well as rotation) from the body
reference frame to the connection point.
213
20-sim 4.0 Reference Manual
Sensor Types
Various sensor types are available in the library.
Position/Orientation
sensor output signal
Position-X A signal with the x-position of the body.
Position-Y A signal with the y-position of the body.
Position-Z A signal with the z-position of the body.
Position (3x1) A signal (size 3) with the x-, y- and z-position of the body.
H-matrix (4x4) A 4x4 signal with the H-matrix.
Rotation (3x3) A 3x3 signal with the rotation-matrix.
Velocity
sensor output signal
Velocity-X A signal with the x-velocity of the body.
Velocity-Y A signal with the y-velocity of the body.
Velocity-Z A signal with the z-velocity of the body.
Velocity (3x1) A signal (size 3) with the x-, y- and z-velocity of the body.
Omega-X A signal with the rotational velocity in x-direction of the body.
Omega-Y A signal with the rotational velocity in y-direction of the body.
Omega-Z A signal with the rotational velocity in z-direction of the body.
Omega (3x1) A signal (size 3) with all three rotational velocities.
Acceleration
sensor output signal
Acceleration-X A signal with the x-acceleration of the body.
Acceleration-Y A signal with the y-acceleration of the body.
Acceleration-Z A signal with the z-acceleration of the body.
Acceleration (3x1) A signal (size 3) with the x-, y- and z-acceleration of the body.
Rotational Acceleration-X A signal with the rotational acceleration in x-direction of the
body.
Rotational Acceleration-Y A signal with the rotational acceleration in y-direction of the
body.
Rotational Acceleration-Z A signal with the rotational acceleration in z-direction of the
body.
Rotational Acceleration A signal (size 3) with all three rotational accelerations.
(3x1)
214
5. 3D Mechanics Toolbox
Jacobian Matrix
This yields the Jacobian Matrix of the connected mass.
Actuators
Actuators are components that impose a force or torque on bodies, where the force or torque is
given by a power port or input signal.
Connecting Sensors
Actuators have to be connected with bodies, just like joints.
The position of the sensor is indicated by its connection point. The connection point is shown
automatically when you make a connection between a body and a sensor. First change to Connection
mode ( ), then click the body and then click the sensor.
The Create Connection dialog will pop to ask you for the location of the connection point. In the
connection dialog you can set the offset (both the position as well as rotation) from the body
reference frame to the connection point.
215
20-sim 4.0 Reference Manual
In this diaolog you can change the connection point by clicking the position or orientation button.
If you select the As Power Port option, the force or torque will be given by a power port, otherwise
an input signal. By default the force or torque is defined in the local body coordinates. This means
the force or torque will rotate and move with the body. If you deselect the In Body Coordinates
option, the force or torque will be in global coordinates and not rotate with the body.
216
5. 3D Mechanics Toolbox
Actuator Types
Powerport
actuator power port
Torque-X A torque in the x-direction of the body.
Torque-Y A torque in the y-direction of the body.
Torque-Z A torque in the z-direction of the body.
Torque (3x1) A torque (size 3) in the x-, y- and z-direction of the body.
Force-X A force in the x-direction of the body.
Force-Y A force in the y-direction of the body.
Force-Z A force in the z-direction of the body.
Force (3x1) A force (size 3) in the x-, y- and z-direction of the body.
Torque & Force (6x1) The combined torque and force (size 6) in all directions
(known as a Wrench).
Signal
actuator input port
Torque-X A torque in the x-direction of the body.
Torque-Y A torque in the y-direction of the body.
Torque-Z A torque in the z-direction of the body.
Torque (3x1) A torque (size 3) in the x-, y- and z-direction of the body.
Force-X A force in the x-direction of the body.
Force-Y A force in the y-direction of the body.
Force-Z A force in the z-direction of the body.
Force (3x1) A force (size 3) in the x-, y- and z-direction of the body.
Torque & Force (6x1) The combined torque and force (size 6) in all directions
(known as a Wrench).
217
20-sim 4.0 Reference Manual
218
6 Animation Toolbox
6.1 Animation in a Graphical Model
To Animate the results of a simulation in the graphical model select the Graph Animation command
from the Tools menu (Simulator). During simulation, the thickness and color of bonds and signals will
correspond with the values they carry.
The color of a bond or signal always corresponds with the sign, red for negative values and green for
positive values. The thickness of signals corresponds with the value. For signals that is obvious but
for bonds or connections carry two variables: effort and flow (also know as across and through). For
bonds and connections you can choose to let the thickness correspond with the effort, flow or power
(effort*flow), depending on the Animation command that was chosen.
3. A menu pops up. Choose the options you like and click OK to start Animation.
219
20-sim 4.0 Reference Manual
Items
Animation Kind: For signals, the thickness always corresponds with their value. For bonds
and connections you can choose. Select here to what the thickness of bonds and
connections should represent: effort, flow or power (effort*flow).
Animation Ranges: The thickness of bonds and signals can vary from 1 to 5 pixels. Select
here the range that should correspond with a thickness of 5 pixels.
220
6. Animation Toolbox
6.2 3D Animation
3D Animation
In the Simulator choose Tools and Animation Toolbox and 3D Animation to open a 3D Animation
window.
Editing
To start editing, from the Properties menu select 3D Properties . This will open 3D
Properties window where you build your animation.
Running
You can run an animation by clicking the green run button . You can also select the Run
command from the Replay menu.
At the top right of the window you see the Speed box where you can set the replay
speed. The default speed is to replay an animation at real time but you can set it to play an
animation faster or slower.
If you have multiple camera's in yyour animation, you can switch camera, by clicking the
camera button .
Ray Trace
Ray Tracing will add shadows and mirror images to a 3D Animation. From the File menu,
select RayTrace to apply Ray Tracing to the current window.
Creating Movies
From the File menu select Create Movie to create movies from your animation.
221
20-sim 4.0 Reference Manual
3D Properties
The 3D Properties window allows you to define the various objects that should be shown in a 3D
Animation. The 3D Properties window can be opened, by double clicking the mouse pointer in the
Animation window or using the Properties menu.
Menu
The menu of the 3D Animation Properties consists of three parts.
The File menu allows you to store and load scenes (parts of the object tree) and create
movies.
The Edit menu allows you to create and edit objects.
The Properties menu allows you to set the General Properties.
Lights, Cameras and Objects
Two lights and five cameras are standard available when you start a new animation. You can delete
or change these lights and cameras or add new additional lights and cameras. Inserting new objects
can be done with the Edit menu by selecting the Insert Object command.
Object Tree
The left side of the 3D Animation Properties window shows tree-like listing of the objects that are
inserted. All objects are defined with respect to a reference frame. This can be done hierarchically by
inserting new reference frames.
222
6. Animation Toolbox
Object Attributes
On the right side of the 3D Animation Properties window shows the attributes of a selected object
(e.g. position, orientation, scaling etc.). Objects can be selected, by clicking the mouse pointer on
top of the object in the objects tree.
Show Frame
Each object has an object attached reference frame. This frame can be shown by selecting the object
and clicking the Show Frame option. This is useful for manipulating objects.
Next Camera
Click the Next Camera button to seen the next camera view.
Manipulate
Click the Manipulate button to move an object with use of your mouse.
223
20-sim 4.0 Reference Manual
Selecting Objects
An object can be selected by pointing with the mouse in the object tree.
This selection is also shown in the 3D Animation window as a yellow box around the object.
It is also possible to select an object with the mouse by clicking in the 3D Animation window. The
selection will automatically jump to the object in the tree of the 3D Animation Properties window.
224
6. Animation Toolbox
Moving Objects
To move an object, you have select it.
Attributes
The right side of the 3D Animation Properties window shows the attributes of a selected object (e.g.
position, orientation, scaling etc.). You can change the position or orientation to move an object.
Manipulate
You can move an object directly by pushing the Manipulate button.
225
20-sim 4.0 Reference Manual
A set of locks will be shown below the Manipulate button. You can use them to lock one or more
directions and orientations. After this you must put the 3D Animation window on front (click on it
with the mouse) and select one of the following keys:
Keys Action
right arrow move right (positive x-direction)
left arrow move left (negative x-direction)
up arrow move up (positive z-direction)
down arrow move down (negative z-direction)
Ctrl + up arrow move forward (positive y-direction)
Ctrl + down arrow move backward (negative y-direction)
Alt+ right arrow yaw right (positive z-axis rotation)
Alt+ left arrow yaw left (negative z-axis rotation)
Alt+ up arrow roll forward (negative x-axis rotation)
Alt + down arrow roll back (positive x-axis rotation)
Ctrl+ Alt + right arrow pitch right (positive y-axis rotation)
Ctrl+ Alt + left arrow pitch left (negative y-axis rotation)
226
6. Animation Toolbox
Scenes
In the 3D Animation Properties you can load and store scenes. Scenes are simply part of an object
tree or a complete object tree. This option can be used to obtain scenes from other experiments or to
create pre-defined environments.
Save Scene
The Save Scene command of the File menu, allows you to save a scene on file. Only the selected
object and all object below will be saved.
Load Scene
The Load Scene command of the File menu, allows you to open a scene from file and insert it under
the selected object of the object tree.
Movies
With a few mouse clicks you can create movies from an animation. In the File menu select Create
Movie.
Target List
You can create movies for various purposes:
YouTube: Movies in mpg-format for placement on YouTube.
Avi: Movies in avi format for use in movie editing software.
Windows Media Video: Movies for the use in Microsoft programs (e.g. Powerpoint).
Flash: Movies in flv format for the use on Internet sites.
Only Frames: For the use in advanced movie editing programs that can handle collections
of pictures
227
20-sim 4.0 Reference Manual
Profiles
You can create movies with three profiles (low, medium, high). The corresponding sizes are shown in
the table below.
Ray Tracing will add shadows and mirror images to a 3D Animation. However ray tracing cost a lot of
processing power. If you select the option Ray Tracing, the quality of your movie will be improved,
but the time to create it will increase seriously.
More
Choose the More button if the standard profiles are not up to your demands. You can set the size of a
movie, the frame rate and speed up or slow down the speed.
Create Movie
Click the Create Movie button to create a movie. The movie will be stored in the output directory that
you have specified using the filename that you have given.
General Properties
Using the General Properties command of the 3D Properties window helps you to select several
options.
Background Color: Change the background color to any desired color you like.
Background Image: Use a bitmap image for the background.
Wireframe: You can choose to show the animation as Wireframe.
Fogging: Fog in any desired color can be added to the animation. The fog is minimal at a
start plane and maximal at an end plane. You can set the distance of these planes.
Grid: You can choose to show a grid.
Frames: Set the frame scaling and thickness.
228
7 Control Toolbox
7.1 Controller Design Editor
Controller Design Editor
The 20-sim Controller Design Editor allows you to enter or edit linear time-invariant models of a plant
with control loop. The control loop is separated in a compensator, prefilter and measurement. You
can open the Controller Design Editor from the Tools menu of the 20-sim Editor or by clicking Go
Down on a ControlledLinearSystem model that was inserted in the Editor.
Sub System
You can choose to show a single element in the loop:
Plant (P), Compensator (C), Prefilter (F) or Measurement (M)
or view the response of the system:
Loop Transfer (L), Sensitivity (S), Compl. Sensitivity (T) or Response (H).
The corresponding transfer function is show in the editor.
229
20-sim 4.0 Reference Manual
Additional Ports
Select one of the radio buttons Input Disturbance, Output Disturbance, Measurement Dist. or
Feedforward. The first three options allow you to use external disturbance in your model. The last
option allows you to use an external feedforward controller (e.g. a B-Spline network). The selected
inputs are shown in the picture.
System Description
Pressing the Edit button will open a dialog for editing the linear system. Each description
(State Space, Transfer Function, Zeros Poles Gain or Eigen Frequency) has a special dialog
and can be used to specify continuous-time and discrete-time systems.
In the 20-sim Simulator, out of an existing (non-linear) model a symbolic linear-system can
be derived by means of linearization. This means that the relevant model parameters are
preserved in the Linear System and the parameters button can be used to change
parameters.
Import/Export
Pressing the s<->z button will transform a continuous-time linear system into a
discrete-time linear system and back.
Pressing the Filter button opens the Filter Editor, where a filter can be designed. This filter
can then be combined with the current linear system or replace the current linear system. If
the linear system is a discrete-time system, the designed analog filter is automatically
transferred into its digital equivalent.
Pressing the From Matlab button and the To Matlab button allows for an instant
exchange of the linear system with the Matlab workspace. Information is transferred
numerically (no parameter relations are preserved)
The button is only active when a Linear System has been imported through
linearization. Clicking the button will import parameters from the simulation.
The button is only active when a Linear System has been imported through
linearization. Clicking the button will export the current parameters to the simulation.
Plots
You can inspect the time- and frequency responses of the selected transfer function using:
Step Response
Bode Plot
Nyquist Plot
Nichols Chart
Poles and Zeros (including root locus)
Output
Clicking the 20-sim button will export the linear system as a new 20-sim submodel.
Clicking the Matlab button will export the 20-sim Linear System to a Matlab m-file. If the
Linear System is symbolic, all parameter relations are preserved.
230
7. Control Toolbox
For some years now, researchers have been developing models that mimic the activity of neurons to
produce a form of artificial intelligence. These "Neural Networks" are formed from tens or hundreds
of simulated neurons connected together in much the same way as the brain's neurons. Just like the
neurons of the brain, artificial neurons can change their response to a given set of inputs, or "learn".
In the past many learning algorithms have been developed, mostly with limited success. The
introduction of the backpropagation paradigm, however, appeared a turning point. It is an extremely
effective learning tool that can be applied to a wide variety of problems.
The backpropagation paradigm require supervised training. This means neural networks must be
trained by repeatedly presenting examples to the network. Each example includes both inputs
(information you would use to make a decision) and desired outputs (the resulting decision,
prediction, or response). Based on a calculation on the inputs, the desired outputs and the networks
own response to the inputs, the backpropagation paradigms tries to adapt the response of each
neuron to achieve an improved neural network behavior. This trial-and-error process continues until
the network reaches a specified level of accuracy.
Once a network is trained and tested it's neurons can be "frozen". This means the neurons ability to
learn" or adapt is stopped. The network can then be used to perform the task it was trained for.
BackPropagation Networks
In backpropagation type neural networks, the neurons or "nodes" are grouped in layers. We can
distinct three groups of layers in a backpropagation type neural network: one input layer, one or
more hidden layers and one output layer. The nodes between two adjacent layers are
interconnected. Fully connected networks occur when each node of a layer is connected with each
node of the adjacent layer.
As the figure shows, information (i.e. input signals) enters the network through the input layer. The
sole purpose of the input layer is to distribute the information to the hidden layers. The nodes of the
231
20-sim 4.0 Reference Manual
hidden layers do the actual processing. The processed information is captured by the nodes of the
output layer, and transported as output signals to the world outside.
The nodes of the hidden layers process information by applying factors (weights) to each input. This
is shown in the figure above. The sum of the weighted input information (S) is applied to an output
function. The result is distributed to the nodes of the next layer.
When the network is in being trained, the weights of each node are adapted according to the
backproagation paradigm. When the network is in operation, the weights are constant.
Depending on the kind neural network, various topologies can be discerned. The 20-sim Neural
Network Editor supports two well-known networks:
The input, x, of the neuron consists of the variables x1 ... xn and a bias term, known as the
momentum constant, which is equal to 1. Each of the input values is multiplied by a weight, wi ,
after which the results are added. On the result, a simple mathematical function, f (x), is performed.
This function is also known as the activation function. The calculations the neuron performs are
thus given by:
232
7. Control Toolbox
Numerous choices for the functions exist. Frequently used implementations are the Sigmoid
functions:
f(u) = 1 / (1 + e-u )
f (u) = c1 * tanh ( c2 * u)
MLP Network
An MLP network, as any type of back-propagation network can consist of many neurons, which are
ordered in layers. The neurons in the hidden layers do the actual processing, while the neurons in the
input and output layer merely distribute and collect the signals. Although many hidden layers can be
used, it has been shown that an MLP with one hidden layer can approximate any continuous function.
Therefore in 20-sim, the MLP networks only have one hidden layer.
Training the MLP network
The MLP network is trained by adapting the weights. During training the network output is compared
with a desired output. The error between these two signals is used to adapt the weights. This rate of
adaptation is controlled by the learning rate. A high learning rate will make the network adapt its
weights quickly, but will make it potentially unstable. Setting the learning rate to zero, will make the
network keep its weights constant.
233
20-sim 4.0 Reference Manual
General Settings
Network Name: this is the local name of the submodel representing the MLP network (this
option is not yet supported).
Number Hidden Neurons: The MLP network specified by this editor has one layer of hidden
neurons. You can specify here the number of neurons that should be used.
Learning Rate: Specify the learning rate that should be used during training. If you do not
want the network to learn, enter a zero value here.
Initial Weights Fill Scale: To start proper learning of the network, all initial weights will be
given a random value (unequal to zero!) between -scale and +scale. You can enter the
scale factor here.
Activation Function Type: Select one of the following activation functions
Unipolar Sigmoid: act = 1/(1 + exp(-v) )
Bipolar Sigmoid: act = const2*tanh(const1*v)
Bipolar Sigmoid Activation Function Scale: If a Bipolar Sigmoid was chosen as the activation
function, you can enter here the values of const1 and const2.
Momentum Constant: Select the momentum constant here.
Load Weights at Start of Simulation: Select this option, if you want to use predefined
weights stored on file (saved in a previous run). Before each simulation run, you will be
asked to enter the filename of this weights file.
Save Weights at Start of Simulation: Select this option, if you want to store the weights on
file. After each simulation run, you will be asked to enter the filename of this weights file.
234
7. Control Toolbox
Network is Discrete: Select this option if the B-spline network is connected with discrete-
time models. Deselect this option if the network is connected with continuous models.
Inputs
Add Input: Add a new input to the network. You will we prompted to give a specific input
name. This name will be shown in the Inputs list.
Delete Input: Delete the input selected in the Inputs list.
Outputs
Add Output: Add a new output to the network. You will we prompted to give a specific
output name. This name will be shown in the Outputs list.
Delete Output: Delete the output selected in the Outputs list.
235
20-sim 4.0 Reference Manual
For some years now, researchers have been developing models that mimic the activity of neurons to
produce a form of artificial intelligence. These "Neural Networks" are formed from tens or hundreds
of simulated neurons connected together in much the same way as the brain's neurons. Just like the
neurons of the brain, artificial neurons can change their response to a given set of inputs, or "learn".
In the past many learning algorithms have been developed, mostly with limited success. The
introduction of the backpropagation paradigm, however, appeared a turning point. It is an extremely
effective learning tool that can be applied to a wide variety of problems.
The backpropagation paradigm require supervised training. This means neural networks must be
trained by repeatedly presenting examples to the network. Each example includes both inputs
(information you would use to make a decision) and desired outputs (the resulting decision,
prediction, or response). Based on a calculation on the inputs, the desired outputs and the networks
own response to the inputs, the backpropagation paradigms tries to adapt the response of each
neuron to achieve an improved neural network behavior. This trial-and-error process continues until
the network reaches a specified level of accuracy.
Once a network is trained and tested it's neurons can be "frozen". This means the neurons ability to
learn" or adapt is stopped. The network can then be used to perform the task it was trained for.
The network is shown with two hidden layers. Some authors prefer to show a B-spline network with
only one hidden layer. For a proper understanding of multi-dimensional B-spline networks we prefer
to show the network with two hidden layers.
236
7. Control Toolbox
The first hidden layer distributes the inputs over several nodes. In the figure above input 1 is
distributed over n nodes. Each node of this layer has only one input. To this input a "basis function" F
is applied. As basis functions, B-splines are used of any desired order. An N-th order B-spline
function consists of pieces of (N-1)th order polynomials, such that the resulting function is (N-1)
times differentiable. The figure below shows examples of B-spline functions of different order. A
spline function differs from zero on a finite interval.
The second hidden layer also consists of n nodes. Each node of this layer has only one input. To this
input a function G is applied which is merely a multiplication by a weight:
G=w*i
The output node sums the results of all second hidden layer nodes. When the spline functions of the
various nodes are properly spaced, every one dimensional function can be approximated. This is
shown in the figure below where the various splines (F1 to Fn) combined with the various weights (w 1
to wn), together form an output function.
237
20-sim 4.0 Reference Manual
The second hidden layer now consists of nodes which each have two inputs. For every combination of
a node from one group and and a node from the second group, a node exists. To each node of the
second hidden layer, a function G is applied which is merely a multiplication of the two inputs
multiplied by a weight:
G = w * i1 * i2
Again the output node sums the results of all second hidden layer nodes. When the spline functions
of the various nodes are properly spaced, every two dimensional function can be approximated. The
figure below shows the spacing of various spline functions of the two inputs and one output of a node
of the second hidden layer.
The output node sums the results of all second hidden layer nodes. When the spline functions of the
various nodes are properly spaced, every two dimensional function can be approximated. This is
shown in the figure below.
238
7. Control Toolbox
Given a certain input (x), only a limited number of splines Fi (x) are nonzero. Therefore only a few
weights are adapted each sample.
Learn after Leaving Spline
When learning after leaving a spline, the network will keep track of the input (x) and the
corresponding nonzero splines Fi (x). For each nonzero spline, a sample will be stored consisting of
the input (x), the output (y) and desired output (yd). Only after the input has left the region where a
spline is nonzero, its weight is updated according to:
239
20-sim 4.0 Reference Manual
General Settings
Network Name: this is the local name of the submodel representing the B-Spline network
(this option is not yet supported).
Order: Enter the order of the B-Splines that must be used.
Learn at Each Sample: Select this option if you want the network to adapt the weights after
every simulation step
Learn after leaving Spline: Select this option if you want the network to adapt the weights
only leaving the spline region.
Learning Rate: Specify the learning rate that should be used during training. If you do not
want the network to learn, enter a zero value here.
Apply Regularization: This option is not yet supported.
Load Weights at Start of Simulation: Select this option, if you want to use predefined
weights stored on file (saved in a previous run). Before each simulation run, you will be
asked to enter the filename of this weights file.
240
7. Control Toolbox
Save Weights at End of Simulation: Select this option, if you want to store the weights on
file. After each simulation run, you will be asked to enter the filename of this weights file.
Network is Discrete: Select this option if the B-spline network is connected with discrete-
time models. Deselect this option if the network is connected with continuous models.
Input Settings
The tabs shown in the editor is used to specify the inputs of the network. Each tab shows the specific
settings of that input.
Add Input: Add a new input to the network. A new tab will be added with default settings.
Delete Input: Delete the input defined in the selected tab (the tab that is in front).
Each input is associated with a certain number of splines. To give the user more flexibility, each input
can be divided in certain regions that each have their own density of splines.
Add: Add a new region of splines.
Delete: Delete the selected region of splines.
Split: Split the selected region into two regions.
Each region can be edited. Just select it from the Regions list and use the following options:
Upper / Lower: The upper and lower bound of a region.
Number of Splines: The number of splines. The more splines you choose, the more accurate
will the network output be, for this region of inputs.
3. Select the model 1DBSplineNetwork-Run.emx. Now the predefined model will be opened.
As you can see, this is exactly the same model as used for training, but now a ramp input is used.
241
20-sim 4.0 Reference Manual
4. From the menu select Model and Start Simulator. Now a Simulator will be opened with the
predefined experiment loaded.
5. From Simulator menu click Simulation and Run. Do not save the weights file at the end of
the run! The results will look like:
As you can see, the B-Spline Network still has its training settings and still prompts for a weight file
at the end of the simulation. Now we are going to change the settings of the B-Spline Network.
6. Open the B-Spline Editor (select the model, Go Down). To create a normal run with the
network, we have to set the learning rate to zero, and load the weights file before simulation.
Change the settings of the network, until it looks like:
242
7. Control Toolbox
7. Click OK to close the B-Spline Editor. From the Editor menu click Model and Check
Complete Model. This will implement the changed settings.
8. Return to the Simulator and click Simulation and Run.Before the run, an Open dialog will
asking you to enter the name of the Weights File. This is a file that contains all the weights of
the trained B-Spline network. Use the file that you saved during training, or the predefined
weights file 1DBSplineNetwork.wgt. The simulation results will look like:
As you can see the function is appriximated by the B-Spline network by 10 first order splines.
F = input2
The input, x , of this function ranges from 0 to 10. It will be approximated by a B-Spline network
with one input. As is shown in the figure below (left), 10 first order B-splines are used. The tenth B-
spline is indicate with fat lines. The output of the B-spline network is a combination of all ten B-
Splines. In other words, the non-linear function will be approximated by 10 intervals of constant
value.
243
20-sim 4.0 Reference Manual
At the start the B-spline has undefined weights. They can either be chosen at random values or all
set to zero. A normal session should therefore start with training the network to adjust the weights
to give a best approximation of the non-linear function. With these weights we can run the network
with any desired input signal.
3. Select the model 1DBSplineNetwork-Train.emx. Now the predefined model will be opened.
4. From the menu select Model and Start Simulator. Now a Simulator will be opened with the
predefined experiment loaded.
244
7. Control Toolbox
5. From Simulator menu click Simulation and Run. The results will look like:
As you can see, the B-Spline output is zero and there is no learning. Now we are going to change the
settings of the B-Spline Network.
7. Click OK to close the B-Spline Editor. Not that the icon of the BSplineNetwork model has
changed to correspond with the first order splines that are used. From the Editor menu click
Model and Check Complete Model. This will implement the changes in settings.
8. Return to the Simulator and click Simulation and Run. The results will look like:
245
20-sim 4.0 Reference Manual
As you can see the error rapidly descent, due to the network learning. After the Simulation Run,
Save dialog opens, asking you to enter a name for the Weights File. This is a file that contains all the
weights of the trained B-Spline network. We can use these weights for normal runs with the network.
9. Enter file name (do not use the predefined weights file!), e.g. test.wgt and click Save.
246
7. Control Toolbox
You can open the Controller Design Editor from the Tools menu of the 20-sim Editor or by clicking Go
Down on a Filter model.
Procedure
1. Select a filter or controller of your choice from the list of available filters and controllers.
Filters
Generic Filter
Lead Filter
Lag Filter
Low Pass First Order Filter
Low Pass Second Order Filter
High Pass First Order Filter
High Pass Second Order Filter
Notch Filter
Universal Notch Filter
Controllers
P Controller
I Controller
D Controller
PI Controller
PD Controller
247
20-sim 4.0 Reference Manual
PID Controller
PID-1 Controller
PID-2 Controller
PID Compensator
A short description of the selected filter will be given in the description field. Depending on the filter
that was chosen three or more parameters will be shown.
Select the Linear System Editor button to export the filter to the Linear System Editor.
Select the OK button to store the filter model on file or update the filter model in the Editor.
248
8 Frequency Domain Toolbox
8.1 FFT Analysis
FFT Analysis
In FFT-Analysis, the Fast Fourier Transform is used to calculate the frequency contents of simulation
signal. Three representations are supported:
Amplitude and Phase: This representation shows the amplitude and phase of the signal as
function of the frequency. This results is a graph very similar to a bode plot.
Frequency Plot: This representation shows the frequency contents of the signal. Summation
of the peak values yields the average power of the original time signal.
Power Spectral Density: This representation shows the frequency contents of the signal.
Integration over the frequency range yields the average power of the original time signal.
FFT analysis can be performed in the Simulator by choosing the FFT Analysis command from the
Tools menu. After selecting this command, a window will pop-up showing the FFT settings:
249
20-sim 4.0 Reference Manual
Items
Sample Type
Use First N samples: The first N simulation points will be used for the FFT calculations. This
option is preferred if you have run a simulation with equidistant points (fixed step size).
Sample all Data: The complete simulation run will be sampled at equidistant points in time.
Data points will be calculated through linear interpolation. This is the only option when you
have run a simulation with variable step size.
Number of samples: Choose the number of samples you would like to use for the FFT
calculations. The number must be a power of two.
Plot Properties: You can select logarithmic scaling and shared Y-axis and indicate the peaks
in the plot.
Filter
Subtract DC-component: If your signal contains a DC-component, the resulting Spectral
Density plot will show a high peak at 0 Hz, which may obscure all other frequencies. Choose
Subtract DC-component, to remove this peak from the Spectral Density plot.
Integrate Data: You can integrate the FFT data to inspect the energy contents of each
frequency. This option is useful for analyzing resonance frequencies. Integrated FFT-data
will usually show a sudden increase exactly at these frequencies.
Anti-Alias Window: You can choose out of a Hamming, Hahn or Quadratic window to prevent
aliasing.
Frequency: Show the results in Herz or radians per second.
Output: select the desired representation of the frequency data:
Amplitude and Phase
Frequency Plot
Power Spectral Density
Status Window: The bottom part of the window shows the number of simulation points and
the chosen frequency range.
250
8. Frequency Domain Toolbox
The results of an FFT plot strongly depend on the actual frequency contents of the time domain plot:
if a frequency is not present in the original time signal, the FFT plot will not show it, even if the
model is very much capable of showing activity for such a frequency. E.g. if you use a 50 Hz input
signal for a current amplifier model, the FFT will certainly not show much. Instead use a frequency
sweep input signal containing all frequencies of interest in order to get an output plot with enough
frequency content. In other words: to get a good FFT plot, take care that a you use input signals for
your model that exitate all frequencies of interest!
FFT plots show very good use when you want to compare a model with an existing system through
measured data. In many cases, the measured data will show noise, making it hard to determine the
resonant frequencies. If you make an FFT plot of both measurement data and model output, you can
easily compare the resonant peaks.
FFT Window
The Fast Fourier Transform is an approximation of the standard Fourier Transform, using a time
limited set of data. The begin and end parts of this limited data set may lead to aliasing effects (i.e.
yielding not existing frequency peaks). Especially when using small data sets aliasing may lead to
unwanted results.
To reduce aliasing, the data set can be preprocessed using special windows. These windows reduce
the values at the begin and end of the data set and thus reduce the aliasing effects. Given an input
array A[i] and an output array B[i], with = 1,2,...,N, 20-sim supports the following windows:
None: no preprocessing A == B
Hamming Window: B(i) = (0.54 + 0.46*cos(pi*(i-1)/(N-1)))*A(i), i = 1,2,...,N.
Hann Window: B(i) = 0.5*(1 + cos(pi*(i-1)/(N-1)))*A(i), i = 1,2,...,N.
Quadratic Window: B(i) = (1 - 2*((i-1)/(N-1))**2)*(1 - (i-1)/(N-1))*A(i), i = 1,2,...,(N-
1)/2+1; B(i) = 2*(1 - ((i-1)/(N-1))**3)*A(i), i = (N-1)/2+2,...,N.
251
20-sim 4.0 Reference Manual
dx/dt = Ax + Bu
y = Cx + Du
x(0)
Where:
x = state vector
x(0) = state vector initial value
dx/dt = state vector derivative
y = output
u = input
And:
A= system matrix
B= input gain matrix
C= output gain matrix
D= direct link gain matrix
This linear system shows an input-output behavior that is closely related to the input-output behavior
of the original model.
The result is shown in the Linear System Editor. In the Linear System Editor you can choose out of
several plot options to show the response of the linear system, such as step responses and Bode
plots.
Working Point
Non-linear models can show variable behaviour. Think for example of an arm. When you stretch it
and push against a wall, it is very stiff. When your arm is bent and you push it against a wall, it will
be more compliant. Depending on which state it is in, linearization of a non-linear system will
therefore result in different linear systems.
To get the correct linear system, we have to bring the non-linear system into the correct state. This
can be done by giving it the proper inputs and simulate the system for a while until the desired state
is reached. This is called the working point. When the working point is reached, the simulation must
be stopped to perform linearization.
When linearization is performed without simulation, the working point is the initial state of the non-
linear system.
252
8. Frequency Domain Toolbox
As a result you will get a linear system with the original model parameters that can be changed at
will, without having to linearize again.
Symbolic linearization is not possible if the original model contains functions that cannot be
differentiated. For such models linearization has to be performed numerically. The resulting linear
system has to be recalculated through linearization for different model parameters.
Procedure
2. Stop the simulation at operating point an select the Linearize command from the Tools
menu.
253
20-sim 4.0 Reference Manual
Items
Input: Use the button to select the input (u).
Output: Use the button to select the output (y).
Linearize Type: Choose between Symbolic and Numeric linearization.
Linearize at: When you are performing numeric linearization, select Current time when you
want to linearize at the operating point where the simulation was stopped. Select Start of
simulation when you want to linearize at the start of the simulation. When you are
performing symbolic linearization, these options are not available, because any time
dependency will appear as a time parameter in your symbolic linear system.
Tolerances: 20-sim calculates a numerical linear state space model by small deviations of
the complete model from the chose setpoint. The deviations are based on the given absolute
and relative tolerances. For most models the default values are sufficient. For stiff models
you can change these values by hand.
OK: click the OK button to start Linearization.
Linearization Explained
During linearization you are asked to enter an input signal and an output signal of your (non-linear)
model. During linearization, 20-sim will derive a corresponding linear system. It is important to
understand that 20-sim will cut the model at the input. This will be explained with the example
model below. It shows a linear system with feedback.
Closed Loop
Suppose we would choose the following settings:
input u: WaveGenerator1\output
output y: Monitor1\input
This means that 20-sim will cut the model at the variable WaveGenerator1\output (equal to u in the
figure below) and linearize the model between this variable and the variable Monitor1\output
(equal to y in the figure below). 20-sim will thus linearize the system between u en y and (in this
example) and yield the closed loop system.
254
8. Frequency Domain Toolbox
Open Loop
Suppose we would choose the following settings:
input u: PlusMinus1\output
output y: Monitor1\input
This means that 20-sim will cut the model at the variable PlusMinus1\output (equal to u in the
figure below) and linearize the model between this variable and the variable Monitor1\input (equal
to y in the figure below). 20-sim will thus linearize the system between u en y and (in this example)
and yield the open loop system.
Frequency Response
Next to time domain analysis through the standard time domain plots, 20-sim can also show results
in the frequency domain through FFT analysis and Bode Plots. The picture below shows the various
actions and resulting plots.
Bode plots originate from linear systems theory. A bode plot shows the amplitude and phase
response (as a function of the frequency) of a linear system. In 20-sim linear systems can be derived
in the Simulator out of any linear or non-linear model (model linearization). The resulting linear
system is shown in the Linear System Editor. In this editor you can generate Bode plots. The
generation of Bode plots can be automated in the Frequency Response dialog. In this dialog you can
define the linearization settings and desired linearization output (Linear System Editor or Bode plot).
255
20-sim 4.0 Reference Manual
Procedure
1. Select the Frequency Response from the command from the Properties menu.
256
8. Frequency Domain Toolbox
Linearization Tolerances
When using numerical linearization, absolute and relative tolerances can be set. In this section is
explained how 20-sim uses these tolerances to derive a linear system for the model equations.
Algorithm
Suppose you have chosen the following tolerance values.
During the linearization procedure (suppose linearization from u to y ) 20-sim will vary the input
variable and state variables. First we will show the variation for the input u:
257
20-sim 4.0 Reference Manual
Out of this 20-sim will calculate the B and D vectors of the state-space ABCD representation:
Out of this 20-sim will calculate the A matrix and C vector of the state-space ABCD representation:
The example system is linear, so the corresponding ABCD representation will give an equal system.
The shown algorithm works equivalent for non-linear models. Suppose we have the following non-
linear model:
B = 2, D = 3, A = -1.668445, C = 1;
Tolerance Values
The absolute tolerance is necessary only if the input or state is zero. In that case the contribution of
the relative tolerance is zero an will not give a contribution to the algorithm. There is however a
problem with the absolute tolerance. Suppose the input = 1e-12 and the state = 1e+6 (ill-scaled
model). For the input an absolute tolerance of 1e-6 will yield a far too large deviation, while the
same absolute tolerance is negligible compared to the state. Only if both the state and input are
nonzero the absolute tolerance can be made non-zero to yield good results.
258
8. Frequency Domain Toolbox
Menu
Some menu items are of particular importance.
File: You can use the file menu to open, import and export linear systems.
Edit - Tolerance: You can specify the tolerance for transforming between state-space and
transfer functions.
Edit - Reduce System: You can reduce the system order by pole-zero cancelation. The
distance between poles and zeros to match for cancelation is given by the Reduction
Tolerance.
View: the view menu can be used for holding, clearing and refreshing plots.
System Description
Pressing the Edit button will open a dialog for editing the linear system. Each description
(State Space, Transfer Function, Zeros Poles Gain or Eigen Frequency) has a special dialog
and can be used to specify continuous-time and discrete-time systems.
259
20-sim 4.0 Reference Manual
In the 20-sim Simulator, out of an existing (non-linear) model a symbolic linear-system can
be derived by means of linearization. This means that the relevant model parameters are
preserved in the Linear System and the parameters button can be used to change
parameters.
Import/Export
Pressing the s<->z button will transform a continuous-time linear system into a
discrete-time linear system and back.
Pressing the Filter button opens the Filter Editor, where a filter can be designed. This filter
can then be combined with the current linear system or replace the current linear system. If
the linear system is a discrete-time system, the designed analog filter is automatically
transferred into its digital equivalent.
Pressing the From Matlab button and the To Matlab button allows for an instant
exchange of the linear system with the Matlab workspace. Information is transferred
numerically (no parameter relations are preserved)
The button is only active when a Linear System has been imported through
linearization. Clicking the button will import parameters from the simulation.
The button is only active when a Linear System has been imported through
linearization. Clicking the button will export the current parameters to the simulation.
Plots
You can inspect the time- and frequency responses of the linear system using:
Step Response
Bode Plot
Nyquist Plot
Nichols Chart
Poles and Zeros (including root locus)
Output
Clicking the 20-sim button will export the linear system as a new 20-sim submodel.
Clicking the Matlab button will export the 20-sim Linear System to a Matlab m-file. If the
Linear System is symbolic, all parameter relations are preserved.
The relation between the original model parameters and the linear system elements is always shown
in the white square of Linear System editor, just below the system description. An example is shown
in the first figure below:
260
8. Frequency Domain Toolbox
As you can see, the some elements of the A, B, C and D matrix are related to the spring constant
and masses of the original model.
Editing
A symbolic linear system can be edited by changing the original model parameters. Click the Edit
Parameters button and a Parameters Editor pops-up. Change the desired parameters, close the
Parameters Editor and the linear system will updated.
Updating Parameters
When the parameters have been changed in the Linear System Editor you can update the parameters
in the Simulator by clicking the Update to Simulator button . Click the Update from Simulator
button to do it the other way.
Exporting
You can export a symbolic Linear System to Matlab, with preservation of the parameter relations, by
clicking the Matlab button or selecting Export to Matlab command from the File menu. This will
generate an m-file that you can use in Matlab.
261
20-sim 4.0 Reference Manual
If you want to transfer a linear system directly (i.e. replace the z by and s or vice versa), click the
Edit button and select or deselect the Discrete Sample time.
Output Delay
Models with time delays can not be linearized in 20-sim, because there is no direct relation between
the inputs and outputs of the model. For systems with control loops it is however useful to see how
the unavoidable time delay of these loops can affect the model behaviour.
Therefore in the linear system editor you can add output delay. The effects of this output delay is
shown in the various plots that you can show of a linear system. The unit of the output delay is
seconds.
Note
Output delay is not saved when you store a linear system model and will therefore not affect the
behaviour of the model!
(continuous) (discrete)
where x is the state vector and u and y are the input and output vectors. These models may arise
from the equation of physics, from state space identification or as the result of linearization.
262
8. Frequency Domain Toolbox
You can enter state space models by selecting the State Space button and clicking the Edit button.
This opens an editor in which you can enter the A, B, C and D matrices. Depending on the selection
of the Discrete Linear System check box (and Sample Time) the system is a continuous-time or
discrete-time system. You can enter the matrix elements in the white space areas. Separate column
elements with Spaces or Commas. Enter new rows by clicking the Enter key (new line) or using a
semicolon. Brackets ( e.g. [ ... ] ) may be used to denote the a matrix or vector.
263
20-sim 4.0 Reference Manual
The A-matrix, shown in the figure above can for example be entered as:
01
-0.5 -1
or
0,1;-0.5,-1
or
[0,1;
-0.5,-1]
Output Delay
To inspect the effects of time delay in your model, you can add output delay. The result will be visible
in the various plots that you can show of a linear system. The unit of the output delay is seconds.
Discrete Sample Time
If you want to transfer a linear system from continuous time to discrete time directly (i.e. replace the
s by a z), select Discrete Sample time and fill in the sample time value. You can also transfer back
directly by deselecting Discrete Sample time.
Commands
Help: Open the help file.
Apply: Apply the current changes of the system, recalculate each plot that is active (step,
Bode, Nyquist, Nichols, pole zero).
OK: Apply the current changes of the system, recalculate each plot that is active (step,
Bode, Nyquist, Nichols, pole zero) and close the editor.
Cancel: Do not apply any changes to the system and close the editor.
Transfer Functions
A continuous time or discrete time SISO transfer function:
(continuous) (discrete)
264
8. Frequency Domain Toolbox
You can enter transfer functions by selecting the Transfer Function button and clicking the Edit
button.
This opens an editor in which you can enter the coefficients of the numerator and denominator
polynomials. You can enter the elements in the white space areas. Separate the elements with
Spaces. Polynomials should be entered in descending powers of s or z. The Steady State Gain, Root
Locus Gain and System Gain are parameters, that are automatically derived from the transfer
function.
265
20-sim 4.0 Reference Manual
0.1 0.1
and
1 1 0.5
or
0.1,0.1
and
1,1,0.5
Output Delay
To inspect the effects of time delay in your model, you can add output delay. The result will be visible
in the various plots that you can show of a linear system. The unit of the output delay is seconds.
Discrete Sample Time
If you want to transfer a linear system from continuous time to discrete time directly (i.e. replace the
s by a z), select Discrete Sample time and fill in the sample time value. You can also transfer back
directly by deselecting Discrete Sample time.
Commands
Help: Open the help file.
Apply: Apply the current changes of the system, recalculate each plot that is active (step,
Bode, Nyquist, Nichols, pole zero).
OK: Apply the current changes of the system, recalculate each plot that is active (step,
Bode, Nyquist, Nichols, pole zero) and close the editor.
Cancel: Do not apply any changes to the system and close the editor.
Gains
Steady State Gain
Given the transfer function:
Note that the steady state gain can be zero or infinite depending on the element values of the
numerator and denominator!
266
8. Frequency Domain Toolbox
where pi .. p1 are the poles and zi .. z1 are the zeros of the system. The gain KRL is known as the
Root Locus Gain. Note that it can easily be derived from the transfer function as:
System Gain
Given the transfer function:
If n0 and d0 are unequal to zero, this transfer function can be rewritten in pole zero notation with:
The gain KS is known as the System Gain. If n0 is zero and n1 is nonzero an equivalent notation can
be found with an extra s multiplied:
If more numerator element are zero, extra multiplications with s are added. The same goes for
denominator elements equal to zero. In general the System Gain can be derived from the transfer
function as:
267
20-sim 4.0 Reference Manual
The Root Locus Gain and the Steady State Gain are related as:
where pi .. p1 are the poles and zi .. z1 are the zeros and KRL is the Root Locus Gain of the system.
The same can be done for a discrete-time SISO transfer function.
You can enter zeros and poles by selecting the Zeros & Poles button and clicking the Edit button.
268
8. Frequency Domain Toolbox
This opens an editor in which you can enter the real and imaginary parts of the zeros and poles as
well as the Root Locus Gain. If preferred, you can also enter the System Gain. Note that zeros and
poles always have conjugate when the imaginary part is non-zero. I.e. when you enter a pole with
imaginary part 0.5 an extra pole is added with imaginary part -0.5.
Output Delay
To inspect the effects of time delay in your model, you can add output delay. The result will be visible
in the various plots that you can show of a linear system. The unit of the output delay is seconds.
Discrete Sample Time
If you want to transfer a linear system from continuous time to discrete time directly (i.e. replace the
s by a z), select Discrete Sample time and fill in the sample time value. You can also transfer back
directly by deselecting Discrete Sample time.
Commands
Add/Delete: Add or delete selected poles or zeros.
Help: Open the help file.
Apply: Apply the current changes of the system, recalculate each plot that is active (step,
Bode, Nyquist, Nichols, pole zero).
OK: Apply the current changes of the system, recalculate each plot that is active (step,
Bode, Nyquist, Nichols, pole zero) and close the editor.
Cancel: Do not apply any changes to the system and close the editor.
269
20-sim 4.0 Reference Manual
Eigen Frequencies
The Eigen Frequencies view is closely related to the pole zero notation and bode plot. It shows the
resonance frequencies and anti-resonance frequencies that result from the given poles and zeros as
well as some characteristic parameters from the bode plot.
Step Response
The Step Response command calculates the systems response y on a unit step input:
u = 0 (time < 0 )
u = 1 (time >= 0 )
270
8. Frequency Domain Toolbox
20-sim automatically generates an appropriate range for the time response, based on the system
dynamics. With the Plot Properties command (right mouse menu), you can change this horizon and
recalculate the step response (click the Step command again).
Plot Options
Using the right mouse menu, you can use several options:
Plot Properties: Set the general plot properties for the step response and specify the curve
properties.
Numerical Values: Inspect numerical values.
Step Characteristics: Display rise time, overshoot, settling time and the steady state value
of the step response.
Copy to Clipboard: Copy the plot to the windows clipboard.
Print: Print the plot.
Zoom in: Show a detail of the plot.
Zoom out: Show a larger portion of the plot.
Zoom Normal: Show the complete plot.
Bode Plots
Bode Plots show the amplitude and phase of a linear system as function of the frequency. Bode plots
can be shown for every 20-sim model through Linearization. During Linearization you are asked to
enter the input variable and output variable for which linearization should be performed. After that
the linear system is calculated and shown in the Linear System Editor. From the Linear System Editor
you can generate a bode plot. These actions can also be predefined using the Frequency Response
command of the Properties menu.
The magnitude part of the plot can be displayed in dB or in absolute values. The phase part can be
displayed in radians or degrees. The frequency can be displayed in radians per second or in Hz.
271
20-sim 4.0 Reference Manual
Plot Options
Using the toolbar or the right mouse menu, you can use various options:
Plot Properties: Set the plot properties.
Numerical Values: Inspect numerical values.
Magnitude (dB): Display magnitude in decibels
Magnitude (-): Display magnitude in absolute values.
Phase (rad): Display phase in radians.
Phase (deg): Display phase in degrees.
Frequency (rad/sec): Display frequency in radians per second.
Frequency (Hz): Display frequency in Hz.
Phase/Gain Margins: Display the gain and phase margins.
Modulus Margin: Display the Modulus Margin.
Peak Response: Display the peak response.
Copy to Clipboard: Copy the plot to the windows clipboard.
Print: Print the plot.
Zoom in: Show a detail of the plot.
Zoom out: Show a larger portion of the plot.
Zoom Normal: Show the complete plot.
Nyquist Diagram
The Nyquist command computes the Nyquist plot of a system.
20-sim automatically generates a range of real and imaginary parts, based on the system dynamics.
With the Plot Properties command (right mouse menu), you can change this horizon and
recalculate the Nyquist diagram (click the Nyquist command again).
Plot Options
Using the right mouse menu, you can use several options:
Plot Properties: Set the plot properties.
Numerical Values: Inspect numerical values.
Phase/Gain Margins: Display the gain and phase margins.
Modulus Margin: Display the Modulus Margin.
Copy to Clipboard: Copy the plot to the windows clipboard.
Print: Print the plot.
272
8. Frequency Domain Toolbox
Nichols Chart
The Nichols command computes the Nichols chart of a system.
273
20-sim 4.0 Reference Manual
20-sim automatically generates a range of real and imaginary parts, based on the system dynamics.
With the Plot Properties command (right mouse menu), you can change this horizon and
recalculate the pole zero diagram (click the Pole Zero command again).
Root Locus
You can show the rootlocus plot by selecting Root Locus from the right mouse menu. Inspect the
root locus gain by selecting Numerical Values from the right mouse menu.
Plot Options
Using the right mouse menu, you can use several options:
Plot Properties: Set the plot properties.
Numerical Values: Inspect numerical values.
Root Locus: Show or hide the root locus plot.
Copy to Clipboard: Copy the plot to the windows clipboard.
Print: Print the plot.
Zoom in: Show a detail of the plot.
Zoom out: Show a larger portion of the plot.
Zoom Normal: Show the complete plot.
Import Data
You can import data from measurements or other software tools to compare it with the response of
your model. 20-sim accepts data in two formats:
Gain-Phase: The data should be stored in a text-file with three columns. The first column
should contain the frequency and the second and third column, the corresponding gain and
phase data.
Real-Imag: The data should be stored in a text-file with three columns. The first column
should contain the frequency and the second and third column, the corresponding real and
imaginary data.
274
8. Frequency Domain Toolbox
Import Data
1. Open the Linear System Editor with your linear system.
2. Open the plot (e.g. Bode, Nyquist) in which you want to show the data.
3. Set the Magnitude (- or dB), Phase (rad or deg) and Frequency (rad/s or Hz) according to the
data you want to import.
4. In the Linear System Editor from the File menu select Import.
Now a file dialog opens helping you to select the file to import. When you have selected a file and
closed the dialog, the data should be visible in your plot. An example is shown in the figure above.
275
20-sim 4.0 Reference Manual
276
9 Mechatronics Toolbox
9.1 Cam Wizard
How to use the Cam Wizard
Cams and mechanisms are all based on the same principle. The motion of an input axis is
transformed to an output axis or translation. The transformation is a function of the input angle. This
function is called the cam motion profile.
The 20-sim cam wizard helps you to generate cam and mechanism models. You can use various
types of motion profiles which are continuous in velocity, acceleration or even in jerk! An example of
a mechanism that can be generated by the Cam wizard is the crank-rod mechanism, where a rotary
input motion is transformed to a translating output motion.
The models that are generated by the 20-sim Cam wizard are fully dynamic! This means:
The models describe the output velocity as function of the input velocity but also the input
torque as function of the output load.
The speed of the input axis does not have to be constant nor does the output load.
No inertia, stiffness or other dynamic behavior is included, but this can be easily
incorporated by coupling elements from the 20-sim library (inertias, springs etc.) to the
input or output of the model.
277
20-sim 4.0 Reference Manual
1. Open the model library and drag the model CamWizard.emx to the editor.
3. Select the camwizard model and click Go Down. Now the wizard will be opened.
4. Choose the desired motion profile, the profile parameters and type of output
(translation/rotation):
278
9. Mechatronics Toolbox
6. Enter the parameters values (Stroke, Start Angle Stop Angle). If you have chosen a
continuous pulse as output, you must also enter the values for the Return Angle and End
Angle:
279
20-sim 4.0 Reference Manual
Note
1. If you have changed the settings of this wizard, you have to process the model first (from the
Model menu, choose Check Complete Model) before the changes become effective.
2. You can change parameter values during simulation (from the Properties menu select
Parameters).
3. This is a masked model that uses the dll-file MotionProfile.dll to open the wizard. This dll-
function must be stored in the bin directory of 20-sim. To see the SIDOPS code of a masked
model press the shift-key, while clicking the Go Down command.
280
9. Mechatronics Toolbox
The continuous pulse motion output returns at the end of each cycle returns to the starting
position. It is characterized by the parameters stroke, start_angle, stop_angle, return_angle and
end_angle.
Motion Profiles
In mechanical engineering an important part of design is the reduction of vibrations. Every time a
construction is in motion, vibrations are induced. When cams or mechanisms are used, the amount of
vibrations, depend on the kind of motion that is induced. E.g. a sudden step change will induce
violent vibrations in comparison with with a fluent motion. An important parameter to characterize
motions, is the order:
1. Zero Order: Motions that are discontinuous in the position (e.g. a step).
2. First Order: Motions that are continuous in the position but discontinuous in the velocity (e.g.
a ramp).
3. Second Order: Motions that are continuous in the position and velocity but discontinuous in
the acceleration.
4. Third Order: Motions that are continuous in the position, velocity and acceleration.
5. Fourth Order: Motions that are continuous in the position, velocity, acceleration and jerk.
281
20-sim 4.0 Reference Manual
The specific shape of a motion profile can have a significant influence on the dynamic behavior. Some
profiles minimize the maximum velocity, some profile minimize acceleration, while other profiles tend
to make a tradeoff between the maximum velocity and acceleration. If we take a standard motion
with stroke 1 and motion time 1 sec., the following table can be generated:
Cubic 3 2 4 32 -32
1: Parameter CV = 20%
2: For lw >> lc the Crank Rod profile equals the sine profile, for lw > lc performance deteriorates.
3: Parameter CV = 20%, CA = 20%
4: Parameter n = 30%, alpha = 10%
5: Parameter BB = 30%, BM = 10%
Here y(0) is the initial jerk (derivative of acceleration) and y(1/2) the crossover (halftime) jerk.
282
9. Mechatronics Toolbox
Ramp
The ramp profile is a first order profile. It has a constant velocity and acceleration peaks at the start
and end of the motion.
If the rod is much longer than the crank, the resulting motion profile will approach the sine profile.
Below the motion profile is shown for half a rotation of the crank (angle from 0 to 180 degrees in 1
sec.).
If the rod gets smaller, the maximum velocity and acceleration increase.
Note: A real crank-rod mechanism will not suddenly stop at half a rotation and therefore not show a
discontinuous acceleration.
283
20-sim 4.0 Reference Manual
Trapezoidal
The trapezoidal profile is a second order profile. It has a constant acceleration at the start of the
motion and a constant deceleration at the end of the motion.
This profile is most widely used in early servo systems. Because of the discontinuity in the
acceleration this motion profile can still induce a lot of vibrations. Therefore in modern servo systems
third order profiles are preferred.
Partial Trapezoidal
The partial trapezoidal profile is a second order profile. It has is equal to the trapezoidal motion, but
has a constant velocity part, during a fraction CV (%) of the motion.
Geneva Mechanism
A Geneva mechanism is an old motion profile generation mechanism. A continuously rotating
crankshaft (a) generates an intermittent motion of a second shaft (b). The result is a second order
profile.
The motion profile generator yields the motion of the second shaft (b). It is shown below:
284
9. Mechatronics Toolbox
Sine
The sine profile is a second order profile of which the displacement can be described as:
x = 0.5 - cos ( * t) / 2.
Cubic
The cubic profile is a third order profile of which the acceleration is constantly increasing and
decreasing.
Partial Cubic
The partial cubic profile (3rd order) is a modified cubic profile with a constant velocity during a
fraction CV (%) of the motion and a constant acceleration during a fraction CA (%) of the motion.
285
20-sim 4.0 Reference Manual
Cycloidal
The cycloidal profile is a third order profile, of which the velocity can be described as:
v = stroke*(1-cos(t*a))
Modified Sine
The modified sine profile is also a third order profile. It is a modification of the cycloidal profile to get
a lower maximum velocity and a lower maximum acceleration.
Modified Trapezoidal
The modified trapezoidal profile is a modification of the trapezoidal profile (to make it a third order
profile). This profile yields a very low maximum acceleration.
286
9. Mechatronics Toolbox
3-4-5 Polynomial
The is a third profile described by a 5th order polynomial.
287
20-sim 4.0 Reference Manual
1-3-5-7-9 Polynomial
The is a third/fourth order profile described by a 9th order polynomial. The profile is characterized by
two parameters that denote the initial jerk, BB, and the crossover jerk, BM. If BB is chosen zero,
this a a fourth order profile. If BB is chosen non-zero, this is a third order profile.
288
9. Mechatronics Toolbox
289
20-sim 4.0 Reference Manual
6. You can enter as many profiles as needed to design the complete motion. You can choose out
of a number of predefined profiles.
In the last page, you can choose to generate Time Events and what to show the next time (the
wizard or the generated code). Use the default settings if you are not sure what to use.
290
9. Mechatronics Toolbox
10. In the Editor from the Model menu Check Complete Model to make the changes effective.
291
20-sim 4.0 Reference Manual
3. Select the model and click Go Down. Now the wizard will be opened.
During simulation the parameter values are used that you have selected in the wizard. These
parameters are available in the Parameters Editor where you can change them as you would do with
any other model. If you have changed the settings of this wizard, you have to process the model first
(from the Model menu, choose Check Complete Model) before the changes become effective.
Motion Profiles
You can choose out of a number of predefined motion profiles in the Motion Profile Wizard.
Flat
Ramp
Trapezoidal
Partial Trapezoidal
Geneva Mechanism
Sine
Cubic
Partial Cubic
Cycloidal
Standard Modified Sine
Modified Trapezoidal
Modified Sine with Constant Velocity (MSC50)
General Modified Sine with Constant Velocity (MSC%)
3-4-5 Polynomial
1-3-5-7-9 Polynomial
Flat
The flat profile is a zero order profile. It has a constant position, zero velocity and acceleration.
292
9. Mechatronics Toolbox
Ramp
The ramp profile is a first order profile. It has a constant velocity and acceleration peaks at the start
and end of the motion.
Trapezoidal
The trapezoidal profile is a second order profile. It has a constant acceleration at the start of the
motion and a constant deceleration at the end of the motion.
This profile is most widely used in early servo systems. Because of the discontinuity in the
acceleration this motion profile can still induce a lot of vibrations. Therefore in modern servo systems
third order profiles are preferred.
Partial Trapezoidal
The partial trapezoidal profile is a second order profile. It has is equal to the trapezoidal motion, but
has a constant velocity part, during a fraction CV (%) of the motion.
293
20-sim 4.0 Reference Manual
Geneva Mechanism
A Geneva mechanism is an old motion profile generation mechanism. A continuously rotating
crankshaft (a) generates an intermittent motion of a second shaft (b). The result is a second order
profile.
A Geneva mechanism.
The motion profile generator yields the motion of the second shaft (b). It is shown below:
Sine
The sine profile is a second order profile of which the displacement can be described as:
x = 0.5 - cos ( * t) / 2.
294
9. Mechatronics Toolbox
Cubic
The cubic profile is a third order profile of which the acceleration is constantly increasing and
decreasing.
Partial Cubic
The partial cubic profile (3rd order) is a modified cubic profile with a constant velocity during a
fraction CV (%) of the motion and a constant acceleration during a fraction CA (%) of the motion.
Cycloidal
The cycloidal profile is a third order profile, of which the velocity can be described as:
v = stroke*(1-cos(t*a))
295
20-sim 4.0 Reference Manual
Modified Sine
The modified sine profile is also a third order profile. It is a modification of the cycloidal profile to get
a lower maximum velocity and a lower maximum acceleration.
Modified Trapezoidal
The modified trapezoidal profile is a modification of the trapezoidal profile (to make it a third order
profile). This profile yields a very low maximum acceleration.
296
9. Mechatronics Toolbox
3-4-5 Polynomial
The is a third profile described by a 5th order polynomial.
1-3-5-7-9 Polynomial
The is a third/fourth order profile described by a 9th order polynomial. The profile is characterized by
two parameters that denote the initial jerk, BB, and the crossover jerk, BM. If BB is chosen zero,
this a a fourth order profile. If BB is chosen non-zero, this is a third order profile.
297
20-sim 4.0 Reference Manual
To keep the polynomial consistent, i.e. the polynomial does not change when the amplitude is
changed, the initial jerk (BB) and the crossover jerk (BM) are defined for a standard motion with:
stroke = 1
start_time = 0
stop_time = 1
Comparison of Profiles
The specific shape of a motion profile can have a significant influence on the dynamic behavior. Some
profiles minimize the maximum velocity, some profile minimize acceleration, while other profiles tend
to make a tradeoff between the maximum velocity and acceleration. If we take a standard motion
with stroke 1 and motion time 1 sec., the following table can be generated:
Flat 0 0 0 0 0
Cubic 3 2 4 32 -32
298
9. Mechatronics Toolbox
1: Parameter CV = 20%
2: For lw >> lc the Crank Rod profile equals the sine profile, for lw > lc performance deteriorates.
3: Parameter CV = 20%, CA = 20%
4: Parameter n = 30%, alpha = 10%
5: Parameter BB = 30%, BM = 10%
Here j(0) is the initial jerk yerk (derivative of acceleration) and j(1/2) the crossover (halftime) jerk.
299
20-sim 4.0 Reference Manual
1. Brush DC
The dynamic models are generated automatically from data files containing commercially available
motors, but you can also enter your own motor parameters. The following motors are available on
data files:
In the first part of these help files, the use of the 20-sim Servo Motor Editor is explained. The Editor
uses a data table with motor parameters of commercial servo motors. You can select any motor from
the table, inspect the corresponding torque speed curve and let the Servo Motor Editor generate a
20-sim dynamic model from the parameters.
The second part of these help files, explains the operating principles of the motors. A good indication
of the performance of permanent magnet motors can be given by the torque speed plot. Various
curves of the torque speed plot and how this can be used to choose the proper motor for a given
task. An important part of the torque speed plot is the maximum continuous torque. It is the
maximum torque that a motor can deliver without overheating. This curve is based on a thermal
model of the motor, which is also explained.
300
9. Mechatronics Toolbox
Use
The 20-sim Servo Motor Editor is part of the Mechatronics Toolbox of 20-sim. You can open the
editor by selecting the Servo Motor Editor command (Tools - Mechatronics Toolbox). If you
have a valid license, a servo motor model will be inserted:
Normally the editor will be opened automatically. If this does not happen, force the editor to open by
clicking the Go Down button. This Editor looks like:
301
20-sim 4.0 Reference Manual
The top of the editor shows a list of motors. You can select one of the motors from the list by
selecting it with your mouse pointer. The selected motor is shown with the blue line. The parameters
of the selected motor are shown below the list.
To see the torque speed plot of the selected motor, click the Plot tab at the bottom of the editor. To
find a motor based on specific searching conditions, click the Search tab. By clicking the OK button, a
dynamic model will be created automatically, based on the selected motor in the list.
Using the Edit menu, new motors can be added to the list or deleted. By double clicking the mouse
pointer on a parameter value, it can be changed.
302
9. Mechatronics Toolbox
Data Files
If you open the Servo motor Editor, default data from file ServoMotor.csv is shown. You can open
other data files by using the file menu.
1. ServoMotor.csv: A selection of various motors to show the capabilities of the Servo Motor
Editor.
2. Maxon 2006.cse: The complete list of Maxon motors, program 2005 / 2006.
Parameters
Unfortunately not all motor suppliers use the same parameters in the data sheets. Therefore the
Servo Motor Editor uses the most common parameters as described in this section. All parameters
are defined using a motor temperature and ambient temperature of 25° C.
General Data
This general section contains the unique identifier of the motor (Keyname) and some additional data,
which can be filled in freely.
Name The name of the motor
Info Additional Info
Keyname A unique name (no duplicates allowed in the motor list) to
identify the motor.
303
20-sim 4.0 Reference Manual
Nominal Data
Many data sheets describe the nominal operating point of a motor. The nominal operation point is
characterized by a fixed current that is supplied to a motor with an initial temperature of 25º C that
will result in a heating up of the coils to the exactly the maximum temperature. Because a current
alone is not enough to describe the state of a motor, the operating point is always given at a certain
speed. Although the other parameters (torque and power) can be derived from the current and speed
they are usually printed in most data sheets.
Torque [N.m]or Force[N] Torque or force at nominal operation.
Current [A] or [Arms] Current at nominal operation.
Speed [rpm]or [m/s] Speed at nominal operation.
Voltage [V] or [Vrms] Voltage at nominal operation.
Power [W] The output power at nominal operation.
Life [hour] Expected Lifetime of the motor under normal operation.
As described, the definition of current and voltage depends on the selected motor:
motor current voltage
1. AC Synchronous rms phase current (A) rms phase to phase voltage (V)
2. Brush DC Iron current (A) voltage (V)
3. Brush DC moving coil current (A) voltage (V)
4. Brush DC Disc Rotor current (A) voltage (V)
5. AC Synchronous Linear rms phase current (A) rms phase to phase voltage (V)
6. Brushless DC peak current (A) peak phase to phase voltage (V)
304
9. Mechatronics Toolbox
Max/Peak Values
The maximum parameters indicate the maximum performance of the motor and are used to show
the limits in the torque speed plot as explained in chapter 3. The parameters do not indicate an
operating point on the torque speed curve. The maximum parameters are preferably measured at a
temperature of 25º C.
Torque [N.m]or Force[N] The maximum short-time or torque or force (also known as
stall torque).
Current [A] or [Arms] The maximum short-time current.
Speed [rpm]or [m/s] The maximum speed.
Voltage [V] or [Vrms] Maximum short-time voltage.
Power [W] The maximum short time power.
The currents and voltages are defined the same as for the nominal parameters.
Electrical Data
R [ohm] The resistance at 25° C.
L [H] The terminal inductance.
alpha_c [1/degC] The temperature dependency of the coil resistance.
ktc [1/degC ] The temperature dependency of the magnets.
poles [-] or pitch[m] The number of poles (always an even number) or pole pitch
(distance N-N poles).
As described, the definition of resistance and inductance depends on the selected motor:
motor resistance inductance
1. AC Synchronous phase to phase resistance phase to phase inductance (H)
(ohm)
2. Brush DC Iron resistance (ohm) inductance (H)
3. Brush DC moving coil resistance (ohm) inductance (H)
4. Brush DC Disc Rotor resistance (ohm) inductance (H)
5. AC Synchronous Linear phase to phase resistance phase to phase inductance (H)
(ohm)
6. Brushless DC phase to phase resistance phase to phase inductance (H)
(ohm)
Mechanical Data
The mechanical data describes the motor inertia and losses.
J_rotor [kg.m2] or m_motor [kg] The rotor inertia or the the moving mass of the
motor.
d [N.m.s/rad]or [N.s/m] Mechanical damping and eddy current losses.
T_fric [N.m] or [N] Mechanical friction and hysteresis losses.
T_cog [N.m] or [N] The amplitude of the cogging torque.
305
20-sim 4.0 Reference Manual
Thermal Data
The thermal data is used for the thermal model as explained in chapter 4. Zero values for the
thermal resistances are replace by a small value (1e-2) to prevent division by zero.
Temp_amb [degC] The ambient temperature.
Temp_initial [degC] The initial temperature of the coils and housing.
Temp_max [degC] The maximum coil temperature.
RT1 [degC/W] The thermal resistance between rotor and
stator.
RT2 [degC/W] The thermal resistance between stator and
environment.
CT1 [J/degC] Thermal capacity of the rotor.
CT2 [J/degC] Thermal capacity of the stator.
Physical Data
This section describes the motor dimensions and maximal load.
F_axial [N] The maximum axial force applied to the motor
shaft.
F_radial [N] The maximum radial force applied to the motor
shaft.
m [kg] The motor weight.
D_motor [m] The motor diameter.
L_motor [m] The motor length.
D_shaft [m] The shaft diameter.
L_shaft [m] The shaft length.
Derived Data
These are values that can be found in many data sheets. They are useful for selection criteria when
searching for motors.
K_nom [N.m/A], [N.m/Arms] or The torque constant or force constant at 25° C
[N/Arms] and nominal currents.
K_max [N.m/A], [N.m/Arms] or The torque constant or force constant at 25° C
[N/Arms] and at peak currents.
S [N.m.s/rad] or [N.s/m] The steepness.
tau_m [s] The mechanical time constant (J_rotor/S or
m_motor/S).
P_dis [W] The maximal continuous dissipation.
tau_T1 [s] The thermal time constant of the rotor (RT1*
CT1).
tau_T2 [s] The thermal time constant of the stator (RT2*
CT2).
306
9. Mechatronics Toolbox
Additional Data
20-sim model [] Not implemented yet.
Desired
Some parameters are desired. I.e. they add more detail to the model:
Nominal Torque or Force Torque or force at nominal operation.
Nominal Current Current at nominal operation.
Nominal Speed Speed at nominal operation.
alpha_c The temperature dependency of the coil resistance.
ktc The temperature dependency of the magnets.
poles or pitch The number of poles (always an even number) or pole
pitch (distance N-N poles).
d Mechanical damping and eddy current losses.
T_fric Mechanical friction and hysteresis losses.
T_cog The amplitude of the cogging torque.
Temp_amb The ambient temperature.
Temp_initial The initial temperature of the coils and housing.
Temp_max The maximum coil temperature.
RT1 The thermal resistance between rotor and stator.
RT2 The thermal resistance between stator and
environment.
CT1 Thermal capacity of the rotor.
CT2 Thermal capacity of the stator.
307
20-sim 4.0 Reference Manual
If you do not know the values of these parameters, fill in zero. 20-sim will automatically change
some into small numbers to prevent division by zero. Because the nominal torque and current are
used to derive the torque constant at nominal operation, they will be replaced by the maximum
current and torque if you fill in a zero value.
Torque Speed Plot
Some parameters will add more detail to the torque speed plot:
Speed The maximum speed.
Voltage Maximum short-time voltage.
Power The maximum short time power.
Additional
The remaining parameters are not used in the torque speed plot or the 20-sim model. They are
useful for selection criteria when searching motors. If you do not know the values of these
parameters, fill in zero.
Dynamic Model
If you have selected a motor, clicking the OK button will close the editor and generate a dynamic
model. The model will be filled with the parameters from the selected motor and is ready for the use
in a simulation. The model contains a number of variables that may be useful to show in a simulation
plot.
General Part
R resistance at simulated (fluctuating) temperature
K torque constant at simulated (fluctuating) temperature
u_rms_ff effective terminal (phase-phase) voltage
u_tt_ff maximum terminal (phase-phase)
i_tt maximum phase current
phi shaft angle
Thermal part
Temp_coil coil temperature
Temp_housing housing temperature
308
9. Mechatronics Toolbox
By default, the file ServoMotor.csv is shown. Using the File menu you can store and open csv files.
The csv files can be edited with the Servo Motor Editor or an external spreadsheet program like MS
Excel. In MS Excel the file looks like:
The top 5 rows contain the description of the motor parameters and the corresponding units. The
first and second row are used for rotation motors and the third and fourth row are used for linear
(translation) motors. The fifth row contains the parameter names.
The other rows contain the motor parameters. The meaning of these parameters is described in the
previous sections. Please use the following guidelines when editing data files:
309
20-sim 4.0 Reference Manual
3. Do use commas
6. Do net enter other information in additional rows or columns. The Servo Motor Editor will try
to read all cells and halt if the content is not according the specifications.
7. Do no add comment.
8. The last column entry (20-sim) should contain one white space character.
General Data
Name Motor Series
Keyname Maxon Order Number
Info Additional Information
Type DC
Date 21 October 2005
Price -
Delivery Time stock / standard / special
Library Maxon 2006.cse
Nominal Data
Torque Max. continuous torque
Current Max. continuous current
Speed No load speed divided by 2
310
9. Mechatronics Toolbox
Voltage Calculated
Power Calculated
Max/Peak Data
Torque Stall torque
Current Starting current
Power Assigned Power Rating
Voltage Calculated*
Speed Max. permissible speed
Thermal Data
Temp_amb Set to 25
Temp_initial Set to 25
Temp_max Maximum rotor temperature
RT1 Thermal resistance rotor-housing
RT2 Thermal resistance housing-ambient
CT1 Calculated
CT2 Given by Maxon
Physical Data
F_axial Maximum Axial load
F_Radial Maximum radial load
m Weight of motor
D_motor Diameter of motor
L_motor Length of motor
D_shaft Diameter shaft
L_shaft Length Shaft
Electrical Data
R Terminal resistance
L Terminal inductance
alpha_c Given by Maxon
Ktc Given by Maxon
Poles Number of poles
Mechanical Data
J_rotor Rotor inertia
d Given by Maxon
T_fric Given by Maxon
T_cog 0
Derived Data
K_nom Calculated
K_max Calculated
S_nom Calculated
P_dis Calculated
* In the data sheets Maxon only gives a nominal voltage. According to Maxon higher operating
voltages are permissible provided that other limits are not exceeded. Therefore the maximum
311
20-sim 4.0 Reference Manual
voltage is chosen equal to the voltage that is needed to run a motor with zero load at maximum
speed.
EC motors with block commutation
Maxon EC motors can be driven by block commutation and sine commutation. The Maxon data
sheets give the parameters for block commutation. To distinguish between block commutation and
sine commutation the character b or s is added to the keyname.
Servo Motor Editor Maxon Data Sheets
General Data
Name Motor Series
Keyname Maxon Order Number + b
Info Additional Information
Type Brushless DC
Date 21 October 2005
Price -
Delivery Time stock / standard / special
Library Maxon 2006.csv
Nominal Data
Torque Calculated
Current Max. continuous current
Speed Nominal speed
Voltage Calculated
Power Calculated
Max/Peak Data
Torque Stall torque
Current Calculated
Power Assigned Power Rating
Voltage Calculated*
Speed Max. permissible speed
Thermal Data
Temp_amb Set to 25
Temp_initial Set to 25
Temp_max Maximum rotor temperature
RT1 Thermal resistance rotor-housing
RT2 Thermal resistance housing-ambient
CT1 Calculated
CT2 Calculated
Physical Data
F_axial Maximum Axial load
F_Radial Maximum radial load
m Weight of motor
D_motor Diameter of motor
L_motor Length of motor
312
9. Mechatronics Toolbox
General Data
Name Motor Series
Keyname Maxon Order Number + s
Info Additional Information
Type AC Synchronous
Date 21 October 2005
Price -
Delivery Time stock / standard / special
Library Maxon 2006.csv
Nominal Data
Torque Calculated
Current Calculated
Speed Nominal speed
Voltage Calculated
313
20-sim 4.0 Reference Manual
Power Calculated
Max/Peak Data
Torque Calculated
Current Calculated
Power Assigned Power Rating
Voltage Calculated*
Speed Calculated
Thermal Data
Temp_amb Set to 25
Temp_initial Set to 25
Temp_max Maximum rotor temperature
RT1 Thermal resistance rotor-housing
RT2 Thermal resistance housing-ambient
CT1 Calculated
CT2 Calculated
Physical Data
F_axial Maximum Axial load
F_Radial Maximum radial load
m Weight of motor
D_motor Diameter of motor
L_motor Length of motor
D_shaft Diameter shaft
L_shaft Length Shaft
Electrical Data
R Terminal resistance phase to phase
L Terminal inductance phase to phase
alpha_c Given by Maxon
Ktc Given by Maxon
Poles Number of poles
Mechanical Data
J_rotor Rotor inertia
d Given by Maxon
T_fric Given by Maxon
T_cog 0
Derived Data
K_nom Calculated
K_max Calculated
S_nom Calculated
P_dis Calculated
* In the data sheets Maxon only gives a nominal voltage. According to Maxon higher operating
voltages are permissible provided that other limits are not exceeded. Therefore the maximum
voltage is chosen equal to the voltage that is needed to run a motor with zero load at maximum
speed.
314
9. Mechatronics Toolbox
Tecnotion 2006
File
20-sim 3.6\Tools\Servo Motor Dynamics\Tecnotion 2006.cse
Date
November 2006
More information
www.tecnotion.com
Description
The data file Tecnotion 2006.cse contains the complete set of Tecnotion motors, program 2006. Most
of the data has been extracted from the Tecnotion data sheets. The tables below shows the 20-sim
names and the corresponding data sheet names. Some parameters were not available in the data
sheets and have been given by the Tecnotion motor company. These parameters are indicated as
Given by Tecnotion. Some parameters were calculated. These are indicated as Calculated.
Important: The nominal data and the default value of the thermal resistance RT2 are calculated for
air cooling. The value for RT2 can be changed using a slider. If water cooling is used, change
the value of RT2 to its minimum value.
Servo Motor Editor Tecnotion Data Sheets
General Data
Name Motor Series
Keyname Order Number
Info Additional Information
Type AC Synchronous Linear
Date 21 October 2005
Price -
Delivery Time -
Library Tecnotion 2006.cse
Nominal Data
Force Continuous Force (air cooled*)
Current Continuous Current (air cooled*)
Speed 0 m/s
Voltage Calculated
Power -
Max/Peak Data
Force Ultimate Force / Peak Force
Current Ultimate Current / Peak Current
Power Calculated
Voltage Max. voltage ph-ph
Speed Maximum speed
Thermal Data
Temp_amb Set to 25
Temp_initial Set to 25
315
20-sim 4.0 Reference Manual
* Note: The nominal data and the default value of the thermal resistance RT2 are calculated for air
cooling. The value for RT2 can be changed using a slider. If water cooling is used, change the
value of RT2 to its minimum value.
Faulhaber 2006
File
20-sim 3.6\Tools\Servo Motor Dynamics\Faulhaber 2006.cse
Date
February 2006
More information
www.faulhaber-group.com or www.minimotor.ch
316
9. Mechatronics Toolbox
Description
The data file Faulhaber 2006.cse contains the most of the Faulhaber servo motors, program 2006.
Most of the data has been extracted from the Faulhaber data sheets. The tables below shows the 20-
sim names and the corresponding data sheet names. Some parameters were not available in the
data sheets and have been given by Faulhaber. These parameters are indicated as Given by
Faulhaber. Some parameters were calculated. These are indicated as Calculated.
DC motors
Servo Motor Editor Faulhaber Data Sheets
General Data
Name Motor Name
Keyname Faulhaber Order Number
Info Additional Information
Type DC
Date 23 February 2006
Price -
Delivery Time -
Library Faulhaber 2006.cse
Nominal Data
Torque Calculated
Current Current up to
Speed No load speed divided by 2
Voltage Calculated
Power Calculated
Max/Peak Data
Torque Stall torque
Current Calculated
Power Output Power
Voltage Nominal Voltage
Speed No-load speed
Thermal Data
Temp_amb Set to 25
Temp_initial Set to 25
Temp_max Maximum coil temperature
RT1 Thermal resistance rotor – housing Rth1
RT2 Thermal resistance housing-ambient Rth1
CT1 Calculated
CT2 Calculated
Physical Data
F_axial Maximum Axial load
F_Radial Maximum radial load
m Weight of motor
D_motor Diameter of motor
317
20-sim 4.0 Reference Manual
General Data
Name Motor Name
Keyname Faulhaber Order Number
Info Additional Information
Type DC Brushless
Date 23 February 2006
Price -
Delivery Time -
Library Faulhaber 2006.cse
Nominal Data
Torque Torque up to
Current Current up to
Speed At speed
Voltage Calculated
Power Calculated
Max/Peak Data
Torque Stall torque
Current Calculated
Power Output Power
Voltage Nominal Voltage
318
9. Mechatronics Toolbox
319
20-sim 4.0 Reference Manual
320
10 Real-Time Toolbox
10.1 Real Time Toolbox
The Real Time toolbox of 20-sim allows you to create C-code out of any 20-sim model for the use in
real-time applications:
2. Create Matlab / Simulink S-functions for the use in the Matlab Real-Time Workshop.
The generation of Matlab / Simulink code is can be performed using the Export command of the
Editor File menu. You can also use the C-code generation command of the Simulator Tools menu.
The generation of C-code can be done with the C-code generation command of the Simulator Tools
menu.
321
20-sim 4.0 Reference Manual
322
10. Real-Time Toolbox
General Structure
The code generation process of 20-sim typically has the following structure:
Step 1
2. In the 20-sim Simulator, the user selects the C-Code Generation command from the Tools
menu.
4. A target configuration file is read that specifies the different code generation targets that
exist.
5. The C-code generation dialog is opened, allowing the user to specify the target to use.
Step 2
1. The selected target refers to specific template files (source files) in a target specific
subdirectory.
2. 20-sim adapts these template files with the model information and generated code for the
model.
Step 3
2. These files are now specific for the target and the model.
3. If desired, 20-sim can call additional commands for further processing (f.i. make, run etc).
323
20-sim 4.0 Reference Manual
The target list shows the names of the available targets. When a selection is made, the description of
the selected target is given at the right. A submodel can be selected when the target requires this.
The output directory can be overruled.
Targets
The user can create own targets. All targets are defined in the target definition file Targets.ini.
This file has a typical INI-file structure and starts with a section that simply enumerates which
targets exist. Each target then has its own section that holds the remaining information, like a short
description of the target, the name of the template directory, the names of the template source files,
additional commands to perform, etc. The following keywords may appear in a target section:
Templates
Each target can point to a set of template files that are used to create C-Code with. Own template
files can be created by the user, with the help of the most powerful feature of 20-sim C-Code
generation: the use of tokens! A token is a placeholder for model-dependent information. For
instance in the C-Code Generation Dialog, the target destination directory contains the name of the
selected submodel (e.g. c:\ temp\%SUBMODEL_NAME%) by default. Since this information is not yet
known when the targets.ini file is created, a specific token that refers to this name is used instead. A
complete description of predefined tokens is described in the section about Available 20-sim Tokens.
Generation Result
After the tokens in the target template files are replaced, the resulting target and model specific files
will be placed in the destination directory. If commands are specified in the Targets.ini file, these
commands are performed. This allows the user to call scripts automatically. E.g. for automatic
compilation, linking and running of the code in a certain target environment.
324
10. Real-Time Toolbox
targetName
="string"
The name that will appear in the 20-sim C-Code Generation Dialog.
iconFile
="string"
The name of an icon file (.ico) that contains an icon to appear in the 20-sim C-Code Generation
Dialog.
description
="string"
The string that will appear in the description field in the 20-sim C-Code Generation Dialog.
templateDirectory
="string"
Here the path name where the template files for the c-code can be found can be specified. The
default name is the target name in the CCode directory of 20-sim. If no full path is specified, the
Ccode directory in 20-sim is taken as a starting point.
templateFiles
=filename1; filename2; filename3...
A list of files, semicolon-separated, that specify the files that are generated in the targetDirectory.
targetDirectory
="string"
This holds the default target directory where the files will be generated. This directory name will
appear in the 20-sim dialog box when C-Code is generated and can be overruled by the user.
submodelSelection
=TRUE (default)
=FALSE
Determines whether C-Code is generated for the complete 20-sim model, or that a submodel
selection is required.
preCommand
="string"
A command which will be executed in the target directory before that the C-Code will be generated.
325
20-sim 4.0 Reference Manual
postCommand
="string"
A command which will be executed in the target directory after that the C-Code has been generated.
For example a "make" command can be given to automatically compile the generated code for the
specific target.
newLineCharacter
=0 CRLF (0x0d0a = DOS Standard)
=1 CR (0x0d = Macintosh Standard)
=2 LF (0x0a = Unix Standard)
Enter a number for the kind of newline character that should be used.
%KEYWORD%
=value
This (re)defines the keyword "KEYWORD" and gives it the contents "value". Own keywords can be
defined in this manner as well.
example:
%XX_TIME%=someTime
Example
A valid Targets.ini file (defining three targets) may look like below. The file may also contain specific
20-sim tokens (%MODEL_NAME%) that are described later on.
326
10. Real-Time Toolbox
templateFiles=xxtypes.h;%MODEL_NAME%.dsp;%MODEL_NAME%.dsw
targetDirectory="c:\temp\%MODEL_NAME%"
327
20-sim 4.0 Reference Manual
A token is a placeholder for model-dependent information. For instance in the code generation dialog,
the target destination directory contains the name of the selected submodel by default. Since this
information is not yet known when the targets.ini file is created, a specific token that refers to this
name is used instead.
The idea is to create targets from template source files that contain tokens instead of actual model-
dependent information (like equations, names, parameters, inputs etc). The files that are specified in
a target section will be scanned for these tokens and tokens will be replaced by the corresponding
model-dependent information.
Predefined variable names
The following variables should be declared in the C-Code template, because 20-sim uses these
names in the generation of the equations:
c: constant array
P: parameters array
V: variables array
s: states array
R: rates array
M: matrix array
U: unnamed variables array
F: favorite variables array
f: favorite parameters array
Model Data
The following tokens will be replaced by numbers indicating the number of model parameters etc.,
typically used in memory allocation parts and loops.
328
10. Real-Time Toolbox
Initialization code
An important part of a model are the parameters, initial values states etc. To match these with the
generated model code and use the correct values the following tokens can be used:
%INITIALIZE_CONSTANTS%
%INITIALIZE_PARAMETERS%
%INITIALIZE_MATRICES%
%INITIALIZE_STATES%
%INITIALIZE_DEPSTATES%
%INITIALIZE_ALGLOOPS%
%INITIALIZE_CONSTRAINTS%
%INITIALIZE_INPUTS%
%INITIALIZE_OUTPUTS%
%INITIALIZE_FAVORITE_PARS%
%INITIALIZE_FAVORITE_VARS%
329
20-sim 4.0 Reference Manual
Equations
The following tokens can be used to place 20-sim simulation model equations into the C-Code:
%INITIAL_EQUATIONS% Equations that should be calculated once for initialization of the model
%STATIC_EQUATIONS% Equations that should be calculated once
%INPUT_EQUATIONS% Equations that should be calculated once at the beginning of every
%DYNAMIC_EQUATIONS% simulation step
%OUTPUT_EQUATIONS% Equations that calculates the dynamic part of the model, calculates the
%OUTPUT2_EQUATIONS% rates.
%FINAL_EQUATIONS% Equations that should be calculated once at the end of every simulation
step
Reduced set of equations that should be calculated at the end of every
simulation step.
Equations that should be calculated once for termination of the model
Inputs/Outputs
To match model inputs and model outputs to for example sensor signals and actuator signals you can
use:
%INPUT_TO_VARIABLE_EQUATIONS%
%VARIABLE_TO_OUTPUT_EQUATIONS%
%ALIAS_EQUATIONS%
%FAVORITE_PARS_EQUATIONS%
%FAVORITE_VARS_EQUATIONS%
Additional tokens
Experiment Tokens
Tokens which hold information about the model, experiment, user and system:
330
10. Real-Time Toolbox
331
20-sim 4.0 Reference Manual
332
11 Time Domain Toolbox
11.1 Time Domain Toolbox
The Time Domain Toolbox contains powerful tools to inspect the behaviour of your model using time
domain simulation.
Parameter sweep: Perform a number of simulation runs, while changing model parameters.
Optimization: Optimize a given result by changing parameters.
Curve Fitting: Fit your model to a given result by changing parameters.
Tolerance Analysis
Sensitivity: Change parameters by a given percentage and monitor results.
Monte Carlo: Change parameters statistically and monitor results.
Variation Analysis: Find the statistical range of parameters to yield a given result.
External DLL: Let the multiple run be controlled by a user-defined function in a DLL.
Procedure
1. From the Toolbox menu select the Time Domain Toolbox and then the tool that you want
to use.
2. This will open the Multiple Run Wizard. Follow the instructions and after all settings have been
entered, close the wizard.
3. Select the Multiple Run command from the Simulation menu to perform the specified
analysis.
4. After simulation is completed a special window will open to showing the results. If it is not
available, you can always open this window, by selecting the Multiple Run Results command
of the View Menu.
333
20-sim 4.0 Reference Manual
A window will open, asking you which parameters / initial values should be changed during the
multiple simulations:
Result
A window opens asking you which result (optional) should be shown after the simulations:
334
11. Time Domain Toolbox
4. If you do not want to use a result after simulation, enter nothing here. If you like to present a
result after the simulation, enter it here using the various options of the window.
Run options
A window will open, asking some simulation run options:
335
20-sim 4.0 Reference Manual
6. Select the desired run options and click the Next button.
A window will open with a summary of the chosen options. If your are not satisfied you can use the
Back button to go to a previous window and change settings.
8. From the Simulation menu click the Multiple Run command to perform the Parameter
Sweep.
336
11. Time Domain Toolbox
9. By choosing the Values button, a new window is opened, showing the numerical results of
the parameter sweep.
In the Results list of this window the subsequent runs are shown and (if available) the value of the
chosen result:
337
20-sim 4.0 Reference Manual
338
11. Time Domain Toolbox
11.3 Optimization
Using the Optimization option of the Time Domain Toolbox, you can optimize a given result using
variation of parameters / initial values.
Optimization Method
1. From the Tools menu select the Time Domain Toolbox and then Optimization.
3. Select the Tolerance (accuracy of the found optimum) that should be used and click Next.
339
20-sim 4.0 Reference Manual
340
11. Time Domain Toolbox
Result
A window opens asking you which result should optimized:
6. Enter the result here using the various options of the window.
341
20-sim 4.0 Reference Manual
Run options
A window opens asking some simulation run options:
8. Select the desired run options and click the Next button.
A window opens with a summary of the chosen options. If your are not satisfied you can use the
Back button to go to a previous window and change settings.
10. From the Simulation menu click the Multiple Run command to perform the Optimization.
Optimization Results
After simulation has been done, an Optimization Results window will open, showing the optimum
value of the result and corresponding parameters:
342
11. Time Domain Toolbox
11. By choosing the Values button, a new window is opened, showing the numerical results of
the parameter sweep.
In the Results list of this window the subsequent runs are shown and (if available) the value of the
chosen result:
343
20-sim 4.0 Reference Manual
result = f(i,v1,v2,...)
with i the number of the simulation run. You also have to specify the parameters that should be
varied to find the optimum result. We can group these parameters in a parameter vector:
with again i the number of the simulation run. All methods in 20-sim for finding an optimum of the
result use the same iterative process:
1. The initial parameter vector is determined, e.g. p(1) and the corresponding function value
f(1).
3. Perform a new simulation run to find the parameter vector p(2) = p(1) + s(1)*r(1).
4. Calculate f(2).
5. When the f(2) is smaller than f(1) and the difference between the two is smaller than a given
tolerance, stop the process. The optimum has been found.
6. When the f(2) is smaller than f(1) and the difference between the two is larger than a given
tolerance, proceed the process at step 2
7. Otherwise a new stepsize and/or a new search direction are determined and the process is
proceeded at step 3.
The choice of the stepsize is of importance for the speed an accuracy of the search process. A small
stepsize will make the optimization process last very long. A large stepsize will make it less accurate.
Most methods will therefore use a variable stepsize.
Of equal importance is the proper choice of the search direction. Methods for finding the search
direction, can be divided in two groups: direct search methods and gradient search methods. The
gradient of a function, is its slope at a certain point. Gradient search methods use this slope to find
the optimal direction of search.
344
11. Time Domain Toolbox
Methods
The optimization methods that are supported in 20-sim will now be explained. The pictures at the
right visualize the methods with two varying parameters x (horizontal) and y (horizontal) and the
corresponding result (vertical).
345
20-sim 4.0 Reference Manual
346
11. Time Domain Toolbox
Users are therefore advised to use methods 1 and 2 only for optimizations with one parameter, and
use the methods 7 and 8 for optimizations with more parameters. Use the other methods for
checking the results or educational purposes.
Bazaraa, M.S., Sherali, H.D., Shetty C.M. (1990), Nonlinear Programming, Theory and Algorithms,
John Wiley & Sons Inc. New York, ISBN 0-471-59973-5.
347
20-sim 4.0 Reference Manual
Optimization Method
1. From the Tools menu select the Time Domain Toolbox and then Curve Fittting.
A window opens asking you which optimization method should used for curve fitting:
3. Select the Tolerance (accuracy of the found fit) that should be used and click Next.
348
11. Time Domain Toolbox
Result
A window opens asking you which result should minimized to fit your model (variable 1) to a given
result (variable 2):
349
20-sim 4.0 Reference Manual
6. Enter the result here using the various options of the window.
Run options
A window opens asking some simulation run options:
8. Select the desired run options and click the Next button.
A window opens with a summary of the chosen options. If your are not satisfied you can use the
Back button to go to a previous window and change settings.
10. From the Simulation menu click the Multiple Run command to perform the Curve Fitting.
350
11. Time Domain Toolbox
Optimization Results
After simulation has been done, the Optimization Results window will open, showing the minimum
value of the result and corresponding parameters:
11. By choosing the Values button, a new window is opened, showing the numerical results of
the parameter sweep.
In the Results list of this window the subsequent runs are shown and the value of the chosen
result:
351
20-sim 4.0 Reference Manual
352
11. Time Domain Toolbox
11.6 Sensitivity
Using the Tolerance Analysis option of the Multiple Run Wizard, you can analyze the effects of
variation of parameters / initial values on the performance of your model. Three methods of
Tolerance analysis are supported in the Multiple Run Wizard. One of these methods is Sensitivity
analysis.
Sensitivity analysis starts with a simulation run with nominal parameter values. After the run a given
result is monitored (r). Then, one by one, each parameter (pi) is changed with a given percentage (to
pi + dpi) and a simulation run is performed. After the simulation run the changed result is monitored
(r + dri). After all the runs, the results are displayed as sensitivities, where sensitivity is defined as
the change in result divided by the change in parameter:
Si = dri / dpi
A large sensitivity means that the result is highly dependant of the parameter value. This can be
used for optimization (change the parameter value) or design (change the design to make it less
dependant of the parameter).
353
20-sim 4.0 Reference Manual
Result
A window opens asking you which result should be monitored for the sensitivity:
5. Enter the result here using the various options of the window.
Run options
A window opens asking some simulation run options:
354
11. Time Domain Toolbox
7. Select the desired run options and click the Next button.
A window opens with a summary of the chosen options. If your are not satisfied you can use the
Back button to go to a previous window and change settings.
9. From the Simulation menu click the Multiple Run command to perform the Sensitivity
Analysis.
10. By choosing the Multiple Run Values button, a new window is opened, showing output of
the various runs performed during the sensitivity analysis:
In the Results list of this window the subsequent runs are shown and the corresponding sensitivities.
355
20-sim 4.0 Reference Manual
356
11. Time Domain Toolbox
Result
A window opens asking you which result should be monitored during the Monte Carlo Analysis:
357
20-sim 4.0 Reference Manual
4. Enter the result here using the various options of the window.
Run options
A window opens asking some simulation run options:
358
11. Time Domain Toolbox
6. Select the desired run options and click the Next button.
A window opens with a summary of the chosen options. If your are not satisfied you can use the
Back button to go to a previous window and change settings.
8. From the Simulation menu click the Multiple Run command to perform the Monte Carlo
Analysis.
359
20-sim 4.0 Reference Manual
9. By choosing the Multiple Run Values button, a new window is opened, showing output of
the various runs performed during the Monte Carlo analysis.
360
11. Time Domain Toolbox
Using Variation analysis, you can perform a predefined number of simulation runs with variation of
parameter values according to a predefined distribution function. During the runs a given result is
monitored. After the runs the statistical range of the result is presented. You can restrict the
parameter distributions to get the result between desired bounds.
Result
A window opens asking you which result should be monitored during the Variation Analysis:
361
20-sim 4.0 Reference Manual
4. Enter the result here using the various options of the window.
Run options
A window opens asking some simulation run options:
362
11. Time Domain Toolbox
6. Select the desired run options and click the Next button.
A window opens with a summary of the chosen options. If your are not satisfied you can use the
Back button to go to a previous window and change settings.
8. From the Simulation menu click the Multiple Run command to perform the Variation
Analysis.
363
20-sim 4.0 Reference Manual
9. By choosing the Multiple Run Values button, a new window is opened, showing output of
the various runs performed during the Variation analysis:
364
11. Time Domain Toolbox
The result can be a function of one or two variables. Instead of the second variable an (offset) value
can be entered.
Items
Choose Variable: Select this button to select a model variable
Clear: Use this button the remove a chosen model variable.
Function:
End value: The value at the end of the simulation run.
Sum Absolute Value: The sum of all absolute values during a simulation run.
Sum Square Value: The sum of all values squared during a simulation run.
Integral Absolute Value: The integral of all absolute values during a simulation run (uses
Euler integration).
Integral Square Value: The integral of all values squared during a simulation run (uses Euler
integration).
365
20-sim 4.0 Reference Manual
2. Use the Choose button to select as var1 the output of your function.
366
Index
-12 153, 161 Add New 29
* 125, 152 Add to Favorites 69
.* 153 Add to Input Probes 69
./ 154 Add to Output Probes 69
.^ 154 Add/Delete 72, 334
.cse 309 Addition 152
.csv 309 Additional Outputs 201
.emxz 19 adjoint 132
/ 155 After the run 322
[ 179 Algebraic 69, 109
] 179 algebraic loop in 36
^ 156 algebraic loop out 36
+ 126, 152, 162 Algebraic loops 40, 84, 182
< 158 algebraic solver 84
<= 159 Algebraic variables solved 23
<> 159 Alias 56
== 160 alias variable 36
> 160 Alias Variables 69
>= 161 All Runs 67
1-3-5-7-9 Polynomial 281, 292 Allow model updates 23
20-sim Filter Editor 259 Allow Symbol Prefixes 57
20-sim library 7 Always perform brute force simulation 23
20-sim Model 201 analog filter 259
20-sim Scenery 201 Analyze Causality 27
3 dimensional objects 321, 333 AND 157
32-bit machine code 36 Animation Properties 222
3-4-5 Polynomial 281, 292 ANSI-C Code 322
3D Animation 67, 321, 333 ANSI-C Function 322
3D Animation Properties 222 antisym 133
3D Representation 194 Apply Regularization 240
ABCD matrix 252 arccos 147
abort 172 arccosh 147
Abs 109 Archive 18
Absolute 85, 86, 152 arcsin 146
absolute tolerance 257 arcsinh 147
absolute value 109 arctan 148
acceleration 289 arctanh 148
across 52 Array 180
activation function 232 Array Division 154
Activation Function Type 234 Array Multiplication 153
Active 72 Array Power 154
Actuated Joints 207 Artificial intelligence 231, 236
Actuator Properties dialog 215 As Constraint Joint 207
Adams-Bashford 85 atan2 148
367
20-sim 4.0 Reference Manual
368
Index
369
20-sim 4.0 Reference Manual
370
Index
371
20-sim 4.0 Reference Manual
kind 69 Magnetic 52
Lang. Ref. 89, 90, 91, 98, 106, 109, 151, 163 main model 17, 23
Laplace variable 264 Main Model / Submodel 23
Larger Than 160, 161 major 104
Last Run 67 Manager 23
layers 231 Manipulate 225
Learn after Leaving Spline 236, 240 Mark 68
Learn at each Sample 236, 240 mask 259
learning rate 234, 236, 240 Matlab 32, 69, 173, 174, 175, 252, 322, 334
Less Than 158, 159 Matlab-Code folders 26
Libraries 26 Matlab-Code Generation 26
library 7, 14 Matrices 30, 69, 179
Library File 23 Matrix 179, 180
Library Folders 26 Matrix Declaration 179
library names 26 Matrix is assigned a scalar 23
Library Path 23 Matrix Notation 179
library paths 26 Matrix Operators 180
Library tab 7, 193 Matrix Use 180
License 2, 4 max 138
limint 114 Maximum 85, 86
limit 115 Maximum allowed lost time 79
Limited Integration 114 Maximum nr. of var. to show in varlist 26
Line 13 Maximum Step Size 86
Line Color 13 Maxon 310
Line Style 13 Maxon motors 310
linear differential equations 262 measured data 249
Linear System Editor 259 measurement 229
linear time- invariant models 259 Mechanical 52
Linearization moment 23 mechanisms 277
Linearization Tolerances 257 mega 57
Linearization Type 23 Melt equal junctions 22
Linearize at 252 Message Log 59
Linearize Model 252 Message window 194
linsolve 137 M-file 32
Load Scene 227 micro 57
Load Weights at Start of Simulation 234, 240 milli 57
Locate License File 4 min 138
locks 225 Minimize/Maximize 339
Log 115 Minimum / Maximum 334, 339
log10 116 MLP Network 232
log2 116 Mod 156
Logarithm 116 Model contains algebraic loops 23
Loop 3D Animation on replay 23 Model contains algebraic variables 23
Loops 40, 182 Model contains constraint variables 23
low 50 Model contains dependent states 23
Machine Code 36 Model Help 23
372
Index
373
20-sim 4.0 Reference Manual
374
Index
375
20-sim 4.0 Reference Manual
376
Index
377
20-sim 4.0 Reference Manual
378
20-sim is a modeling and simulation program that runs
under Microsoft Windows. With 20-sim you can
simulate the behavior of dynamic systems, such as
electrical, mechanical and hydraulic systems or any
combination of these.