Main Content

export

Export driving scenario to ASAM OpenDRIVE, ASAM OpenSCENARIO or RoadRunner HD Map file

Since R2020b

Description

example

export(scenario,"OpenDRIVE",filename) exports the roads, lanes, junctions, and actors in a driving scenario to the ASAM OpenDRIVE® file format, describing the static content of driving scenario. There may be variations between the original scenario and the exported scenario. For details, see Limitations.

The function supports exporting driving scenarios to OpenDRIVE® file versions V1.4, V1.5, and ASAM OpenDRIVE file version V1.6.

example

export(scenario,"OpenSCENARIO",filename) exports the road network, actors, and trajectories in a driving scenario to the ASAM OpenSCENARIO® file format, describing the dynamic content of driving scenario. Exporting to an ASAM OpenSCENARIO file also exports several data files. For more information, see Data Files Exported with ASAM OpenSCENARIO File. To know about the default actor parameters that the function exports, see ASAM OpenSCENARIO Representations.

The function supports exporting driving scenarios to ASAM OpenSCENARIO file versions V1.0 and V1.1.

Note

  • The function interpolates additional waypoints between the ones specified in the driving scenario, to generate smooth trajectories for exported actors in the output ASAM OpenSCENARIO file.

  • The function does not support exporting reverse waypoints of actors to an ASAM OpenSCENARIO file.

example

export(___,Name=Value) specifies options using one or more name-value arguments and any of the input argument combinations from previous syntaxes. For example, export(scenario,"OpenDRIVE",filename,OpenDRIVEVersion=1.5) exports the driving scenario to V1.5 of the OpenDRIVE file format.

export(scenario,"RoadRunner HD Map",filename) exports the road network and static actors in a driving scenario to the RoadRunner HD Map file format, describing the static content of driving scenario. There may be variations between the original scenario and the exported scenario. For details, see Limitations.

Examples

collapse all

Create a driving scenario.

inputScenario = drivingScenario;

Import a OpenStreetMap® road network into the driving scenario. For more information about the osm file, see [1].

fileName = "chicago.osm";
roadNetwork(inputScenario,"OpenStreetMap",fileName);

Export to ASAM OpenDRIVE® file.

fileName = "chicago.xodr";
export(inputScenario,"OpenDRIVE",fileName);
Warning: There may be minor variation between the actual driving scenario and the exported OpenDRIVE road networks. For more information, see <a href="matlab:helpview(fullfile(docroot,'toolbox','driving','helptargets.map'),'exportOpenDriveCLI')">export</a>.

Read the exported ASAM OpenDRIVE file by using the roadNetwork function.

scenario = drivingScenario;
roadNetwork(scenario,"OpenDRIVE",fileName);

Plot the exported scenario. Notice that the display for the exported road network is flipped along the x and y dimensions and does not have the border lines.

figure
plot(inputScenario)
zoom(2);
title("Actual Scenario")

figure
plot(scenario)
zoom(2);
title("Exported Scenario")

Appendix

[1] The osm file is downloaded from https://www.openstreetmap.org, which provides access to crowd-sourced map data all over the world. The data is licensed under the Open Data Commons Open Database License (ODbL), https://opendatacommons.org/licenses/odbl/.

Create the driving scenario with one road having an S-curve.

scenario = drivingScenario;
roadcenters = [-35 20 0; -20 -20 0; 0 0 0; 20 20 0; 35 -20 0];

Create the lanes and add them to the road.

lm = [laneMarking("Solid",Color="w") ...
     laneMarking("Dashed",Color="y") ...
     laneMarking("Dashed",Color="y") ...
     laneMarking("Solid",Color="w")];
ls = lanespec(3,Marking=lm);
road(scenario,roadcenters,"Lanes",ls);

Plot the scenario.

plot(scenario)

Export the road network in the scenario to ASAM OpenDRIVE® file.

fileName = "scurveroad.xodr";
export(scenario,"OpenDRIVE",fileName,OpenDRIVEVersion=1.6)
Warning: There may be minor variation between the actual driving scenario and the exported OpenDRIVE road networks. For more information, see <a href="matlab:helpview(fullfile(docroot,'toolbox','driving','helptargets.map'),'exportOpenDriveCLI')">export</a>.

