MapleSim BR Connector Getting Started Guide
MapleSim BR Connector Getting Started Guide
Maplesoft, Maple, and MapleSim are all trademarks of Waterloo Maple Inc.
iii
Introduction
The B&R MapleSim™ Connector provides all of the tools you need to prepare and export your dynamic systems
models into B&R Automation Studio ANSI-C source code from a MapleSim model. You can create a model in
MapleSim, simplify it in Maple™ by using an extensive range of analytical tools, and then generate the source code
that you can incorporate into your toolchain.
System Requirements
For installation instructions and a complete list of system requirements, see the Install.html file on the product disc.
Distribution of an FMU
Under the terms and conditions of the Maplesoft End User License Agreement, you have the right to use an FMU
created with the B&R MapleSim Connector within your organization. If you wish to distribute this FMU outside
your organization, you must first obtain a FMU Commercial Distribution License from Maplesoft. For more
information, see FMU Distribution.
iv
1 Getting Started
1.1 Working with Apps
The B&R MapleSim Connector includes the following apps:
• B&R Automation Studio FMU Generation app — Generate a custom B&R FMU archive that can be used in B&R
Automation Studio.
• B&R SERVOsoft Data Generation app — Generate a Microsoft® Excel spreadsheet that contains the operational
data (time, velocity, thrust) for a motion driver in the model. The spreadsheet can be used by the SERVOsoft® drive
design tool that's in B&R Automation Studio.
Other apps are included in MapleSim itself, such as the 1-D Motion Generation app.
This chapter describes how to use the B&R MapleSim Connector to generate an FMU archive for use in B&R Auto-
mation Studio.
The next chapter describes how to use the B&R SERVOsoft Data Generation app.
For information about the BRConnector package, in Maple, refer to the BRConnector help page.
With this app, you can define inputs and outputs for the subsystem, set the level of code optimization, generate the
source code, and choose the format of the resulting FMU component and library code. You can use any Maple commands
to perform task analysis, assign model equations to a variable, group inputs and outputs and define additional input
and output ports for variables.
1
2 • Getting Started
Note: FMU component generation now handles all systems modeled in MapleSim, including hybrid systems with
defined signal input (RealInput) and signal output (RealOutput) ports.
Example models are available in MapleSim. To access these, from the Help menu, select Examples > BR Connector
Examples.
To connect a subsystem to modeling components outside of its boundary, you add subsystem ports to your model. A
subsystem port is an extension of a component port in your subsystem. The resulting signals can then be directed as
inputs and outputs for the FMU archive file. By creating a subsystem you improve the visual layout of a system in the
model workspace and also prepare the model for export. The Preparing the 2-D Rigid Slider Crank Model for Export
Using Subsystems (page 8) section in Chapter 2 shows you how to group all of the components into a subsystem.
You can select which subsystems from your model you want to export to an FMU archive file. To begin, select a sub-
system.
After selecting a subsystem, click Load Selected Subsystem. All defined input and output ports are loaded.
After the subsystem is loaded you can group individual input and output variable elements into a vector array, and add
additional input and output ports for customized parameter values. Input ports can include variable derivatives, and
output ports can include subsystem state variables. You can specify prefixes for both input and output port variables.
The prefix for the input (output) port variables will be applied to all the variables in the input ports (outputs) table.
3 • Getting Started
Note: If the parameters are not marked for export they will be numerically substituted. Parameters marked as tunable
will also be marked for export by default. However, tunable parameters will be ignored if FMI Version and Environment
(see Step 3: Export Options) are anything other than FMI 2.0 and Co-Simulation. To use fully qualified parameter
names for the generated FMU, check the corresponding check box; otherwise, short parameter names will be used by
default.
The Port and Parameter Management interface lets you customize, define and assign parameter values to specific ports.
Subsystem components to which you assign the parameter inherit a parameter value defined at the subsystem level.
Solver Options
Specify the solver and step size.
For the Implicit Euler (stiff) solver, you can select between a symbolic or numeric approximation to the system Jacobian.
Visualization Options
For models with multibody components, the B&R Generation app creates an FMU that includes a B&R specific scene
file, which can be used to create an animation in B&R Automation Studio.
Select Export geometric shapes/primitives to control whether geometric shapes or primitives are exported.
Set the Max projection iterations to specify the maximum number of times that a projection is permitted to iterate to
obtain a more accurate solution.
Set the Error tolerance to specify the desirable error tolerance to achieve after the projection.
Select Apply projection during event iterations to interpolate iterations to obtain a more accurate solution.
Constraint projection is performed using the constraint projection routine in the External Model Interface as described
on The MathWorks™ website to control the drift in the result of the DAE system.
satisfied, the system result may deviate from the actual solution and could lead to an increase in error at an exponential
rate.
Set the Max event iterations to specify the maximum number of times that a projection is permitted to iterate to obtain
a more accurate solution.
Set the Width of event hysteresis band to specify the desirable error tolerance to achieve after the projection.
Event projection is performed using the event projection routine in the External Model Interface as described on The
MathWorks website to control the drift in the result of the DAE system.
Note: Currently, if the model has events, they are handled using the event handling functions in the generated Msim-
Model.c file, and not the FMI provided Event Handling routines.
Author: Name and organization of the model author (for example, J. Smith, Maplesoft http://www.maplesoft.com).
Description: Brief description of the model (for example, Model of a lithium-ion battery).
License: Intellectual property licensing (for example, Proprietary, Public Domain, or BSD License).
Step 5: Export
Generating the FMU archive creates temporary files for viewing purposes.
Provide a name for the generated FMU archive in FMU Archive Name.
Select Remove temporary `fmiTMPXXXXXX`directory to remove temporary files after code generation.
To generate an FMU archive click Generate FMU Archive. The file is saved to the target directory.
To view an example:
1. From the Help menu, select the Examples > BR Connector Examples submenu.
2. Click the entry for the model that you want to view.
Note: Some models may include additional documents, such as templates that display model equations or define custom
components. These are found in the Attached Files tab.
5. Click Load Selected Subsystem. All of the app fields are populated with information specific to the subsystem
displayed in the model diagram. You can now specify which subsystem parameters will be kept as configurable
parameters in the generated block.
6. Under the Export Options section, select all the Visualization options:
7. In the Export section of the app, specify the target directory and name.
8. Click Generate FMU Archive. The FMU file is created and saved in the target directory.
2.1 Preparing the 2-D Rigid Slider Crank Model for Export Using
Subsystems
Preparing a Model
This example starts with a slider crank model and prepares it for export by grouping the necessary components in a
subsystem. At the end of the process, the example will look like the example model used in the FMU Generation
Example: Slider Crank Model (page 6) section of the Chapter 1. This step is necessary before exporting your model
to an FMU.
To create a subsystem:
1. Using the selection tool ( ) located in the Model Workspace Toolbar, draw a box around all of the components
in the model.
8
9 • Further Examples
In this example, you will convert the displacements of the slider and the joint between the crank and connecting rod
to output signals. The input signal needs to be converted to a torque that is applied to the revolute joint that represents
the crank shaft. A spherical geometry component is also added for visualization purposes.
5. To connect the Angle Sensor component to the model, click the triangular y connector. The frame is highlighted
in green when you hover your pointer over it.
7. Click the boundary once. A real output port is added to your subsystem.
8. Connect the other end of the Angle Sensor to the white flange of revolute joint Revolute1.
Since the B&R connector supports causal and acausal ports, an acausal input is added outside of the subsystem to
control the torque on the crank shaft.
9. From the 1-D Mechanical > Rotational > Torque Drivers menu, add a Torque component to the Model Workspace
and place it above the Fixed Frame component.
10. Click on the white flange of the leftmost Revolute Joint R1 and drag the pointer to the left boundary. This will act
as the acausal input connection to the subsystem.
11. From the Multibody > Visualization palette, select the Spherical Geometry component and add it above the Rigid
Body component. Use Edit > Flip Horizontal to flip the component and then connect it to both Revolute3 and the
Rigid Body component.
12. Add a probe: Click Attach Probe( ) above the Model Workspace toolbar and then click the connection line from
Revolute1 to Angle Sensor. Click the probe once to position it.
13. In the Properties tab, name the probe crank, and select Angle, Angular velocity, and Torque to measure these
quantities.
11 • Further Examples
14. Click Main ( ) in the Model Workspace toolbar to browse to the top level of the model.
15. From the 1-D Mechanical > Rotational > Torque Drivers menu, add a Torque component to the Model Workspace
and place it next to the subsystem. Connect its output port to the input port of the SliderCrank subsystem.
16. From the Signal Blocks > Controllers palette, drag a PID component into the model workspace and connect its
output port to the input signal port of the Torque component. The result is shown below.
17. Click on the PID and in the Properties tab set k to 400, Ti to 0.5 s, and Td to 0.1 s.
12 • Further Examples
18. From the Signal Blocks > Math > Operators palette, drag a Feedback component into the model workspace and
connect its output port to the input port of the PID component.
19. Click the Feedback component, and from the Edit menu, select Flip Vertical.
20. Connect the Feedback component to the PID component and the SlidingCrank subsystem to the Feedback com-
ponent.
21. From the Signal blocks>Common menu, add a Constant signal component to the Model Workspace and connect
it to the input of the Feedback component.
22. The model is prepared and ready to use with the apps in the B&R MapleSim Connector.
To edit parameters
1. Double-click the SliderCrank component on the Model Workspace to see the detailed view of the SliderCrank
subsystem, and then click Parameters ( ) in the Model Workspace toolbar. The parameter editor appears.
2. In the first Name field, type CrankL and press Enter.
3. Change the Type to Length from the drop-down menu.
4. Specify a default value of 1m and enter Crank length as the description.
5. In the second row of the table, define a parameter called ConRodL and press Enter.
6. Change the Type to Length from the drop-down menu.
7. Specify a default value of 2m and enter Connecting Rod Length as the description.
8. Click Diagram View ( ) to switch to the diagram view, and then click Main ( ).
9. Select the SliderCrank subsystem. The parameters are defined in the Properties tab ( ).
10. Double-click the SliderCrank subsystem, and then select the Crank subsystem.
11. In the Properties tab ( ), change the length value (L) to CrankL. The Crank subsystem now inherits the numeric
value of CrankL that you defined.
12. Select the ConnectingRod subsystem and change its length value to ConRodL.
14 • Further Examples
13. Click Main ( ) in the Model Workspace toolbar to navigate to the top level of the model. You will include these
parameter values in the model that you export. You are now ready to convert your model in the B&R Connector
App.
2.3 Exporting Your Model Using the B&R Automation Studio FMU
Generation App
After preparing the model, you can use the B&R Automation Studio FMU Generation app to set export options and
convert the model to an FMU file. In this example, the Slider Crank Subsystem is exported as an FMU block for which
the controller can be designed in the Automation Studio.
5. In the Export section, specify the location for the Target Directory, Visual C++ Directory and provide a name
for the generated FMU Archive.
6. Click Generate FMU Archive to generate the .FMU zip file.
15 • Further Examples
5. Change the Height from Segment Properties to 1 and choose Sinusoid from the drop down menu and click Apply.
6. Click on Add Right again and change the Height to -1 from the Segment Properties.
17 • Further Examples
Symbols V
Visualization Options, 4
1-D Motion Generation App, 15
A
Apps, 1
B&R Automation Studio FMU Generation, 14
B
B&R Connector Examples Palette, 2
B&R FMU Generation, 1
B&R SERVOsoft Data Generation, 15
C
Constraint Handling Options, 4
Converting the model to a subsystem, 8
D
Defining subsystem inputs and outputs, 9
E
Event Handling Options, 4
Examples
Slider Crank Model, 6, 8
Viewing Examples, 6
Export Geometric Shapes, 4
Export Options, 3
Export Primitives, 4
G
Generate
FMU Archive, 6, 14, 15
L
License
Distribution of FMU, iv
P
Port and Parameter Management, 2, 3
Preparing a model, 8
S
Solver Options, 3
Subsystem parameters, 12
Subsystem Selection, 2
T
Tutorial Using B&R FMU Generation App, 6
18