Frequently Asked Question
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:
- FMI Kit
- MATLAB Support for MinGW
- CMake (there is a script in FMI Kit tool that does this automatically which will be explained later)
Installing all the necessary tools
- Add MATLAB Support for MinGW:
- Download MATLAB Support for MinGW from the link above. The downloaded file has the extension .mlpkginstall. This file can be installed directly through MATLAB.
- Open MATLAB, navigate to the downloaded file inside the MATLAB file explorer and install it
- After the installation is finished, add the path to the compiler to the System variables:
- 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
- Copy the compiler path
- Open Environment Variables window
- 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
- Confirm all the changes
- Download MATLAB Support for MinGW from the link above. The downloaded file has the extension .mlpkginstall. This file can be installed directly through MATLAB.
- Download FMI Kit tool
- Download FMI Kit tool from the link above
- Extract the archive on the desired location (ex. C:\FMI Kit\)
- Install CMake
- 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)
- Open this script in MATLAB and run it
- After the script finishes, CMake will be present in the root directory
Using FMI Kit
- Initialize FMI Kit:
- Open MATLAB
- Add the FMI Kit to path by executing the command: addpath('C:\FMI Kit\')
- Initialize FMI Kit library by typing the command: FMIKit.initialize()
- Exporting the FMI Simulink model
- Open the model in Simulink and change the Model Configuration Parameters
- Change the Solver to Fixed-step and define the Fixed-step size
- 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
- 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.
- 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)
- Press OK
- Build the model using the Ctrl+B command
- If the build is successful, the .fmu file should be generated in the current folder. Import this file in Typhoon HIL FMI Import component.
- Open the model in Simulink and change the Model Configuration Parameters
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:
- In the Model Configuration Parameters window, search for Code Generation | Custom Code
- 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.