dds positioning system application -凯发k8网页登录
this example shows how to import, model, and deploy a dds application. the example application is a multi-sensor positioning system designed to estimate the position of a vehicle. the positioning system is composed of three components: a sensor component, an estimation component, and a display component. in the positioning system, the sensors send data to the estimation component that calculates the vehicle position estimate that it sends to the display component to show as a visual representation of the estimated vehicle position.
import dds definitions for positioning system
for the positioning system, the dds definitions (for example, domains, topics, types, and qos policies) were specified in xml. in the general dds blockset workflow, you use the dds application quick start to import these xml definitions. for this example, the xml has already been imported. to view the xml specifications for the positioning system, open the xml file positioning_system.xml
. to view the representation of these definitions in the dds blockset, open the dds dictionary:
open positioning_system.sldd
model and configure sensor component
the first component in the positioning system is the sensors. the positioning system uses an accelerometer and gps, each represented by a model, to estimate the vehicle position. each sensor model is constructed as a publisher. to view the model structure and interface, open the models:
open_system('ex_accelerometer');
open_system('ex_gps');
in each sensor model, you can view each aspect of a publisher modeled in simulink:
the sensor model logic, which is composed of a function block that simulates sensor input data.
the write dds sample block that converts the sensor data from a simulink data type to a dds data type.
the bus element out block that sends the dds data type.
in addition to the modeling of the sensors, the dds interface has been configured for each sensor model. you can view the dds interface for each sensor in the code mappings editor:
on the toolstrip, click the code interface and select individual elements code mappings.
to view the imported topic and datawriter for each sensor, click on the outports tab.
model and configure position estimate component
the second component is the estimate model. the estimate model receives data from the sensors and calculates the estimated position of the vehicle. the estimation model is constructed as a subscriber to the sensors and as a publisher to the display component. to view the model structure and interface, open the model:
open_system('ex_positionestimator');
in the estimation model, you can view each aspect of a subscriber and publisher modeled in simulink:
the estimation model has two bus element in blocks configured as dds data types to receive the sensor data.
the model has a take dds sample block attached to each bus element in block to convert the dds data types to simulink data types.
the estimation model computes the logic to estimate the vehicle position.
the model uses the write dds sample block to convert the simulink data types to dds data types.
the estimate model uses an bus element out block to send the estimate as a dds data type to the display component.
in addition to the modeling of the estimation model, the dds interface has been configured for the estimation model. you can view the dds interface in the code mappings editor:
on the toolstrip, click the code interface and select individual elements code mappings.
to view the imported topics and datareaders, click on the inports tab.
to view the imported topics and datawriter, click on the outports tab.
model and configure display component
the third component is the display model. the display model receives and graphically displays the estimated position of the vehicle. the display model is constructed as a subscriber to the estimation component. to view the model structure and interface, open the model:
open_system('ex_resultdisplay');
in the display model, you can view each aspect of an application that acts as a subscriber modeled in simulink:
the estimation model has an bus element in block configured as a dds data type to receive the vehicle position estimate.
the model has a take dds sample block to convert the dds data type to the simulink data type so that it can display the vehicle estimate.
the model logic of the display component graphically shows the estimate of the vehicle position.
in addition to the modeling the display model, the dds interface has been configured. you can view the dds interface in the code mappings editor:
on the toolstrip, click the code interface and select individual elements code mappings.
to view the imported topic and datareader to recieve the estimate, click on the imports tab.
build and deploy positioning system
to visually show the dds positioning system application, this example simulates the dds network to show the results of the positioning system. a queue block is placed between accelerometer and position estimator model blocks to simulate history qos. when you simulate the application, you can see on the dashboard that the position estimation system produces a more accurate position of the vehicle than the sensor input.
open_system('ex_positioningsystem');
set_param('ex_positioningsystem/dds samples: gpspos','timespan','10'); set_param('ex_positioningsystem/dds samples: estpos','timespan','10'); sim('ex_positioningsystem'); set_param('ex_positioningsystem/dds samples: gpspos','timespan','100'); set_param('ex_positioningsystem/dds samples: estpos','timespan','100');
to see the effect of quality of service (qos) on the estimate, if the qos is not honored the results are inaccurate.
set_param(['ex_positioningsystem/queue for history' newline 'qos simulation'], ... 'commented','through') set_param('ex_positioningsystem/dds samples: gpspos','timespan','10'); set_param('ex_positioningsystem/dds samples: estpos','timespan','10'); sim('ex_positioningsystem'); set_param('ex_positioningsystem/dds samples: gpspos','timespan','100'); set_param('ex_positioningsystem/dds samples: estpos','timespan','100');
after reviewing the simulation of the positioning system, if you would like to deploy this example, you can build the ex_positionestimator
model and use the executable to deploy this application on the dds network.