You can import the ASAM OpenDRIVE file to MATLAB® workspace by using the roadNetwork function.

scenario = drivingScenario;
roadNetwork(scenario,"OpenDRIVE",fileName)
plot(scenario)

Copyright 2020-21 The MathWorks, Inc.

Create a driving scenario.

scenario = drivingScenario(StopTime=6);

Import the road network from an ASAM OpenDRIVE® file into the scenario.

fileName = "parking.xodr";  
roadNetwork(scenario,"OpenDRIVE",fileName);

Add an ego vehicle to the scenario. Set a trajectory in which the vehicle drives along the curve at varying speed.

egoVehicle = vehicle(scenario,ClassID=1);
waypoints = [-80 43; -34 29; -18 15; -10 -2; 4 -17; 38 -24; 52 -20];
speed = [50 20 20 20 20 50 50];
trajectory(egoVehicle,waypoints,speed);

Add a non-ego actor and set it to spawn during the simulation by specifying an entry time value. Generate a trajectory for the non-ego actor.

truck = vehicle(scenario,ClassID=2,Position=[4 -17 0],EntryTime=3);
waypoints = [4 -17; 20 -24; 38 -24; 60 -16];
speed = [40 40 40 40];
trajectory(truck,waypoints,speed);

Plot the scenario and run the simulation. Observe how the vehicle slows down as it drives along the curve.

plot(scenario,Waypoints="on");
while advance(scenario)
    pause(0.01)
end

Export the scenario to an ASAM OpenSCENARIO® file.

export(scenario,"OpenSCENARIO","parking.xosc");

Create a driving scenario object.

scenario = helperCreateDrivingScenario;

Plot the scenario.

plot(scenario)

Figure contains an axes object. The axes object with xlabel X (m), ylabel Y (m) contains 5 objects of type patch, line.

Export the driving scenario directly to a .rrhd binary file.

export(scenario,"RoadRunner HD Map","directExportScenario.rrhd")

Alternatively, you can first get the RoadRunner HD Map object for the scenario and plot it.

rrMap = getRoadRunnerHDMap(scenario);
plot(rrMap)

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent Lane Boundaries, Lane Centers.

You can inspect it and make any desired modifications. Then, write the RoadRunner HD Map to a .rrhd binary file.

write(rrMap,'4wayIntersection.rrhd')

Import the map into RoadRunner. Specify the import options to enable overlap groups.

rrApp = roadrunner("D:\RR\TestProjects");
impOpts = roadrunnerHDMapImportOptions(BuildOptions=roadrunnerHDMapBuildOptions(EnableOverlapGroupsOptions=enableOverlapGroupsOptions(IsEnabled=false)));
importScene(rrApp,fullfile(pwd,"4wayIntersection.rrhd"),"RoadRunner HD Map",impOpts)

Helper Functions

helperCreateDrivingScenario creates a four way intersection driving scenario with an ego vehicle and a pedestrian.

function scenario = helperCreateDrivingScenario

% Create scenario and add roads
scenario = drivingScenario;
roadCenters = [0 40 0;
    0 -40 0];
marking = [laneMarking('Solid')
    laneMarking('Dashed')
    laneMarking('Solid')];
laneSpecification = lanespec(2, 'Width', 3.5, 'Marking', marking);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Road');

roadCenters = [-40 0 0;
    40 0 0];
marking = [laneMarking('Solid')
    laneMarking('Dashed')
    laneMarking('Solid')];
laneSpecification = lanespec(2, 'Width', 3.5, 'Marking', marking);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Road1');

% Add ego vehicle
egoVehicle = vehicle(scenario, ...
    'ClassID', 1, ...
    'Position', [-1.75 30 0], ...
    'FrontOverhang', 0.9, ...
    'Wheelbase', 2.8, ...
    'Mesh', driving.scenario.carMesh, ...
    'Name', 'Vehicle Under Test');
waypoints = [-1.75 30 0;
    -1.75 10.629767723813 0;
    -0.980075893866154 4.2738387109925 0;
    4.2738387109925 -0.980075893866154 0;
    10.629767723813 -1.75 0;
    30 -1.75 0];
