Frequently Asked Question

How to export FMU file from Simulink model and import it in Typhoon HIL toolchain (for MATLAB release 2021a)?
Last Updated 7 months ago

From the 2021a version, Matlab enables its users to export a Simulink model to FMU along with C source code. Although FMU could be exported in previous versions as well, those versions didn't support exporting C source code along with FMU. 

Having C source code included in FMU is crucial for running real-time simulations in the Typhoon HIL toolchain. 

Exporting FMU from Simulink

1. Open your model in Simulink. It is recommended that the path to your model does not contain empty spaces, so we recommend that you place _ instead of empty space.

2. Comment out parts of the model you don't want to export. Place Inport components to the places inputs to the system and Outport components to the places where are outputs of the system.

image

3. Go to Model settings (Modeling tab). In the Solver tab, there are two parameters that should be set:

  • Type of Solver (Model Settings->Solver->Solver Selection->Type), should be set to Fixed-step
  • Fixed step size (Model Settings->Solver->Solver details->Fixed step size), should be defined. (This value is important for parametrization of the FMU unit when it is imported in Typhoon HIL tool-chain)
image
4. In the Code Generation tab, the System target file must be defined as realtime.tlc.
image

5. In the Hardware Implementation tab, the Device vendor and Device type should be specified as ARM Compatible and ARM Cortex-A, respectively.

image

6. Next step is to export FMU. This can be done in Save drop-down menu in the section Export Model To. Pressing Standalone FMU... will open FMU Export window.

image

7. In the FMU export model you have to select Save source code to FMU, while other parameters can be selected as you want. When everything is selected, press Create and FMU will be generated in the folder you set.

image


Import FMU in Typhoon HIL tool-chain

Before you can import created FMU file, a small adjustment to the FMU file must be done.

1. Open FMU file as archive

image


2. Edit "modelDescription.xml" file

image


3. Delete the line which includes lccstub.c.(This library is not supported by the HIL device, so without removing it, the model will not be able to compile successfully.)

image


4. Save the modified file.

5. Import it in Typhoon HIL by dragging FMU import from the core library (core/Signal Processing/Extras/FMU Import)

6. In the properties of FMU Import, choose the FMU file you exported and modified.

image

7. You should choose the Execution rate to be the same or larger than the one you selected the value of Fixed step size in Simulink. If the execution rate is smaller than the one you set in Simulink, FMU behavior will not be correct.

This concludes the steps needed for the proper setup of the Functional Mock-up Unit. You can now start the simulation.

Please Wait!

Please wait... it will take a second!