Exchanging UDP Data Between Simulink® Model and SimWB Test Session

This example shows how to send data back and forth between a running Simulink model and a SimWB test session running on the real-time host. This can be useful to update variables in Simulink based on the value of variables calculated via the scripts and models running in SimWB and vice versa. For example, you can drive animation in Simulink® based on the state of the system being simulated in the test session running on the real-time host.

Overview

Real-Time Host UDP Communication

Use the NET-IO I/O device in SimWB to send/receive UDP (or TCP) data from the real-time host. Map the relevant RTDB variables to field in Input/Output messages.

Use NET-IO I/O device for UDP communication to/from the SimWB Test Session
Figure 1: I/O Mapping for NET-IO device depicting a message being received from Simulink® into SimWB.

Simulink UDP Communication

Use the From_SimWB_Host and To_SimWB_Host blocks from the simwbUDPBlocklib library to send/receive UDP data from the Simulink model. UDP communication is supported by both fixed-step and variable-step models.

Use the From_SimWB_Host and To_SimWB_Host blocks in the simwbUDPBlocklib library for UDP communication to/from a Simulink model
Figure 2: From_SimWB_Host and To_SimWB_Host in the simwbUDPBlocklib library.

Determinism Considerations

UDP communication can introduce nondeterministic behavior in a real-time test. Therefore, for tests where real-time considerations are important, ideally, UDP communication should be reserved for slow-changing and non-real-time-critical variables. You must analyze the reliability of your UDP channel and determine the merits of the tradeoff and accordingly specify transmission/receive rates.

The following factors contribute to the lack of determinism in UDP communication between the real-time host and a Simulink instance:

Example Setup

This example comprises the ccur_udp Simulink model and the udp_example RTDB and Test. The following diagrams depict the flow of data between the Simulink model and the SimWB test.

Data originating in Simulink travels to SimWB and is routed back to Simulink model
Figure 3: Details of how data is sent from the Simulink model to SimWB and routed back to the Simulink model.

Data originating in SimWB travels to the Simulink model and is routed back to SimWB
Figure 4: Details of how data is sent from SimWB to the Simulink model and routed back to SimWB.

To run this example, perform the following steps on the real-time host machine:

Modify Example to Run Between Two Different Machines

Suppose you want to run the Simulink® model from a different machine. Assume the Simulink model machine IP address is IP_Simulink and the SimWB real-time host machine IP address is IP_SimWB. The port numbers for the four UDP messages are indicated by PORT_message_name.

Change the following values to ensure proper data propagation:

Example Resources

See Also

Simulink®, developed by MathWorks, is a graphical modeling environment.