export a model as a tool-coupling fmu
to integrate simulink® components into third-party software, export a simulink model as a tool-coupling functional mockup unit (fmu). when a third-party tool runs the fmu, it checks out required licenses and starts a local installation of simulink to start the model. tool-coupling fmus support the fixed-step and variable-step solvers that the fmu encapsulates.
use a project to export an fmu. open the model and select new > project > new project from this model to create a project from a model.
you can export a fmu from a project interactively.
in the project, select share > tool-coupling fmu.
type in the 凯发官网入口首页 copyright, description, and fmu icon fields. click save settings and export as and provide a name.
the generated fmu includes model implementation, as well as the metadata provided during export.
you can also create and export a project to a fmu from the command line as follows:
>> p = slproject.create('vdpproject') >> copyfile(which('vdp'), './vdpslave.slx') >> p.addfile('./vdpslave.slx') >> simulink.fmuexport.exportsimulinkprojecttofmu(p,'vdpslave.slx','-fmuname','vdpfmu')
for more fmu export options from the command line, type:
help simulink.fmuexport.exportsimulinkprojecttofmu
the model must satisfy these conditions for exporting:
model must be in normal or accelerator simulation mode.
root input and output ports must be one of these numerical data types:
double
int32
boolean
simulink bus object, where all elements are
double
,int32
, orboolean
simulink.aliastype
, in which the base type resolves todouble
,int32
orboolean
if the cosimulation component is an fmu exported from simulink. the local sample time for that fmu is the sample time of the original model.
include tunable parameters for tool-coupling fmu
to include tunable parameters:
open the model from the associated simulink project.
from the simulink model, click the modeling tab and start model explorer.
select model workspace and add a matlab® variable or simulink parameter.
for each parameter you add and want tunable, in the data properties or simulink.parameter pane, select the argument check box.
click apply.
reference the tunable parameters in the model.
export the tool-coupling fmu.
use protected model to conceal content
the exported tool-coupling fmu is a zip package and contains the original simulink project and model files in its resources folder. to protect your intellectual property, use protected model workflow. save the model as a protected model and select the simulate check box to conceal the contents. create a new model with model reference block to load the slxp file, and use this model as the main interface model when exporting to tool-coupling fmu. for more information, refer to (embedded coder).
use the exported tool-coupling fmu
the exported fmu requires a local installation of simulink to run. the matlab version used for cosimulation must be the same as the matlab version where the fmu is exported. on windows®, the application that runs the fmu can check out the required licenses automatically. for other operating systems, apply these settings:
on linux®:
setenv ld_library_path ${ld_library_path}:
/bin/glnxa64: /extern/bin/glnxa64 (csh/tcsh) export ld_library_path=${ld_library_path}: /bin/glnxa64: /extern/bin/glnxa64 (bash) on mac os:
setenv dyld_library_path ${dyld_library_path}:
/bin/maci64: /extern/bin/maci64 (csh/tcsh) export dyld_library_path=${dyld_library_path}: /bin/maci64: /extern/bin/maci64 (bash)
for mac os, due to system integrity protection (sip), setenv
command
does not work for applications that starts new processes, such as matlab. follow to set
dyld_library_path
to
.
before you can run the fmu, you must set up a matlab session from your operating system console. after you set up this session, start the third-party application and import the tool-coupling fmu. each fmu instance requires a new matlab session.
start a dedicated session from matlab
if the application that imports the fmu runs a single instance of the fmu, you can use matlab to start a session.
>> sharematlabforfmucosim
dedicates the current matlab session available for requests from the external tool to co-simulate an imported fmu. when an fmu is connected this session, the simulink editor and simulink project are loaded, and cosimulation starts automatically. you can use this session to pause, resume cosimulation, tune parameters, and plot signals from the command window while cosimulation is running. if cosimulation is finished, stopped by you, or interrupted by a runtime error, matlab closes, unloads the simulink editor and simulink project, and discards changes to the model. if an error occurs, it displays in the simulation tool that imports this fmu. each session can connect to one fmu instance at the same time.
start a dedicated session from the operating system
if the application that imports the fmu runs multiple fmu instances, you can use the
operating system console to start dedicated matlab sessions. run matlabroot
in matlab to find out
then, use
on windows:
\toolbox\shared\fmu_share\script\fmu-matlab-setup.cmd [numberofmatlabsessions] on linux and mac os:
/toolbox/shared/fmu_share/script/fmu-matlab-setup [numberofmatlabsessions]
the input argument numberofmatlabsessions
is an integer
representing the number of matlab sessions to be launched when starting this script. if
numberofmatlabsessions
is not present, matlab sessions are not launched. then, the program enters command-line interface
mode and waits for a command.
see available commands by typing
help
:
> help command list: quit - close all shared matlabs and exit. list - list shared matlabs. start number_of_matlabs - start number_of_matlabs more matlabs. stop number_of_matlabs - stop number_of_matlabs matlabs. ignore - stop asking about the hardware core count when launching matlabs. clean matlab_number - clean up the matlab workspace for matlab #matlab_number. use 0 for all matlabs. help - print the command list.
launch one session for each fmu to run concurrently. if there is a single fmu, type:
> start 1
if there are three fmus running concurrently, type:
> start 3
only one matlab management tool should be running on a single machine.