Support : Knowledge base

Knowledge Base

Welcome to OPAL-RT’s Knowledge Base

OPAL-RT offers a repository of support information for optimal use of its technology.

Loading…

Please note that OPAL-RT knowledge base is not fully optimized for mobile platforms.

For optimal experience, use a desktop computer.

Reference Number: AA-01962// Views: AA-01962// Created: 2020-10-28 15:20:09// Last Updated: 2020-10-28 19:03:04
MATLAB/Simulink
Demo: Synchronizing an Offline Simulation Through UDP (Using Step Forward in Simulink and Arduino)

Demo: Synchronizing an Offline Simulation Through UDP (Using Step Forward in Simulink and Arduino)

This example demonstrates shows a proof of concept to synchronize an offline simulation through UDP.

The idea is to use the 'Step Forward' Mode of Simulink to 'wait' until the data is ready from the other simulation before calculating the next step of the ePHASORSIM Model. In this example, Arduino is being used and every time a value is sent, the ePHASORSIM model calculates exactly one time-step.

An Arduino with an ethernet shield is used for this proof-of-concept, but it could be another simulation controlled by an API. The script could then control and transfer the info between the two simulations.

Here is the functional diagram:



Explanation

NOTE: It is mandatory to execute once the following command to compile and start Model 2 before doing the rest.


set_param('phasor01_IEEE39', 'SimulationCommand', 'start', 'SimulationCommand', 'pause'); %Takes the simulation to time t = 0.0 and pauses it


The Arduino is running a simple script that is waiting for a user input in the Serial Monitor:



When a value is entered (the character 'A' in the screenshot above), then, it sends that value through UDP to the Model 1. It is possible to see it via Wireshark:



Of course, more values (and more relevant ones too) can be transferred. In Model 1, which is running continuously, it has a UDP receive block to receive this value:



We receive in the 'UDP Receive' block in Model 1. The first subsystem ('detect_sync_signal') is simply parse the UDP message to trigger a new step in Model 2. The subsystem is to represents that we can set values in Model 2 before executing the step forward. In this example, it is a basic counter.

In the MATLAB function, this is where the other model is being controlled:



The 'coder.extrinsic' lines are to avoid errors. The model will not run in Simulink if those lines are not present. Note that we are setting the parameters in the model before executing the step. In this example, it is setting a constant value based on the input value u2 of the MATLAB function block. In this example, it is simply a counter that increments but it could come from decoding the UDP message. The following command executes the simulation for exactly one time-step.



All the required files (except the license) can be found in attachment.


Pre-requistes & Version Used

RT-LAB Localhost License (for running ePHASORSIM offline)

DSP System Toolbox (For the UDP Receive block)

Arduino Uno + Ethernet Shield

Matlab 2017a

RT-LAB version v2020.2.1.74

Arduino IDE 1.8.12


NOTES: 

Need to change the extension of the Arduino script to be able to use it (i.e. remove the .txt extension).

The Matlab functions are based on : Matworks Step Forward.


Model_2_udp_receive.mdl 48.3 Kb 48.3 Kb
phasor01_IEEE39.mdl 0.1 Mb 0.1 Mb
phasor01_IEEE39.xls 67.5 Kb 67.5 Kb
UDPSend.ino.txt 1.5 Kb 1.5 Kb