48. FMI Export

AGX Dynamics supports FMI export for co-simulation using the FMI-standard (see http://fmi-standard.org/). The standard (and its interface) is called Functional Mockup Interface (FMI), and one unit created or connected via this standard is called a Functional Mockup Unit (FMU).

The following tutorial demonstrates how to build an AGX Dynamics FMI module compatible with the FMI 2.0 standard. The resulting FMI module can, according to the FMI standard, also be referred to as an FMU (see above).

The FMI export interface is exposed in AGX using the agxFMI2::Export namespace. The interface bindings are defined using Python. AGX Dynamics only supports creating FMUs using the FMI 2.0 standard.

The following diagram displays the structure of an AGX FMI module:

../_images/fmi_export_1.png

Building an AGX FMU consists of

  1. Setting up a directory structure matching the structure described in the FMI standard. The FMI module structure is described in section 2.3 (FMU Distribution) in the FMI2 specification.

  2. Implementing the Python script, which is responsible for

  1. Defining the AGX scene to be simulated

  2. Registering the FMI variables to be exported

  1. Running the AGX FmiExporter tool which will

  1. Automatically generate the FMI XML interface definition (modelDescription.xml)

  2. Package the FMU as a zip file according to the standard

The FMU root directory, from here on referred to as $FMU_ROOT, must contain a Python file named main.agxPy. This is the main entry point for building the scene and setting up the module parameters.

The main.agxPy file must contain a function called fmiInit, which takes no arguments. The module of type agxFMI2::Export::Module* can be accessed through the global agxPython context:

def fmiInit():
    context = agxPython.getContext()
    export_module = context.environment.getFMI2Module()

This module contains a simulation instance, to which the simulated scene is added, an OSG render node for debug rendering, and methods for registering FMI parameters.

You can find an FMU example in the data/FmiModules/Tutorial/Python/SpinningBox directory.

The AGX-FMUs are exported using the FmiExporter tool, which has the following syntax

FmiExporter --name <FMU module name> --output <FMU output path> <FMU data root>

Name and output have implicit values so you can simply run

FmiExporter myFmu

where myFmu is the directory containing the main.agxPy file. In this case the module name will be myFmu and output path will be myFmu.fmu.

The FmiExporter will automatically generate a FMI modelDescription.xml and package the FMU zip file.

In order to run the FMU, AGX has to be installed on the computer with a valid license and valid environment variables.