Model DDS Input Events
DDS Blockset supports event-driven communication where a subscriber application thread waits for an event trigger before executing condition-based algorithms.
In Simulink, you configure DDS events at the input ports of your model and bind the event to a model partition that contains the response algorithm. You can trigger one or more events based on the flow of data into a root-level input port of a model subsystem. Using the Schedule Editor, you can specify a partition to execute in response to each event.
DDS Blockset supports input events for applications using RTI Connext®. In the generated
code, the input event is implemented by using WaitSets and Conditions. The WaitSet
wait()
operation blocks execution of the application thread until an
input event (or timeout) causes the user-defined condition to be true. For more information
about WaitSets and Conditions, see RTI Connext documentation.
This table lists supported event types and maps DDS callback method names to the corresponding Simulink event name.
Event Type | DDS Method Name | Simulink Event Trigger Name | Description |
---|---|---|---|
onDataAvailable | on_data_available | Input write | Value for input port updates. |
onSampleLost | on_sample_lost | Input write lost | Input port value update overwrites unprocessed data. |
onDataDeadlineMissed | on_requested_deadline_missed | Input write timeout | Input port value does not update within a specified amount of time. |
Model DDS Input Event
This section provides an example of configuring an existing DDS model as the response algorithm for a data available event.
Create or open a model configured for DDS. The model should contain Take DDS Sample blocks, application logic, and Inport blocks configured as DDS data types. For more information, see Model DDS Applications.
Enclose the model in a subsystem.
To enclose the model in a subsystem, select all blocks in the DDS model, right-click one of the highlighted elements, and select Create Subsystem from Selection. The DDS model is enclosed in a subsystem, and corresponding inport and outport blocks are added at the top level.
For this example, name the subsystem
On Data Available Handler
.Configure the model to run tasks concurrently.
On the Modeling tab, click Model Settings to open the configuration parameters:
In the Configuration Parameters dialog box, on the Solver pane, click the arrow next to Solver details.
Under Tasking and sample time options, select Allow tasks to execute concurrently on target.
Click OK.
Double-click the Inport block to open the Block Parameters dialog box and configure events.
In the Block Parameters dialog box:
Select the Execution tab.
On the Execution tab, under Events, click the plus sign and select one of the event types:
Input Write
(DDS on_data_available) — Seesimulink.event.InputWrite
for more information.Input Write Lost
(DDS on_sample_lost) — Seesimulink.event.InputWriteLost
for more information.Input Write Timeout
(DDS on_requested_deadline_missed) — Seesimulink.event.InputWriteTimeout
for more information.
For this example, select
Input Write
.Under Events, the Events spreadsheet contains event settings for that input port and lists the added events. You can add up to one of each event type. For an
Input Write Timeout
event, you enter the timeout duration in the Timeout column. The timeout duration is entered in seconds.Click OK. After adding the event, an event badge appears above the inport block.
Use the Schedule Editor to configure the DDS subsystem as an aperiodic partition and then bind the event configured on the input port to the partition that executes on event occurrence.
To configure the DDS subsystem:
Open the Schedule Editor and click Manage Partitions to open the Manage Partitions pane.
In the Manage Partitions pane, under Block Name, select On Data Available Handler, and then click the Schedule as aperiodic partition button.
Click Update Diagram. The
On_Data_Available_Handler
partition displays in the Schedule Editor canvas.At this step, if you configured only one event and one partition, you see the
Inport.InputWrite
event bound toOn_Data_Available_Handler
. If the binding does not occur automatically in your model, continue with the next steps.Expand the Events tab. The input write event for the input port (
Inport.InputWrite
) is listed under Name.Manually bind the event to the partition by dragging the
Inport.InputWrite
event from the Events tab to theOn_Data_Available_Handler
partition shown in the Schedule Editor canvas.Schedule additional events or behaviors as needed. See Schedule Editor for more information.
Close the Schedule Editor and press Ctrl+D to update the model.
The block diagram updates to reflect the binding of the
Inport.InputWrite
event to the aperiodic partition scheduled as atomic subsystemOn Data Available Handler
.
For more information about creating and configuring partitions, see Create Partitions.
Modeling Pattern Considerations and Limitations
Modeling – Modeling DDS input events is only supported for DDS Blockset models using RTI Connext 6.0.1+.
Port Configuration – DDS Blockset requires that all ports must map to DDS and all input ports in models that configure input events must use Inport blocks.
See Also
Inport | simulink.event.InputWriteTimeout
| simulink.event.InputWriteLost
| simulink.event.InputWrite
| Schedule Editor