> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/rt-lab/simulation-control-monitoring-and-logging/interact-using-simulink.md).

# Interact using Simulink

RT-LAB enables users to interact with a simulation in real-time directly from Simulink. This requires adapting the model appropriately before compilation.

## **Simulink model modification steps**

{% stepper %}
{% step %}

### Create subsystems

Create subsystems respecting **RT-LAB naming conventions:**

* **sc\_\<descriptive\_name>:** Place all monitoring and control blocks you want to access during real-time simulation here (e.g., **Display**, **Scope**, **Constant**). **Do not include any computation or time-dependent blocks** such as Sine Wave or integrators. Only one sc\_ subsystem is allowed per model.
* **sm\_\<descriptive\_name>:** Group all remaining computation blocks into one sm\_ subsystem. If additional computation subsystems are needed, see the [**Single-Core & Multi-Core Simulation**](https://www.opal-rt.com/docs/rt-lab/model-and-simulation/single-core-and-multi-core-simulation.md) section.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-89bb5c6f2029c713bdd9d725cbb286710e009502%2Fsc-subsystem.png?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Insert OpComm blocks (required)

All inputs to top-level subsystems must first go through an **OpComm** block. OpComm blocks communicate signal type and size to RT-LAB and emulate real-time behavior within Simulink.

To insert an OpComm block:

1. Open the **Simulink Library Browser**.
2. Navigate to **RT-LAB**.
3. Drag an **OpComm** block and place it immediately after the subsystem inputs.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-2db6f4cce33e5ef544afb0fefa2f790961f8a8cc%2Fopcomm.png?alt=media" alt="" width="354"><figcaption></figcaption></figure>

{% hint style="info" %}
You may use multiple OpComm blocks in the sc\_ subsystem (up to 25). Each OpComm creates a separate acquisition group, allowing you to group signals independently and tune each group’s acquisition parameters individually.
{% endhint %}
{% endstep %}

{% step %}

### Build, load and execute the model

Save and execute the model in Simulink to confirm it runs correctly. Then, build, load, and execute the model in RT-LAB.

* During the load stage, RT-LAB automatically opens the sc\_ subsystem in Simulink for real-time interaction.
* If it does not open, go to RT-LAB **Project Explorer**, expand the model to show its subsystems, and double-click the sc\_ subsystem to open it in Simulink.
* To automate this before loading, open the model editor, go to the **Simulation Tools** tab, and check **Handle console automatically**.
  {% endstep %}
  {% endstepper %}

## Improve interactions during real-time execution

The sc\_ subsystem runs on the workstation and operates **asynchronously** from the simulation executing on the simulator. As a result, the console is **not synchronized** with the model and can be **stopped or restarted without resetting the simulation**.

RT-LAB uses a **double-buffered acquisition system** for each acquisition group:

* **Buffer 1** collects data on the simulator and transmits it to the console once full.
* **Buffer 2** collects new data while Buffer 1 is being transmitted.
* The buffers alternate continuously to ensure efficient, lossless data transfer.

Acquisition groups and their sampling behavior can be configured through the RT-LAB **Probe Control**.

{% stepper %}
{% step %}

### Access the Probe Control

In RT-LAB **Project Explorer**, first select the model. Then, in RT-LAB top toolbar, click the **Probe Control** icon.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-afef3b5ced1e7e260c2e29960f8934e616354dc7%2Fprobe-control.png?alt=media" alt="" width="475"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Change the Probe Control parameters

In some cases, users may observe **distortion or data loss** during signal transfer between the simulator and the workstation. A common scenario occurs when **Buffer 1 is still transmitting while Buffer 2 becomes full**. In this case, Buffer 2 may overwrite its oldest samples while waiting for transmission, leading to visible gaps or steps in the console display.

To mitigate this, ensure the **Number of Samples per Signal** (total points stored in the buffer) is sufficiently high, typically **2000–2500**. The main trade-off is that larger buffers may produce slightly less smooth bursts of data when displayed.

Adjusting the **Decimation Factor** can further improve signal visualization, since collecting every data point is usually unnecessary. For example, a decimation factor of **1** collects all data points, while a factor of **2** collects every other point. Increasing the decimation reduces the number of points transmitted, helping maintain smooth and efficient data display while preventing buffer overflow.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-932252905bc0272523138b8cd63ba8581a9a3789%2Fprobe-control-settings.png?alt=media" alt="" width="413"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

{% hint style="info" %}
Decimation factor, number of samples, and duration can be adjusted **while the model is running**.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/rt-lab/simulation-control-monitoring-and-logging/interact-using-simulink.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
