Frequently Asked Question

How to export FMU file from Simulink model and import it in Typhoon HIL toolchain (for MATLAB release 2020b and previous releases)?
Last Updated 2 years ago

If you are using MATLAB versions released before 2021a, you must install additional tools to enable FMI export. We recommend using the FMI Kit tool to add this support.

In order to use the FMI Kit tool to export FMI Simulink models, some additional tools must be also installed. These tools are MATLAB Support for MinGW and CMake. All the necessary files can be downloaded following these links:

Installing all the necessary tools

  1. Add MATLAB Support for MinGW:

    1. Download MATLAB Support for MinGW from the link above. The downloaded file has the extension .mlpkginstall. This file can be installed directly through MATLAB.

    2. Open MATLAB, navigate to the downloaded file inside the MATLAB file explorer and install it
    3. After the installation is finished, add the path to the compiler to the System variables:
      1. Navigate to the installed compiler. It should be in C:\ProgramData\MATLAB\SupportPackages\R2017b\3P.instrset\mingw_w64.instrset\bin (the path may vary depending on the MATLAB version
      2. Copy the compiler path
      3. Open Environment Variables window

      4. Edit Path variable in System variables. Double click the field and paste the compiler path at the end. Make sure that you put ‘;’ before you add the compiler path
      5. Confirm all the changes
  2. Download FMI Kit tool
    1. Download FMI Kit tool from the link above
    2. Extract the archive on the desired location (ex. C:\FMI Kit\)
  3. Install CMake
    1. Inside the FMI Kit folder, there is a script that automatically downloads CMake. The is called grtfmi_install_cmake.m and it is located in grtfmi folder (ex. C:\FMI Kit\grtfmi\ grtfmi_install_cmake.m)
    2. Open this script in MATLAB and run it
    3. After the script finishes, CMake will be present in the root directory

Using FMI Kit

  1. Initialize FMI Kit:
    1. Open MATLAB
    2. Add the FMI Kit to path by executing the command: addpath('C:\FMI Kit\')
    3. Initialize FMI Kit library by typing the command: FMIKit.initialize()
  2. Exporting the FMI Simulink model
    1. Open the model in Simulink and change the Model Configuration Parameters
    2. Change the Solver to Fixed-step and define the Fixed-step size

    3. In Code Generation, change the System target file to gtrfmi.tlc using the Browse button. At the bottom, specify the Select objective to be either Debugging or Execution efficiency
    4. Under FMI options, make sure to check Include sources in FMU. Without the source files, the model cannot be compiled to work on HIL device.
    5. Under CMake options, select MinGW Makefiles for CMake generator, and for CMake command put the path to cmake executable (ex. C:\FMI Kit\cmake…\bin\cmake.exe)
    6. Press OK
    7. Build the model using the Ctrl+B command
    8. If the build is successful, the .fmu file should be generated in the current folder. Import this file in Typhoon HIL FMI Import component.

Including files to the build process

It may be that the Simulink model you want to export uses C files that are not included by default when exporting the FMU. This is likely the case when the FMU build process fails with an undefined reference error. To include extra files:

  1. In the Model Configuration Parameters window, search for Code Generation | Custom Code
  2. In Additional build information paste the paths to all relevant files and folders.

For example, Simscape Electrical control models that use PLL blocks need the rt_matrx.c file, which is located in%MATLABROOT%/rtw/c/src/.


Known limitations

  • FMU Import is tested with files exported using FMI Kit 2.7 from MATLAB 2017b
  • Although using multiple FMU Import components is supported, exported FMU files using FMI Kit 2.7 are not adequate for this use. Files exported with this FMI Kit version do not use unique functions and redefinition breaks the model compilation. The FMU files can be manually changed to patch this.
  • Although Co-simulation for tool coupling is permitted for Virtual HIL, this option is not tested since FMI Kit 2.7 does not support this.

Please Wait!

Please wait... it will take a second!