speed = 2.77777777777778;
yaw =  [-90;-90;-69.38;-20.62;0;0];
smoothTrajectory(egoVehicle, waypoints, speed, 'Yaw', yaw);

% Add the non-ego actors
euroncappedestriantarget = actor(scenario, ...
    'ClassID', 4, ...
    'Length', 0.6, ...
    'Width', 0.5, ...
    'Height', 1.8, ...
    'Position', [9.5 -7.75 0], ...
    'PlotColor', [237 177 32] / 255, ...
    'Name', 'Euro NCAP Pedestrian Target');
waypoints = [9.5 -7.75 0;
    9.5 -6.75 0;
    9.5 10 0];
speed = [0;1.38888888888889;1.38888888888889];
waittime = [7.82;0;0];
trajectory(euroncappedestriantarget, waypoints, speed, waittime);
end

Input Arguments

collapse all

Driving scenario, specified as a drivingScenario object. The driving scenario must contain one or more road networks in order to export it to the ASAM OpenDRIVE file format.

The driving scenario must contain one or more actors to export it to the ASAM OpenSCENARIO file format.

If the driving scenario does not have lane specifications, then the export function assigns a default lane specification while exporting the road network to the ASAM OpenDRIVE or ASAM OpenSCENARIO file format.

Name of the destination file, specified as a character vector or string scalar. You can specify the file name with or without the file extension. If you choose to specify a file extension, the file extension must be one of these:

  • ASAM OpenDRIVE File — .xodr (default) or .xml

  • ASAM OpenSCENARIO File — .xosc (default) or .xml

  • RoadRunner

    HD Map File — .rrhd

If the specified file name, including the file extension, already exists, then the function overwrites the data in the existing file with the driving scenario specified in the scenario argument.

Data Types: char | string

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: export(scenario,"OpenDRIVE","newfile.xodr",OpenDRIVEVersion=1.6) exports a driving scenario to ASAM OpenDRIVE file version V1.6.

Version of the OpenDRIVE file, specified as 1.4, 1.5, or 1.6. The function exports the driving scenario to the specified version of OpenDRIVE file.

Data Types: single | double

Export actors flag, specified as a logical 1 (true) or logical 0 (false).

  • true or 1 — Export actors from the driving scenario to the ASAM OpenDRIVE file.

  • false or 0 — Do not export actors from the driving scenario to the ASAM OpenDRIVE file.

Data Types: logical

Version of the ASAM OpenSCENARIO file, specified as 1.0 or 1.1. The function exports the driving scenario to the specified version of ASAM OpenSCENARIO file.

Data Types: single | double

Export TimeReference element flag, specified as a logical 1 (true) or logical 0 (false).

  • true or 1 — Export TimeReference element of the FollowTrajectoryAction with Timing property to ASAM OpenSCENARIO file. The function exports absolute time domain values of actor waypoints without any scaling and offset from the driving scenario to the Trajectory element within the Init section of the output ASAM OpenSCENARIO file. This option specifies that you should consider the time information of exported actor trajectories that completely specify the motion of actors, including their speed and wait times. As such, the Story element of the exported file does not contain any SpeedAction element. The Story element of the exported file can contain VisibilityAction elements if you specify valid EntryTime and ExitTime parameters for an actor.

  • false or 0 — Export empty TimeReference element of the FollowTrajectoryAction. This option specifies that you should not consider the time information contained in the Trajectory element within the Init section of the output ASAM OpenSCENARIO file. The exported actor trajectories do not specify speed along the path. So, the function separately exports speed of an actor using the SpeedAction elements within the Story element of the exported file. The Story element of the exported file can also contain VisibilityAction actions if you specify valid EntryTime and ExitTime parameters for an actor.

Data Types: logical

Limitations

ASAM OpenDRIVE Export Limitations

Roads

  • The cubic polynomial and the parametric cubic polynomial geometry types in the scenario are exported as spiral geometry types. This causes some variations in the exported road geometry if the road is a curved road. For example, in the figure below, notice that the sharp corners in the input road became relatively smooth when exported to the ASAM OpenDRIVE format.

    Input RoadExported ASAM OpenDRIVE Road

    Original road

    Exported road

  • When segments of adjacent roads overlap with each other, the function does not export the overlapping segments of the roads.

    Input RoadsExported ASAM OpenDRIVE Roads

    Input overlapping roads

    Exported roads

