Contents Previous Next Index
2 Example: Exporting a Model as an FMU File
2.1 Preparing a Model for Export
In this example, you will perform the steps required to prepare a slider-crank mechanism model and export it as an FMI file.
1. Convert the slider-crank mechanism model to a subsystem.
2. Define subsystem inputs and outputs.
3. Define and assign subsystem parameters.
4. Export the model using the FMI file Generation app.
To open the slider-crank mechanism example:
In MapleSim, click the Help menu item.
Select Examples > User's Guide Examples > Chapter 6, and then select Planar Slider-Crank Mechanism.
Converting the Model to a Subsystem
By converting your entire model or part of your model into a subsystem, you identify which parts of the model you want to export. Since the FMI connector supports data signals and properties on acausal connectors such as mechanical flanges and electrical pin, in this example, you will group all of the components into a subsystem and use an acausal input into the subsystem.
To create a subsystem:
Draw a box around all of the components in the model by dragging your mouse over them.
From the Edit menu, select Create Subsystem.
In the Create Subsystem dialog box, enter SliderCrank as the subsystem name.
Click OK. A SliderCrank subsystem block appears in the model workspace.
Defining Subsystem Inputs and Outputs
MapleSim uses a topological representation to connect interrelated components without having to consider how signals flow between them, whereas traditional signal-flow modeling tools require explicitly defined system inputs and outputs. In this example, since FMI supports causal and acausal ports, a torque driver is used as an input to the subsystem in MapleSim and for the FMU file.
You will convert the displacements of the slider and the joint between the crank and connecting rod to output signals. The input will be a torque driver that is applied to the revolute joint that represents the crank shaft.
To create a subsystem output port:
Double-click the subsystem block to view its contents. The broken line surrounding the components indicates the subsystem boundary, which can be resized by clicking and dragging its sizing handles.
Delete the probes that are attached to the model.
In the Library Components tab (
) on the left side of the MapleSim window, expand the Multibody palette and then expand the Sensors submenu.
Drag the Absolute Translation component to the Model Workspace and place it below the Prismatic Joint component.
Right-click (Control-click for Mac®) the Absolute Translation component and select Rotate Counterclockwise.
From the Signal Blocks > Routing > Demultiplexers menu, drag a Real Demultiplexer component to the Model Workspace and place it to the right of the Absolute Translation component.
To connect the Absolute Translation component to the model, click the frame_b connector. The frame is highlighted in green when you hover your pointer over it.
Draw a vertical line and click the connection line directly above the component. The sensor is connected to the rest of the diagram.
In the same way, connect the r output port (TMOutputP) of the Absolute Translation component to the input port of the demultiplexer. This is the displacement signal from the sensor in x, y, and z coordinates. Since the slider only moves along the x axis, the first coordinate must be an output signal.
Hover your pointer over the first demultiplexer port and click your mouse button once.
Drag your pointer to the subsystem boundary and then click the boundary once. A real output port is added to your subsystem.
Add another Absolute Translation component above the Connecting Rod subsystem.
Right-click (Control-click for Mac) the Absolute Translation component and select Flip Vertical. Right-click the Absolute Translation component again and select Rotate Clockwise.
Add a Real Demultiplexer component to the right of the sensor and connect the components as shown below. Since the crank is moving in the x, y plane, you only need to output the first two signals. You are now ready to add a real input port to your subsystem to control the torque on the crank shaft.
Click on the white flange of the leftmost Revolute Joint and drag the pointer to the left boundary. This will act as the acausal input connection to the subsystem.
The complete subsystem appears below.
Click Main (
) in the Model Workspace toolbar to browse to the top level of the model.
From the 1-D Mechanical > Rotational > Torque Drivers menu, add a Torque component to the Model Workspace and place it next to the subsystem.
From the Signal blocks>Common menu, add a Constant signal component to the Model Workspace and next to the Torque component and connect it to the Torque component.
Click Attach Probe (
) above the Model Workspace toolbar and then click the top output port of the SliderCrank subsystem.
In the Model Workspace, click the probe once to position it.
In the same way, add probes to the other SliderCrank output ports as shown below.
2.2 Defining and Assigning Subsystem Parameters
You can define custom parameters that can be used in expressions in your model to edit values more easily. To do so, you define a parameter with a numeric value in the parameter editor. You can then assign that parameter as a variable to the parameters of other components; those individual components will then inherit the numeric value of the parameter defined in the parameter editor. By using this approach, you only need to change the value in the parameter editor to change the parameter values for multiple components.
To edit parameters
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.
In the first Name field, type CrankL and press Enter.
Change the Type to Length from the drop-down menu.
Specify a default value of 1m and enter Crank length as the description.
In the second row of the table, define a parameter called ConRodL and press Enter.
Specify a default value of 2m and enter Connecting Rod Length as the description.
Click Diagram View (
) to switch to the diagram view, and then click Main (
Select the SliderCrank subsystem. The parameters are defined in the Properties tab (
Double-click the SliderCrank subsystem, and then select the Crank subsystem.
In the Properties tab (
), change the length value (L) to CrankL. The Crank subsystem now inherits the numeric value of CrankL that you defined.
Select the ConnectingRod subsystem and change its length value to ConRodL.
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 to an FMI block.
2.3 Exporting Your Model Using the FMU File Generation App
After preparing the model, you can use the FMU Generation app to set export options and convert the model to an FMU file.
To generate an FMU file
Select the Add Apps or Templates tab (
Double-click on the FMU Generation entry in the Apps palette. The Analysis window opens with the FMU Component Code Generation app loaded in the Apps tab.
In the Subsystem Selection section, select the SliderCrank subsystem from the drop-down list, and then click Load Selected Subsystem. All of the app fields are populated with information specific to the subsystem.
Since this example uses an acausal 1D - mechanical rotational flange, on selecting the input option, you have the option to either choose a torque or an angle input that can be fed into the subsystem.
In the Export section, specify the location for the Target Directory, Visual C++ Directory and provide a name for the generated FMU Archive.
Click Generate FMU Archive to generate the .FMU zip file.
Download Help Document
What kind of issue would you like to report? (Optional)