LabVIEW Control Design and Simulation Module

Using the External Model Interface (Control Design and Simulation Module)

  • Updated2023-03-14
  • 4 minute(s) read

Third parties can use the External Model Interface (EMI) to create an external, or third-party, model in C/C++. LabVIEW users can use EMI to simulate the external model in the LabVIEW Control Design and Simulation Module.

The following illustration shows the relationship between the components of the EMI.

Creating an External Model

First create a C/C++ project that uses the External Model Interface functions to define the dynamic equations for the model. Refer to the Example 1: Creating an External Model topic for an example of a C/C++ project that defines an external model.

Note  In many cases, LabVIEW users do not need to create external models. Instead, use the External Model function in LabVIEW to simulate models you receive from a third party.

Before defining the dynamic equations for the external model, you must include the SIM_EMI_API.h header file, located in the labview\CCodeGen\Simulation directory. This header file includes definitions and declarations for all functions and data types that the EMI supports.

After you enter the include line for the header file, use the External Model Interface functions to define the following dynamic equations for the external model:

Model Part Equation
Indirect Outputs yindirect = f1(t, p, xc, xd)
Direct Outputs ydirect = f2(t, p, xc, xd, u)
Derivatives of Continuous States xc' = f3(t, p, xc, xd, u)
Discrete States xd, next = f4(t, p, xc, xd, u)
where y is the outputs of the model
t is the time
p is the parameters of the model
xc is the continuous states
xd is the discrete states
u is the inputs to the model
xc' is the derivatives of xc
Note  The total number of inputs (u), outputs (y), and parameters (p) of the model cannot exceed 25.

You also can define equations for calculating the zero crossings or reset states of the external model.

You must export the EMI_CB_ModelInterface function for each model you create. You also must export Callbacks functions as appropriate for the structure of the model. For example, if the model contains indirect outputs, you must export the EMI_CB_CalculateIndirectOutputs function to calculate the indirect outputs. If you do not export the appropriate Callbacks functions, LabVIEW returns an error when you attempt to simulate the model.

Build the C/C++ project into a (Windows) .dll, (macOS) .framework or .dylib, or (Linux) .so shared library file and distribute the shared library to end users.

Simulating an External Model

Use the External Model function to represent an external model that you want to simulate, such as a model you receive from a third party. Refer to the Example 2: Simulating an External Model topic for an example of simulating an external model.

When you add an External Model function to a simulation diagram, the Select an External Model Library dialog box appears. In this dialog box, specify the shared library you want to reference from the External Model function. The External Model function updates to reflect the structure of the model corresponding to the shared library. For example, if the model has one input, two parameters, and one output, the External Model function has one block diagram input, two parameters in the configuration dialog box, and one block diagram output.

When you run the simulation, the Control Design and Simulation Module uses an ordinary differential equation (ODE) solver to compute the behavior of the dynamic system model that the External Model function represents. The Control Design and Simulation Module calls the External Model Interface functions that the corresponding shared library exports.

Note  The Control Design and Simulation Module executes the Callbacks functions in a specific order.

If the shared library you reference from an External Model function changes, right-click the External Model function and select Relink to External Model Library from the shortcut menu to reference the modified shared library. If you want to reference a different shared library from the External Model function, right-click the External Model function and select Select External Model Library from the shortcut menu to display the Select an External Model Library dialog box. Then select the new shared library you want to reference.

You can configure the External Model function as you do other Simulation functions.

Log in to get a better experience