12. Tutorial

To demonstrate the capabilities of the DDS Simulink Integration, this tutorial will create two Simulink models. One model will write DDS samples, and the second model will read the DDS samples.

Both models will be run simultaneously, and use a DDS system for communication.

A Simulink bus named ShapeType is created as part of this tutorial. The bus can be created by either using the Simulink bus editor, or by generation from an IDL file. Both options are covered in this tutorial.

12.2. Create ShapeType Using IDL

The public Vortex.idlImportSl function can be called to generate Simulink bus definitions from an IDL file. The generated bus definitions are inserted into the ‘Design Data’ section of a data dictionary.

From the Simulink documentation -

“A data dictionary is a persistent repository of data that are relevant to your model. You can also use the base workspace to store design data that are used by your model during simulation.”

The data dictionary can then be referenced from your models.

12.2.1. Create IDL File

Create an IDL file to define your ShapeType topic structure. For this tutorial we will name the file ShapeType.idl.

 struct ShapeType {
   string color; //@Key
   long x;
   long y;
   long shapesize;
 };
#pragma keylist ShapeType color

IMPORTANT NOTE: The IDL file has to have a blank line after the pragma keylist declaration. (known bug)

12.2.3. Model Explorer

To make use of the bus definitions generated into the data dictionary, Simulink models can specify design data using the Model Explorer.

Model Explorer Design Data

12.3. Shapes Write Model

This section outlines how to create a new DDS Simulink model that will write sample data for the topic type ShapeType.

Although not necessary, this model will use the optional Domain and Publisher blocks.

12.4. Shapes Read Model

12.4.1. Create a new Simulink model

This section outlines how to create a new DDS Simulink model that will read and display sample data for the topic type ShapeType.

In this model example, we will be making use of many of the defaults, so the optional blocks will not be included in this model.

12.4.1.1. Start Simulink

Start Simulink

12.4.1.2. Add a new blank model

Start Add new blank model

12.4.1.3. Save As…

  • Save the model as “shapes_read_model.slx”.

12.4.1.4. Model Settings

  • Open Model Configuration Parameters dialog, by selecting menu Simulation / Model Configuration Parameters.

  • Set the simulation stop time to inf. (Note: “Specify inf to run a simulation or generated program until you explicitly pause or stop it.” Simulink Help documentation)

  • Set the Solver Type to Fixed-step.

Setup Read Model

12.4.2. Add Simulink DDS Blocks

12.4.2.1. Open the Simulink Library Browser

Vortex DDS Library

12.4.2.2. Add all required blocks (Topic and Reader)

Using the Simulink Library Browser drag the following block types onto your diagram:
  • 1 Topic

  • 1 Reader

Note: For this example model, we will be using the block defaults for the Domain and Subscriber, therefore they will not be included on the model.

To set a block’s parameters, double click on the block to bring up the Block Parameters dialog.

Add Blocks

12.4.2.3. Toggle off optional ports

  • Double click on the Topic to bring up the Block Parameters dialog.

  • In the Topic Ports tab deselect the Participant port.

  • Double click on the Reader to bring up the Block Parameters dialog.

  • In the Reader Ports tab deselect the Subscriber, Reader, Status, Info and Samples Read ports.

12.4.2.4. Set Topic Block Parameters

  • Double click on the Topic to bring up the Block Parameters dialog, select Topic tab.

  • Set the Bus Type: ShapeType bus

    Note: If the ShapeType bus is not displayed, select Refresh data types from dropdown list.

  • Set the Topic Name to: Circle.

Topic Block Parameters
  • Select the QoS tab.

  • Set the QoS file toShapes_Demo_QoS.xml.
    INSTALLDIR/ADLINK/Vortex_v2/Device/VortexOpenSplice/6.8.x/HDE/x86_64.linux/tools/matlab/

    examples/simulink/dds_reader_writer_model/Shapes_Demo_QoS.xml

12.4.2.5. Set Reader Block Parameters

  • Double click on the Reader block to edit the Block Parameters. Set the Input Data Type to the bus: ShapeType.

  • Select the QoS tab.

  • Set the QoS file toShapes_Demo_QoS.xml.
    INSTALLDIR/ADLINK/Vortex_v2/Device/VortexOpenSplice/6.8.x/HDE/x86_64.linux/tools/matlab/

    examples/simulink/dds_reader_writer_model/Shapes_Demo_QoS.xml

12.4.2.6. Connect Topic and Reader

  • Connect the Topic block topic output to the Reader block topic input.

Connect Topic and Reader

12.4.2.7. Add a Bus Selector to read and display sample data

To read and display sample data, we will add a Simulink / Signal Routing / Bus Selector block to our diagram.

12.4.2.8. Set Bus Selector Block Parameters

Specify the output signals we would like to display in our simulation. For this example, we will display all the ShapeType BUS signals in the running simulation.

  • Connect the Reader data output to the Bus Selector.

  • Double click on the Bus Selector block to edit the Block Parameters.

  • Add all the signals in the bus to the Selected signals.

Bus Selector Block Parameters

12.4.2.9. Add Bus Selector outputs

For demonstration purposes, we will output the bus signals using 2 Simulink Display blocks and an XY Graph.

Note: To change the positioning of block ports, you can use the Rotate & Flip block menu item, accessible by right clicking on a block.

  • Drag 2 Simulink / Sinks / Display blocks onto the diagram.

  • Connect the Display blocks to the Bus Selector output signals.
    • Connect the Bus Selector color output signal to a Display block.

    • Connect the Bus Selector shapesize output signal to a Display block.

Note: Default Display block settings used.

Bus Selector Outputs
  • Drag Simulink / Sinks / XY Graph block onto diagram

  • Connect the BusSelector x and y outputs to the XY Graph block.

  • Set the Block Parameters on the XY Graph:

    X-min: 0 X-max: 400 Y-min: 0 Y-max: 400

Bus Selector XY Graph

Save your model!!! The model is now complete!

12.5. Running Simulations

We now have two Simulink models. We will run both models and see that data samples are being written by one model and read be the second model.

12.5.1. Setup Write Model

  1. Open shapes_write_model.slx.

  2. Select menu item Simulation / Update Diagram to diagnose any possible model problems.

  3. Fix any issues.

12.5.2. Setup Read Model

  1. Open shapes_read_model.slx.

  2. Select menu item Simulation / Update Diagram to diagnose any possible model problems.

  3. Fix any issues.

12.5.3. Run Simulations

  1. Position models side by side.

  2. Start the read model simulation.

  3. Start the write model simulation.

  4. Expected: The write model will write samples, that are received by the read model and displayed in that model’s XY Graph and Display blocks.

  5. The write model will run to completion. The read model needs to be stopped manually.

Run Simulations

Run Results

Run results