Implement an FMU Block
Implement a block and assign a functional mockup unit (FMU) to it. You can then explore the block to see the FMU. This example uses theFMUblock with the vehicle FMU.
Create a model and add theFMUblock.
In the block dialog box, enter the path name for an FMU file in theFMU nameparameter and clickOKorApply. The file extension
.fmu
is optional.The first time you clickOKorApply, the block identifies which FMU mode to set your FMU to, co-simulation or model exchange.
The block also creates a
slprj/_fmu/fmu_name
folder and unpacks the contents of the FMU file into this folder, which optionally include:binaries
— FMU binary filesdocumentation
— FMU documentation HTML filesresources
— FMU source filessources
— FMU source filesOther supporting files, such as block mask and description files
The FMU block icon and port labels update to the labels of the corresponding FMU. After you associate the block with an FMU, if you want to change the FMU, right-click the FMU block, and selectBlock Parameters, and enter a new FMU name inFMU name. The section in this topic use the FMU from theSimplify Interface for Structured Data with FMU Import Blockexample.
Explore the FMU Block
Double-click the block. Suppose that you entered an FMU namedfmuVehicAOB.fmu
from your current folder. TheFMUblock dialog box reflects the FMU parameters defined in thefmuVehicAOB.fmu
file.
Parameters Tab
Lists the FMU block parameters. Edit the values as necessary. You can edit the elements of a structure parameter by expanding the tree view.
Simulation Tab
Enables logging and associated customizations.
To enter a relative tolerance, selectEnable FMU toleranceand set it.
To determine the sample time of the block in the model, setCommunication step size. To inherit the step size from the Simulink®solver, set to
-1
. This option is available only if the FMU is a co-simulation FMU.To enable logging, select theEnable FMU Debug Logging.
InRedirect debug logs to, select the destination for the logs.
File
, saved toslprj\_fmu\_logs_
modelname
\modelname_blockname
.txtDisplay
, displayed in the MATLAB®Command Window.
If theEnable FMU Debug Loggingcheck box is selected and theRedirect debug logs toparameter is set to
Display
, you cannot use the FMU block for co-simulation. For more information on co-simulation and multiple cores, seeRun Co-Simulation Components on Multiple CoresIn theFilter logs by return status, select the check box for the return status you want.
Input and Output Bus Tabs
These two tabs list the input and output bus objects that the block defines.
In theBus Object Nameparameter, you can change the bus object names to match the bus objects defined in the workspace.
To create a bus object in the workspace:
fmudialog.createBusType(gcb)
Change Block Input, Output, and Parameter Structures
You can change the layout of FMU block input ports, output ports, and parameters with these parameters:
Parameter | Action | Settings |
---|---|---|
FMUInputMapping |
Change hierarchy of input ports. |
|
FMUOutputMapping |
Change hierarchy of output ports. |
|
FMUParamMapping |
Change hierarchy of parameters. |
|
Use theget_param
andset_param
functions to set these values. For example, assume a block parameter tab with a structure construct:
The parameters are contained in astruct
. To list the parameters individually, set theFMUParamMapping
property to'Flat'
:
set_param(gcb,'FMUParamMapping', 'Flat')
Timing Considerations
You can set the sample time for the FMU block with theCommunication step sizeparameter. This block sample time setting,tC, like all Simulink blocks, must be an integer multiple of the model sample time,tM. Simulink generates an error if the communication step sizetCis not a multiple of the model step sizetM.
The local step size of the FMUtL, on the other hand, is part of the FMU specification and is known to the FMU only internally. For proper operation, the communication step size,tCmust also be an integer multiple oftL. If the model sample timetMor the block sample timetCis incompatible with the FMU local step sizetL, the FMU may or may not produce an error at run time, depending on its implementation.
Troubleshooting FMUs
If there are problems with using the FMU:
Check the compliance of the FMU with the FMI standard. Use theFMU compliance checker.
Select theEnable FMU Debug Loggingcheck box on the FMU block Simulation tab.
Contact the FMU supplier.