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.
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.
Configure the DDS subsystem as an aperiodic partition that can be scheduled to respond to events.
To configure the subsystem, right-click the subsystem block, select Block Parameters (Subsystem), and then do the following:
In the dialogue box, select Treat as atomic unit.
From the Schedule as list, select
Aperiodic partition
.Specify the partition name as
A1
.Click OK.
After the subsystem is configured, in the top-level model, a badge appears above the subsystem block indicating that the subsystem is partitioned.
Configure events on the input port.
To configure the input port, right-click the Inport block, select Block Parameters (Inport), and then do the following:
In the dialog box, select the Execution tab.
On the Execution tab, under Events, click the plus sign to add one or more events:
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 bind events configured on input ports to partitions that execute on event occurrence. To configure event binding, do the following:
Click the badge above the subsystem block to open the Schedule Editor. Alternatively, to open the Schedule Editor from the Inport Block, open the Inport Block Parameters dialogue box, and under the Execution tab, in the Events section, click . The Schedule Editor opens.
In the Schedule Editor, click Update Diagram, then expand the Events tab. The input write event for the input port (
In1.InputWrite
) displays.Bind the event to the partition by dragging the
In1.InputWrite
event from the Events panel to theA1
partition shown in the Schedule Editor canvas.Note that this step might not be required because binding might occur automatically if you configured only one event and one partition.
Schedule additional events or behaviors. See Schedule Editor for more information.
Close the Schedule Editor, then press
Ctrl+D
to update the model. The block diagram updates to reflect the binding of theIn1.InputWrite
event to theA1
aperiodic partition scheduled as subsystem On Data Available Handler.
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