Main Content

Designing and Deploying Interoperable Applications for Heterogeneous Automated Driving Platforms

This example shows how to deploy the Automated Parking Valet application and interoperability between AUTOSAR Adaptive, DDS and ROS 2 over DDS network. This example extends the Automated Parking Valet (Automated Driving Toolbox) example in the ROS Toolbox and Automated Parking Valet in Simulink (Automated Driving Toolbox) example in the Automated Driving Toolbox™.

Example Prerequisites

Before running this example, verify that your system meets the following requirements:

Also, ensure you are familiar with the following examples:

The example deploys the nodes as shown below.

Register Custom Messages

Many of the existing ROS 2 messages use strings and may not be appropriate for deployment with various middleware. Since the string fields are not used in the application either, run exampleHelperBuildCustomMessage to register a custom message that is specific for the algorithm.

exampleHelperBuildCustomMessage
Identifying message files in folder '/tmp/Bdoc24a_2528353_1192037/tp56a3cac0/dds-ex54609270/custommsg'.Validating message files in folder '/tmp/Bdoc24a_2528353_1192037/tp56a3cac0/dds-ex54609270/custommsg'.Done.
Creating Python virtual environment for ros2.Done.
Adding required Python packages to virtual environment.Done.
Copying include folders.Done.
Copying libraries.Done.
Done.
[1/1] Generating MATLAB interfaces for custom message packages... Done.
Running colcon build in folder '/tmp/Bdoc24a_2528353_1192037/tp56a3cac0/dds-ex54609270/custommsg/matlab_msg_gen/glnxa64'.
Build in progress. This may take several minutes...
Build succeeded.build_log.Generating zip file in the folder '/tmp/Bdoc24a_2528353_1192037/tp56a3cac0/dds-ex54609270/custommsg'.Done.

Use the ros2 command to verify that the custom message is built.

ros2 msg show valet/Float64ArrayFixed
#Using fixed size data in preparation for production
#Copyright 2022-2023 The MathWorks, Inc.
float64[1500] data

Load Demo Data

The example loads localization data used for picking the parking spot. Use exampleHelperDDSValetLoadLocalizationData to load the pre-recorded localization map data. To park the car in a different spot, you can update the script.

exampleHelperDDSValetLoadLocalizationData;

Check for NDDSHOME and Start admin Console

This example uses RTI Connext®. Other vendors can also be used.

Set NDDSHOME and open rtiadminconsole.

NDDSHome = getenv('NDDSHOME');
if isempty(NDDSHome) || ~isfolder(NDDSHome)
    error('Ensure you have ''NDDSHOME'' set to your RTI Connext 6.x folder');
end

You can use the admin console to monitor messages.

%system(fullfile(NDDSHome,'bin','rtiadminconsole'));

Open ROS2 Models

The following models make up a ROS 2 network comprised of four ROS 2 nodes.

  • The behavioralModel reads the current vehicle information from ROS 2 network, sends the next goal and checks if the vehicle has reached the final pose of the segment.

  • The pathPlannerModel plans a feasible path through the environment map using a pathPlannerRRT (Automated Driving Toolbox) object, which implements the optimal rapidly exploring random tree (RRT*) algorithm and sends the plan to the controller over the ROS 2 network.

  • The controllerModel calculates and sends the steering and velocity commands over the ROS 2 network.

  • The vehicleModel simulates the vehicle controller effects and sends the vehicle information over the ROS 2 network.

behavioralModel = 'ROS2ValetBehavioralPlannerExampleNV';
pathPlannerModel = 'ROS2ValetPathPlannerExampleNV';
controllerModel = 'ROS2ValetControllerExampleNV';
controllerModelOrig = 'ROS2ValetControllerExampleNV_orig';
vehicleModel = 'ROS2ValetVehicleExampleNV';

Set Up Screen Space

% Get screen size and base params
scrSize = get(0, 'screensize');
h = scrSize(4);
w = scrSize(3);

