Main Content

Create Routes Similar to Seed Actor Trajectory in Scenes

This example shows how to create routes, in multiple target scenes, which are similar to an actor trajectory in the seed scenario.

Creating routes in scenes is useful for various automated driving test applications. However, manual creation of routes for each scene is not scalable, and is prone to human error. Unlike manual route creation, this example explains how to create trajectories for various scenes automatically, with reference to a trajectory in the seed scenario.

In this example, you:

  • Configure MATLAB® settings to interact with RoadRunner Scenario.

  • Explore the seed scenario using RoadRunner.

  • Extract actor properties from the seed scenario and visualize the actor trajectory in MATLAB.

  • Extract all routes from each RoadRunner scene.

  • Find a subset of routes that match the seed actor trajectory, and visualize a similar route for each target scene.

Set Up Environment

This section shows how to set up the environment to cosimulate MATLAB with RoadRunner Scenario.

This example requires Automated Driving Toolbox™ Test Suite for Euro NCAP® Protocols support package. Check if the support package is installed.

helperCheckSupportPackageInstalled

Specify the path to your local RoadRunner installation folder. This code shows the path for the default installation location on Windows®.

rrAppPath = "C:\Program Files\RoadRunner R2023b\bin\win64";

To update the MATLAB path for the RoadRunner installation folder, get the root object within the settings hierarchical tree, and update the TemporaryValue for the RoadRunner installation folder property.

For more information, see SettingsGroup.

s = settings;
s.roadrunner.application.InstallationFolder.TemporaryValue = rrAppPath;

Specify the path to your RoadRunner project. This code shows the path for a sample project folder location in Windows.

rrProjectPath = "C:\RoadRunnerProject";

Open RoadRunner using the specified path to your project. The rrApp RoadRunner object enables you to interact with RoadRunner from the MATLAB workspace.

rrApp = roadrunner(rrProjectPath);

This example uses a seed scenario file that you must add to the RoadRunner project.

actorTrajectory.rrscenario — RoadRunner seed scenario containing a reference actor trajectory to use to generate similar trajectories in target scenes.

referenceScenario = "actorTrajectory.rrscenario";

Copy the seed scenario file to the RoadRunner project. To learn more about the RoadRunner environment, see RoadRunner Project and Scene System (RoadRunner).

copyfile(referenceScenario,fullfile(rrProjectPath,"Scenarios"))

Explore Seed Scenario

Open the seed scenario actorTrajectory.rrscenario.

openScenario(rrApp,referenceScenario)

seedTrajectory.png

The scenario contains a vehicle. The vehicle travels on the path specified in the scenario, first turning left at a junction, and then turning right to reach its destination.

Extract Actor Trajectory from Seed Scenario

Connect to the RoadRunner Scenario server from MATLAB, for cosimulation, using the createSimulation function.

rrSim = createSimulation(rrApp);

Extract properties from the seed scenario, and store these properties in a ScenarioDescriptor object, descriptor, by using the getScenarioDescriptor function. Additionally, store the name of the scene by using the status (RoadRunner) function.

scenario.SimulatorInstance = rrApp;
scenario.SimulationInstance = rrSim;
descriptor = getScenarioDescriptor(scenario,Simulator="RoadRunner");
rrStatus = status(rrApp);
seedName = rrStatus.Scene.Filename;
close(rrApp)

Extract the properties of an actor, specified by actorID, from descriptor by using the helperGetActorProfiles function.

actorID = 1;
actorData = helperGetActorProfiles(descriptor,actorID)
actorData = struct with fields:
          Time: [337×1 double]
     WayPoints: [337×3 double]
           Yaw: [337×1 double]
         Pitch: [337×1 double]
          Roll: [337×1 double]
      Velocity: [337×1 double]
    Dimensions: [1×1 struct]

Save the waypoints of the actor to the variable actorRoute.

actorRoute = actorData.WayPoints;

Visualize the actor trajectory in blue. The green and red markers represents the start and end waypoints of the route.

plot(actorRoute(:,1),actorRoute(:,2),"b")
hold on
plot(actorRoute(1,1),actorRoute(1,2),"g*")
plot(actorRoute(end,1),actorRoute(end,2),"r*")

Extract Routes from Target Scenes

Fetch the names of all the RoadRunner target scenes available in the path specified by rrProjectPath.

sceneNames = helperFindSceneNames(rrProjectPath);

Create a RoadRunner HD Map for each target scene, and store them along with their scene names in a structure sceneMaps by using the helperSceneToMap function.

sceneMaps = helperSceneToMap(rrProjectPath,sceneNames,referenceScenario)
sceneMaps=1×13 struct array with fields:
    SceneName
    Map
    codeGenMap

Extract all feasible routes for each target scene by using the helperFetchAllRoutes function. For each target scene, the helper function stores all the routes in a cell array. The helper function returns these routes along with their scene names in a structure routeInfo.

routeInfo  = helperFetchAllRoutes(sceneMaps)
routeInfo=1×13 struct array with fields:
    Name
    TotalRoutes

Find Routes Similar to Actor Trajectory

For each target scene, find a subset of routes, from all extracted routes, which are similar to the actor trajectory in the seed scenario by using the helperMatch function. This helper function stores a subset of similar routes as a cell array in descending order of their scale of similarity with the seed scenario actor trajectory.

routeInfo = helperMatch(routeInfo,actorRoute)
routeInfo=1×5 struct array with fields:
    Name
    TotalRoutes
    MatchedRoutes

Visualize the actor trajectory in the seed scenario and a similar route in each target scene by using the helperVisualizeScenes function. The figure shows the actor trajectories in blue. The green and red markers represents the start and end waypoints of the route.

referenceScenarioMap = helperSceneToMap(rrProjectPath,seedName,referenceScenario);
helperVisualizeScenes(referenceScenarioMap,actorRoute,routeInfo,sceneMaps)

Helper Function

helperFindSceneNames finds the names of all the scenes within a given project folder.

function sceneNames = helperFindSceneNames(rrProjectPath)

% This function returns all the filenames of RoadRunner scenes within a specified project path.
% Input
%   - rrProjectPath : RoadRunner project path, specified as a string scalar. It specifies a path that contains RoadRunner scenes.
% Output
%   - scenes : Filenames of the RoadRunner scenes, returned as a 1-by-N structure. N is the number of RoadRunner files present in the specified path rrProjectPath.

% Find all files with extension .rrscene
path = rrProjectPath + "\Scenes\*.rrscene";
x = dir(path);
numScenes = size(x,1);
for i = 1:numScenes
    sceneNames(i,1) = string(x(i).name);
end
end

See Also

Functions

Related Topics