该内容不适用于您选择的语言

该内容将以另一种语言显示出来。 您可使用浏览器的翻译功能查看内容。

Generating FMI Models from The MathWorks®, Inc. Simulink® for NI VeriStand

Updated Dec 22, 2023

Environment

Software

  • VeriStand
  • MATLAB
  • Simulink

Operating System

  • LabVIEW Real-Time (NI Linux Real-Time)
  • Windows

Other

<FLAG was there about it being unclear - review and check solution>

This article will explain and walk through how to generate FMI models from the MathWorks®, Inc. Simulink® for NI VeriStand.

The Functional Mockup Interface (FMI) is an API standardization for exchanging dynamic system models. NI VeriStand 2019 and higher versions enable configuration and execution of FMI 2.0 Co-Simulation models on Windows and NI PXI Linux Real-Time systems. This support requires FMI models to have the proper executable binaries available. For Windows targets, win32 binaries are required. For NI PXI Linux Real-Time targets, linux64 binaries are required.

MATLAB R2020a and higher versions enable generating standalone FMI models with Simulink® Compiler™. This article also introduces an open-source 3rd-party toolkit, FMIKit-Simulink from Dassault Systèmes®, for working with lower versions of MATLAB. The following table gives a summary of toolkits' capability to generate models for NI VeriStand model deployment.
 
Table 1. Toolkits' Capability to Generate Models for NI VeriStand Model Deployment
Toolkit for Simulink®Generated Model FormatDeploy to
Windows
Deploy to
Phar Lap
Deploy to
NI PXI Linux RT
MATLAB Compatibility
VeriStand Model Framework*.dll/*.soüüüVeriStand Modeling Version Compatibility
Simulink® Compiler™*.fmuüNot supportedüFor Windows targets: R2020b - latest
For NI PXI Linux RT targets: R2020a - latest
FMIKit-Simulink*.fmuüNot supportedüR2012b - latest

Setting up the Software Environment

  1. Install MATLAB®

    • Refer to Table 1 to check MATLAB compatibility before installing.
    • For generating Windows targets models, install MATLAB in a Windows system.
    • For generating NI PXI Linux Real-Time targets models, install MATLAB in a compatible Linux system.
  2. Install Compiler
 

Simulink® Compiler™

  1. Ensure you have installed Simulink® Compiler™ on your computer.
  2. Open the Simulink model.
  3. Open the Configuration Parameters window. 
  4. Configure Solver. Navigate to the Solver tab. Configure Solver selection > Type as Fixed-step, and specify a proper Fixed-step size

     
  5. Save and close the Configuration Parameters window.
  6. Generate the model.
    • For Windows system: Execute the following code in the Command Window.

      % generate win32 FMU, replace the first argument 'mdl' as your own model name
      exportToFMU2CS('mdl', 'Generate32BitDLL', 'on')
       
    • For Linux system: Navigate to Simulation > Save > Standalone FMU.... Click Create in the FMU Export dialog.
       

 

FMIKit-Simulink

  1. Download FMI Kit for Simulink and decompress the zip file, refer to External Link: The Latest Release of FMIKit-Simulink - GitHub
  2. Initialize FMI Kit for Simulink. Open MATLAB and execute the following code in the Command Window

    % add the FMIKit-Simulink folder to the MATLAB path, replace the path as your own
    addpath(‘C:\Users\xxx\Desktop\FMIKit-Simulink-2.8’)
    % initialize FMIKit
    FMIKit.initialize
     
  3. Open the Simulink model.
  4. Open the Configuration Parameters window. 
  5. Configure Solver. Navigate to Solver tab. Configure Solver selection > Type as Fixed-step, and specify a proper Fixed-step size.  
  6. Configure Code Generation. Navigate to Code Generation > Target selection > System target file. Browse to choose grtfmi.tlc (based on the Generic Real-Time target). 
     
  7. Configure the compiler. 
    • For Windows systems: Navigate to CMake CMake generator. Choose one of the win32 compilers shown in the following figure.  
    • For Linux systems: Use the default configuration.

       
  8. Save and close the Configuration Parameters window.
  9. Build the model. The Simulink menu differs in different MATLAB versions. The following figure shows the condition in MATLAB R2020a.
     
     
  10. It will report an error that CMake is not installed when compiling for the first time. You can click grtfmi_install_cmake in the Diagnostic Viewer window to download and install CMake. Then build the model again.

Next Steps

Import the FMI models into NI VeriStand, refer to Adding and Configuring a Model - NI VeriStand Manual.