Lanes

  • When a road with multiple lane specifications contains a taper between two road segments, the function exports the road without taper.

    Input RoadExported ASAM OpenDRIVE Road

    Original road with taper

    Exported road without taper

  • When a road consisting of multiple segments is connected to a junction, the function does not export the road.

Junctions

  • The junctions of the road network are processed without lane connection information, so the junction shapes may not be accurate in the exported scenario.

    Input RoadExported ASAM OpenDRIVE Road

    Original junction

    Exported junction

  • When a junction is not connected to any road, the function does not export such junction.

    Input RoadsExported ASAM OpenDRIVE Roads

    Original road network

    Exported road network without junction

    To export a detached junction to an ASAM OpenDRIVE file, you can manually drag incoming or outgoing roads and attach them to the junction.

Actors

  • The export function does not export any actor that is present either on a junction or on a road with multiple road segments.

  • While exporting a user-defined actor, the function sets the type of object to 'none'.

ASAM OpenDRIVE Import

  • When you export a driving scenario object that contains an imported ASAM OpenDRIVE scenario, the limitations of ASAM OpenDRIVE import apply to ASAM OpenDRIVE export. You can import an ASAM OpenDRIVE scenario to a drivingScenario object by using the roadNetwork function. For information on the limitations of ASAM OpenDRIVE import, see roadNetwork.

RoadRunner HD Map Export Limitations

A RoadRunner Scene Builder license is required to build a scene from the HD map file. Without a RoadRunner Scene Builder license, you can import the HD map file and only view the map as nodes and links in RoadRunner.

Composite Lane Specifications

  • Roads that use composite lane specifications (compositeLaneSpec) and form loops or intersect with themselves are not supported.

  • Composite lane specifications for creating roads with varying widths are not supported

Lane Markings and Lane Type

  • For lane markings created using the laneMarking object and lane types created using the laneType object, only Color name-value argument is supported. Only white and yellow colors are supported.

  • For roads that form loops, multiple lane marking styles are not supported.

Parking Lot

  • Driving scenarios containing parking lots added using the parkingLot function are not supported.

Barriers

  • Barriers with gaps between segments created using the barrier function with SegmentGap name-value argument, are not supported. Such barriers will be laid out without any gaps in the RoadRunner HD map representation.

  • For barriers, setting the SegmentLength, Width, and Height properties are not supported. These properties are calculated automatically based on the asset size during import to RoadRunner.

Static Actors

  • Static actors such as pedestrians and bicycles are not supported. To represent these actors in RoadRunner, you can either download a cuboid FBX and place it under Assets/Vehicles/ or edit the map to point to their own assets.

Road Groups and Road Networks

  • Road junctions and intersections added using the roadGroup function are not supported.

  • Road networks created using the roadNetwork function are not supported when they use road groups.

More About

collapse all

Data Files Exported with ASAM OpenSCENARIO File

While exporting a driving scenario to an ASAM OpenSCENARIO file, the function also exports additional data files. Each data file describes information about a specific element, such as a vehicle or pedestrian. The name of each data file has the prefix filename_, where the filename is the name specified in filename argument, excluding the extension.

Data FileElement of Scenario
filename_OpenDRIVE.xodrRoad network and barriers in the scenario
filename_VehicleCatalog.xoscProperties of vehicles
filename_PedestrianCatalog.xoscProperties of pedestrians

Note

  • The function exports data files based on the contents of the scenario. For example, if the scenario does not contain any pedestrians, then the data file filename_PedestrianCatalog.xosc is not exported.

  • As of R2021b, the function exports actor routes to the primary ASAM OpenSCENARIO file using instances of the Trajectory element. In R2021a, the routes of actors are exported separately using a RouteCatalog file that contains instances of the Route element.

  • When a driving scenario contains a road network, the limitations of ASAM OpenDRIVE export apply to the exported OpenDRIVE.xodr data file.

Version History

Introduced in R2020b