Main Content

export

Export driving scenario to ASAM OpenDRIVE or ASAM OpenSCENARIO file

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.

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

Figure contains an axes object. The axes object contains 10 objects of type patch, line.

Export the scenario to an ASAM OpenSCENARIO® file.

export(scenario,"OpenSCENARIO","parking.xosc");
Warning: Exported road network to OpenDRIVE may have minor variations from actual road network in the scenario. For more information, see <a href="matlab:helpview(fullfile(docroot,'toolbox','driving','helptargets.map'),'exportOpenDriveCLI')">export</a>.

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

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.

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