Main Content

Export Multiple Scenes Using MATLAB

This example shows how to bulk-export scenes from a RoadRunner project to one of the file formats supported by RoadRunner. In this example, you export scenes to the ASAM OpenDRIVE® file format using MATLAB® functions.

To run this example, you must:

  • Have an Automated Driving Toolbox® license.

  • Have a RoadRunner® license and the product is installed.

  • Have created a RoadRunner project folder.

Start RoadRunner Programmatically

To use MATLAB functions to control RoadRunner programmatically, use the roadrunner object. By default, roadrunner opens RoadRunner from the default installation folder for the platform you are using (either Windows® or Linux®). These are the default installation locations by platform:

  • Windows – C:\Program Files\RoadRunner R20NNx\bin\win64

  • Linux, Ubuntu® – /usr/local/RoadRunner_R20NNx/bin/glnxa64

R20NNx is the MATLAB version for the release you are using.

If your RoadRunner installation is at a different location than the default location, use MATLAB settings API to customize the default value of the RoadRunner installation folder.

Export Scene from RoadRunner to ASAM OpenDRIVE

Export a scene from a RoadRunner project to the ASAM OpenDRIVE format using MATLAB.

Open a project in RoadRunner using the roadrunner function by specifying the location in which to create a project. This example assumes that RoadRunner is installed in its default location in Windows.

Specify the path to an existing project. For example, this code shows the path to a project located on C:\RR\MyProject. The function returns a roadrunner object, rrApp, that provides functions for performing basic workflow tasks such as opening, closing, and saving scenes and projects.

projectFolder = "C:\RR\MyProject";
rrApp = roadrunner(projectFolder,InstallationFolder="C:\Program Files\RoadRunner R2022b\bin\win64");

Open a scene in the project by using the openScene function with the roadrunner object and the RoadRunner scene you wish to open as input arguments. This example uses the FourWaySignal.rrscene scene, which is one of the scenes included by default in RoadRunner projects, and is located in the Scenes folder of the project.

sceneName = "FourWaySignal.rrscene";
openScene(rrApp,sceneName);

Set export options by creating an openDriveExportOptions object to enable export of signals and objects from the file.

options = openDriveExportOptions(OpenDriveVersion=1.5,ExportSignals=true,ExportObjects=true);

Use the exportScene function to export the scene to ASAM OpenDRIVE. Specify your roadrunner object, the name of the file to which you want to export the scene, the export format, and the export options as input arguments to the exportScene function.

filename = "FourWaySignal.xodr";
formatname = "OpenDRIVE";
exportScene(rrApp,filename,formatname,options);

Export Multiple Scenes from RoadRunner to ASAM OpenDRIVE Format

Export multiple scenes in a RoadRunner project to ASAM OpenDRIVE® format using MATLAB.

Open a project in RoadRunner using the roadrunner function by specifying the location in which to create a project. This example assumes that RoadRunner is installed in its default location in Windows.

Specify the path to an existing project. For example, this code shows the path to a project located on C:\RR\MyProject. The function returns a roadrunner object, rrApp, that provides functions for performing basic workflow tasks such as opening, closing, and saving scenes and projects.

demoProj = fullfile('C:','DemoProject');
rrApp = roadrunner(demoProj,InstallationFolder="C:\Program Files\RoadRunner R2022b\bin\win64");

Specify the path to the scene files you wish to export. You must specify the path to the Scenes folder in your RoadRunner project, which contains all the scenes in that project.

sceneFiles = dir(fullfile(demoProj,'Scenes','*.rrscene'));
scenes = {sceneFiles.name};

Specify the path to your export folder. this is the folder into which RoadRunner exports all your scene files. Iterate through all the scene files, opening each scene using the openScene function and then calling the exportScene function to export the open scene to the ASAM OpenDRIVE format.

exportFolder = fullfile('C:','OpenDRIVE');
for sndx = 1:numel(scenes)
    openScene(rrApp,scenes{sndx});
    [~,fileName] = fileparts(scenes{sndx});
    exportFilePath = [fullfile(exportFolder,fileName) '.xodr'];
    exportScene(rrApp,exportFilePath,'OpenDRIVE');
end

Once all the scene files have been exported, close the RoadRunner application by using the close function.

close(rrApp);

Extend RoadRunner Export Options

To customize the script further, you can specify non-default export settings or specify other file formats. For more details on supported formats, see the exportScene function. For additional flexibility in exporting scenes, consider exporting the scene using custom export options. For more details, see the exportCustomFormat function.

See Also

| | |

Related Topics