> 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/example-models/ephasorsim-example-models/interface-with-simulink-based-controllers.md).

# Interface with Simulink Based Controllers

## Description

The **Interface with Simulink Based Controllers** example can be created by starting a new RT‑LAB project. From the menu bar, select **File > New > RT‑LAB Project**. Enter a name and location for your project, then click **Next**. From the available templates list, navigate to **ePHASORsim** and select **phasor23\_SimulinkController**, then click **Finish**.

This example shows how to use ePHASORSIM for Model-In-the-Loop (MIL) applications. IEEE 39-bus power system is modified to have two switched shunt devices at buses 12 and 28.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-8367c60ac39d58b2b203842ff8b6478935caab97%2Fphasor23_ieee39.jpg?alt=media" alt=""><figcaption><p>Modified IEEE 39-bus power system with CSSCST type switch-shunts</p></figcaption></figure>

The controller of these devices are similar to CSSCST model in PSS/e and it is developed using Simulink's library. The input of the controller is the voltage magnitude of the bus (in pu) and the output is the set-point for required Q (in MVAr). This set-point is passed to switched shunt device through an incoming pin. This controller resides in RT-LAB/Phasor path.

### Input file data preparation

In this demo the input data format is PSS/e RAW and DYR files. Since switched shunt controllers are external to the solver two items should be noted here:

* The dynamic data for the controller must be entered manually in the mask of controller and it must not exist in the DYR file used by ePHASORSIM (phasor23\_SimulinkController.dyr). The controllers' parameters are defined in the param\_set.m file; however, for the reference of the user, the DYR file that includes CSSCST parameters is located in the demo folder (phasor23\_SimulinkController.dyr).
* Since the power-flow calculation in ePHASORSIM considers that all switch shunts are locked (no adjustment), to have a steady state simulation for this demo the power-flow has run in PSS/e with enabled adjustments for switched shunts, and then the result is saved in the RAW file to be used by solver. Therefore, solver does not require to do power-flow and the execution mode will be "Dynamic simulation only". The initial reactive power injection value for the switch shunt devices are defined in param\_set.m file and they are equal to the same values in the RAW file.

## Requirements

* MATLAB R2019b and later

## Simulation and results

To show the impact of CSSCST controllers, a load disturbance scenario is considered. At t=3sec, the active and reactive power values of loads at buses 12, 26 and 27 (shown in red in schem) are augmented twice.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-571394072707cc3b7417e6ba3c07f40f7da19956%2Fphasor23_results.png?alt=media" alt=""><figcaption><p>Simulation results for load disturbance scenario.</p></figcaption></figure>

Comparison of the results with "No Control" case shows that the CSSCST controllers can successfully adjust the voltage deviation within 1% margin in a few milliseconds by injecting reactive power to the bus.

The in-port and out-port configurations are given in **phasor23\_SimulinkController.xlsx** file.

{% file src="/files/zt5KmNRR5vu3E0ng1DCK" %}

In "Pins" sheet of this Excel file the following outgoing and incoming pins are assigned:

<details>

<summary>Outgoing pins (measurements)</summary>

* Vmag\_bus12: Voltage magnitude at bus 12, input to CSSCST of bus 12 (p.u.)
* Vmag\_bus28: Voltage magnitude at bus 28, input to CSSCST of bus 28 (p.u.)

</details>

<details>

<summary>Incoming pin (control command)</summary>

* Disturbed\_load: Active and reactive power of loads at buses 12, 26 and 27
* Q\_swSH\_12: Reactive power of switched shunt at bus 12
* Q\_swSH\_28: Reactive power of switched shunt at bus 28

</details>


---

# 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/example-models/ephasorsim-example-models/interface-with-simulink-based-controllers.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.
