Documentation Home Page RT-LAB Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

Embedded Targets and Snapshots

Installing Embedded Targets

Previous versions of RT-LAB (8.4.x and lower), require the installation of a special archive file, named rt-lab_e.tgz, on the target to support embedded simulations. This step is now automatically performed during the general target installation of RT-LAB, so no extra step is required. The embedded mode is available for OPAL-RTLinux (x86-based) platforms.

Known Limitations

Embedded simulation has the following limitations:

  • Only one model per project can be embedded on a target.
  • Only one model per target can run in embedded mode.
  • Embedded simulation is limited to models that have only one real-time subsystem (SM Master). This means that models that contain multiple subsystems could not be embedded on a target.
  • Users that did not start an embedded simulation need to share (or have a copy of) the original project to connect to the embedded simulation.
  • Embedded mode is not supported on RT-LAB 10.0 and 10.1.

Taking a Snapshot

The Snapshot feature has two main uses:

  • to restore a set of values in your simulation
  • to generate a report on the state of the simulation at a given time.

A Snapshot contains the values of all the model’s parameters, signals, and states at a given time of the real-time simulation. It also contains information about the solvers and data required by s-functions. Users can take a snapshot of a model while the real-time simulation is running, and then restore it later if desired. For example, if a simulation must run for two days to achieve a given state, a snapshot of the model can be taken after it has run for two days. When the simulation is run again, the snapshot’s values can be restored, saving two days of simulation. Also note that to restore a snapshot the real-time simulation must be paused.

To take or restore a snapshot; use the corresponding item in the Simulation menu or Main Toolbar.

A Snapshot block may also be placed in the model, helping the user to automatically take snapshots based on the behavior of the model. See the Snapshot block in the Block Library Reference Guide for more help.

Registering a User S-Function for Snapshot

Note: The following paragraphs are designed for advanced users developing S-Functions with Simulink. If you are not familiar with S-Function, skip this section.

To save data contained in an S-Function when a snapshot is taken, you must register your S-Function in RT-LAB. To do this, use the OpalSnapshotRegister function in your s-function. This function enables you to register data so it can be saved when a snapshot is taken and reloaded when the snapshot is restored.

Follow these steps to register your s-function

  • Include the model_main.h header file in your s-function source code:
    #include model_main.h

This file is located in the <RT-LAB directory>\common\include_target directory on a
WINDOWS OS environment, or in /usr/opalrt/common/include directory on a OPAL-RTLinux (x86-based) environment.

  • Define a structure to be copied with the snapshot. For example:

def struct
{
real_T value;
unsigned int count;
char string[50];
}LocalData;


Once your S-Function is registered, every snapshot taken will contain a raw copy (memcpy is used) of your data.

Note: the structure definition must not contain pointers since snapshot will not copy the area referred by your data pointer. In this case, when a snapshot is restored the pointers will be reset to their previous value and you will get an invalid pointer that may corrupt your sfunction and the real-time simulation. This problem is caused by the fact that the memory allocation that was performed for the current simulation may be different from the memory allocation performed when the snapshot was taken.


  • Initialize and register your structure in the mdlInitializeCondition function :


// Initialize your data
LocalData *data;
Data = (LocalData *) malloc(sizeof(LocalData));
// Register your data pointer to RT-LAB
OpalSnapshotRegister((void *)data, sizeof(LocalData), ssGetPath(S));

  • First argument: void pointer to the memory block to copy.
  • Second argument: size (in bytes) of the memory block to copy.
  • Third argument: path of the S-function (available from the ssGetPath macro).


Free your data structure in mdlTerminate function:

if (data != NULL) {
free(data);
}


Before compiling your s-function as a shared library (.mexw32 file), add the model_main.h include path to your compilation command. Example:

cc [...] -I<RT-LAB directory>\common\include_target [...]

OPAL-RT TECHNOLOGIES, Inc. | 1751, rue Richardson, bureau 1060 | Montréal, Québec Canada H3K 1G6 | opal-rt.com | +1 514-935-2323