Use Fixed Size Arrays

The original ROS 2 models are simplified to not use variants and then updated to use the fixed size arrays in preparation for deployment.

open_system(controllerModelOrig);
open_system(controllerModel);

set_param(controllerModelOrig,'Location', [w/2 h/2+5 w h-5]);
set_param(controllerModel,'Location', [1 h/2+5 w/2-5 h-35]);

The /velprofile topic uses fixed-size arrays. Typically this is necessary for production.

open_system([controllerModel,'/Subscribe/Subscribe8']);
open_system([controllerModelOrig,'/Subscribe/Subscribe8']);
close_system(controllerModelOrig)

Examine DDS Version of Controller System

The ROS2ValetBehavioralPlannerExample_DDS example model is converted to use DDS modeling elements. To step through the process of converting the ROS 2 model to DDS, use the exampleHelperCreateDDSModels example helper function. To optionally step through the process, uncomment the following line and run exampleHelperCreateDDSModels to transform the ROS 2 model to use DDS.

%exampleHelperCreateDDSModels({controllerModel, behavioralModel});

This conversion process analyzes the ROS 2 model, retrieves the messages and topics used by the model, and uses this information to populate a DDS Dictionary. Finally, it replaces ROS modeling semantics with DDS modeling semantics. For example, Subscribe blocks from the ROS Toolbox are replaced by Message Receive blocks from the Simulink® library.

open_system([controllerModel '_DDS']);
set_param([controllerModel '_DDS'],'Location', [w/2 h/2+5 w h-5]);
open_system(controllerModel);
close_system(controllerModel);
set_param([controllerModel '_DDS'],'Location', [1 h/2+5 w/2-5 h-5]);

Create AUTOSAR Model

A version of the AUTOSAR model is available. If you optionally want to step through the process, uncomment the following line and run exampleHelperCreateAdaptive to transform the DDS model to use Adaptive AUTOSAR.

%exampleHelperCreateAdaptive([behavioralModel '_DDS']);

Open AUTOSAR Model

open_system([behavioralModel '_DDS_adaptive']);
set_param([behavioralModel '_DDS_adaptive'],'Location', [1 50 w/2-5 h/2-5]);

Open Other ROS Models

open_system(pathPlannerModel);
set_param(pathPlannerModel,'Location', [w/2+5 50 w-5 h/2-5]);

open_system(vehicleModel);
set_param(vehicleModel,'Location', [w/2+5 h/2+5 w-5 h-35]);

Move models to the front to examine the system: Path Planner and Vehicle models using ROS 2, the Controller model using DDS, and the Behavioral model using Adaptive AUTOSAR.

open_system([controllerModel '_DDS']);
set_param([controllerModel '_DDS'],'Location', [1 h/2+5 w/2-5 h-35]);

open_system([behavioralModel '_DDS_adaptive']);
set_param([behavioralModel '_DDS_adaptive'],'Location', [1 50 w/2-5 h/2-5]);

Deploy DDS and AUTOSAR Models

This step of the example is supported for host Linux® or Windows® platforms only. Before deploying the Adaptive AUTOSAR model to a Linux platform, set up the Linux target. Based on your setup, update tgtName to your Linux® target name.

tgtName = 'LinuxTarget1';

Get the target handle using TargetManager.

if ~ismac 
    tgs = linux.Targets;
    tg = tgs.getTarget(tgtName);
else
    tg = [];
end

Use the following helper functions to generate C++ code and deploy the DDS and AUTOSAR models. When you run the system, the valet system consisting of the DDS, ROS 2, and AUTOSAR models automatically parks the car.

if ~isempty(tg) && ~isempty(tg.getIpAddress) && tg.isConnected
    exampleHelperDeployROS2AndDDSAndAutosar([behavioralModel '_DDS_adaptive'], ...
        pathPlannerModel, ...
        [controllerModel '_DDS'], ...
        vehicleModel, tg, false); %to rebuild set to true
end
bdclose all;