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.
Buses define the data which will be published and read. Both the read and write Simulink models will make use of a bus to read and write sample data.
For this tutorial, we will create a BUS named ShapeType.
Note: If the Key is not set, the topic block’s Key annotation in the model will be shown empty and it will result in a keyless topic. Keyless topics have only one instance.
The ShapeType bus will have 4 bus elements: color, x, y and shapesize.
A BusElement can be added to the ShapeType bus by selecting the Add/Insert BusElement button.
A BusElement can be moved up or down using the Move Element Up and Move Element Down buttons.
Note: This creates a DDS ‘string’ type. Bus elements of type ‘int8’ or ‘uint8’ with an annotation of @String in the Description field define a DDS string. Dimension set to 10 means Simulink is going to read only the first ten bytes of the string. You can also use the ‘@BString’ annotation to define a DDS bounded string. The dimension of the field is treated as the maximum string size.
When bus objects are added to the MATLAB workspace, they will be lost on MATLAB close or workspace clear. To persist the bus objects, they can be exported.
A quick way to export the ShapeType bus using the bus editor, is to right click on the bus and select Export ShapeType to File…
The ShapeType bus is complete.
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.
The data dictionary can then be referenced from your models.
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)
Steps:
In MATLAB, navigate to the directory that contains the ShapeType.idl file. Set this directory to be the MATLAB Current Folder.
Call the idlImportSl function in the MATLAB command window.
>> Vortex.idlImportSl(‘ShapeType.idl’, ‘shape.sldd’)
where:
‘ShapeType.idl’ is the name of the IDL file
‘shape.sldd’ is the name of the target data dictionary for the generated bus definitions
To make use of the bus definitions generated into the data dictionary, Simulink models can specify design data using the Model Explorer.
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.
Double click on the Topic to bring up the Block Parameters dialog.
The Ports tab allows for the setting of optional ports. For this model, we will not change the defaults.
Select the QoS tab.
/examples/simulink/dds_reader_writer_model/Shapes_Demo_QoS.xml
Connect the Topic topic output to the Writer topic input.
Connect the Publisher ppub output to the Writer ppub input.
Double click on the Writer block to edit the Block Parameters. Set the Input Data Type to the bus: ShapeType.
Select the Writer QoS tab.
Set the QoS file to: Shapes_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
To generate sample data, we will add a Simulink / Signal Routing / BusCreator block to our diagram.
For demonstration purposes, we will input to the BusCreator signals using Constant, Clock and Sine Wave blocks.
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 / Sources / Constant blocks onto the diagram
- Connect one Constant block to color input signal
- Connect one Constant block to shapesize input signal
Set Block Parameters for Math Function block.
Set Function to: mod
Set Output signal type to: real
Save your model. Your model is now complete!
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.
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.
Double click on the Topic to bring up the Block Parameters dialog, select Topic tab.
Note: If the ShapeType bus is not displayed, select Refresh data types from dropdown list.
Set the Topic Name to: Circle.
Select the QoS tab.
examples/simulink/dds_reader_writer_model/Shapes_Demo_QoS.xml
Double click on the Reader block to edit the Block Parameters. Set the Input Data Type to the bus: ShapeType.
Select the QoS tab.
examples/simulink/dds_reader_writer_model/Shapes_Demo_QoS.xml
To read and display sample data, we will add a Simulink / Signal Routing / Bus Selector block to our diagram.
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.
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.
Note: Default Display block settings used.
Drag Simulink / Sinks / XY Graph block onto diagram
Connect the BusSelector x and y outputs to the XY Graph block.
X-min: 0 X-max: 400 Y-min: 0 Y-max: 400
Save your model!!! The model is now complete!
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.
Run Results