Main Content

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.

  1. Create a model and add theFMUblock.

  2. In the block dialog box, enter the path name for an FMU file in theFMU nameparameter and clickOKorApply. The file extension.fmuis 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 aslprj/_fmu/fmu_namefolder and unpacks the contents of the FMU file into this folder, which optionally include:

    • binaries— FMU binary files

    • documentation— FMU documentation HTML files

    • resources— FMU source files

    • sources— FMU source files

    • Other 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.fmufrom your current folder. TheFMUblock dialog box reflects the FMU parameters defined in thefmuVehicAOB.fmufile.

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.txt

    • Display, displayed in the MATLAB®Command Window.

    If theEnable FMU Debug Loggingcheck box is selected and theRedirect debug logs toparameter is set toDisplay, you cannot use the FMU block for co-simulation. For more information on co-simulation and multiple cores, seeRun Co-Simulation Components on Multiple Cores

  • In 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.

'Flat'— Separates input into individual signals.

'Structured'— Combines input into a structure of signals (bus).

FMUOutputMapping Change hierarchy of output ports.

'Flat'— Separates output into individual signals.

'Structured'— Combines output into a structure of signals (bus).

FMUParamMapping Change hierarchy of parameters.

'Flat'— Separates parameters into individual parameters, listed by the parameter name and value.

'Structured'——结合参数的结构参数r values (struct).

Use theget_paramandset_paramfunctions 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 theFMUParamMappingproperty 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.

See Also

|

Related Topics

External Websites