Translocate Collision from Seed Scenario to Target Scene
This example shows how to translocate a collision from a RoadRunner seed scenario to a target scene.
Creating collisions in scenarios is useful for various automated driving test applications. However, creating a test scenario for each scene is not scalable, and is prone to human error. Unlike manual test scene creation, this example explains how to translocate a collision from a seed scenario to a target scene using these steps.
Set Up MATLAB® — Configure MATLAB settings for interacting with RoadRunner Scenario.
Set Up RoadRunner Scenario — Open RoadRunner, and copy the required files to the RoadRunner project folder.
Explore Seed Scenario — Explore the seed scenario using RoadRunner.
Extract Actor Properties from Seed Scenario — Extract ego and target actor properties from the seed scenario.
Extract Collision Information — Extract colliding ego and target actor waypoints and their travel distances.
Explore Target Scene and Fetch Locations to Translocate Collision — Explore the target scene and fetch filtered locations to translocate the collision.
Translocate Collision from Seed Scenario to Target Scene — Translocate the collision from the seed scenario to the target scene, and visualize the collision.
Import Waypoints into RoadRunner — Write translocated ego and target waypoints to CSV files and import them into RoadRunner.
Set Up MATLAB
This section shows how to set up the environment to cosimulate MATLAB with RoadRunner Scenario.
Ensure that no other session of RoadRunner is currently open.
if exist("rrApp","var") close(rrApp) end
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 R2023a\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
s = settings; s.roadrunner.application.InstallationFolder.TemporaryValue = rrAppPath;
Set Up RoadRunner Scenario
Specify the path to your RoadRunner project. This code shows the path for a sample project folder location in Windows.
rrProjectPath = "C:\TestProject";
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 two files that you must add to the RoadRunner project.
Specify the filenames of the RoadRunner seed scenario and target scene.
seedScenario = "seedScenario.rrscenario"; targetScene = "LargeFourWayIntersection";
seedScenario file to the RoadRunner project. To learn more about the RoadRunner environment, see RoadRunner Project and Scene System (RoadRunner).
Explore Seed Scenario
Open the seed scenario
The scenario contains two vehicles. The red car is the ego vehicle and the blue car is the target vehicle. The ego vehicle has an initial speed of 0 m/s and accelerates to 16.2 m/s over a distance of 10 meters. The target vehicle has an initial of 0 m/s and accelerates to 15.4 m/s over a distance of 10 meters. Both vehicles travel on the path specified in the scenario, and they collide where their paths intersect.
Extract Actor Properties from Seed Scenario
Extract properties from the seed scenario, and store these properties in a
rrDescriptor, by using the
rrDescriptor = helperGetScenarioDescriptorRR(rrApp);
Specify the colliding actor IDs as
egoID = 1; targetID = 2;
Extract the properties for the actors specified by
targetID by using the
egoData = helperGetActorProfiles(rrDescriptor,egoID)
egoData = struct with fields: Time: [240×1 double] WayPoints: [240×3 double] Yaw: [240×1 double] Pitch: [240×1 double] Roll: [240×1 double] Velocity: [240×1 double] Dimensions: [1×1 struct]
targetData = helperGetActorProfiles(rrDescriptor,targetID)
targetData = struct with fields: Time: [221×1 double] WayPoints: [221×3 double] Yaw: [221×1 double] Pitch: [221×1 double] Roll: [221×1 double] Velocity: [221×1 double] Dimensions: [1×1 struct]
Extract Collision Information
Get the collision information of the colliding actors by using the
c = getCollisionData(rrDescriptor,Actor1ID=egoID,Actor2ID=targetID);
Extract the precollision actor waypoints for the ego and target vehicles by using the
Note: This function assumes that the ego and target vehicle waypoints intersect.
[egoData.preCollisionWayPoints,targetData.preCollisionWayPoints] = helperIntersectWayPoints(c,egoData.WayPoints,targetData.WayPoints);
Compute the total travel distance of the ego and target actors by using the
helperGetDistance function. This function calculates the travel distance of an actor based on the specified actor waypoints.
egoData.totalTravelDistance = helperGetDistance(egoData.WayPoints); targetData.totalTravelDistance = helperGetDistance(targetData.WayPoints);
Compute the precollision travel distance of the ego and target actors by using the
helperGetDistance function. Calculate the precollision travel distance using the extracted precollision actor waypoints.
egoData.preCollisionTravelDistance = helperGetDistance(egoData.preCollisionWayPoints); targetData.preCollisionTravelDistance = helperGetDistance(targetData.preCollisionWayPoints);
Explore Target Scene and Fetch Locations to Translocate Collision
Get the RoadRunner HD Map passing the seed scenario as an input to the
sourceRRHDMap = helperGetMap(rrApp,seedScenario)
sourceRRHDMap = roadrunnerHDMap with properties: Author: "" GeoReference: [0 0] GeographicBoundary: [2×3 double] Lanes: [50×1 roadrunner.hdmap.Lane] LaneBoundaries: [79×1 roadrunner.hdmap.LaneBoundary] LaneGroups: [0×1 roadrunner.hdmap.LaneGroup] LaneMarkings: [1×1 roadrunner.hdmap.LaneMarking] Junctions: [1×1 roadrunner.hdmap.Junction] BarrierTypes: [0×1 roadrunner.hdmap.BarrierType] Barriers: [0×1 roadrunner.hdmap.Barrier] SignTypes: [0×1 roadrunner.hdmap.SignType] Signs: [0×1 roadrunner.hdmap.Sign] StaticObjectTypes: [0×1 roadrunner.hdmap.StaticObjectType] StaticObjects: [0×1 roadrunner.hdmap.StaticObject]
The target scene
LargeFourWayIntersection.rrscene contains numerous lanes on each side of the road intersecting at a junction at the center of the scene.
Get all intersecting lane locations from the target scene, based on the seed scenario, by using the
helperGetLaneIntersections function. These intersecting lane locations are the potential locations to which to translocate the collision from the seed scenario.
[allLaneIntersections,targetRRHDMap] = helperGetLaneIntersections(rrApp,seedScenario,targetScene);
Remove the intersecting lane locations where translocation is not viable by using the
filteredLaneIntersections = helperFilterIntersection(sourceRRHDMap,targetRRHDMap,allLaneIntersections,egoData,targetData)
filteredLaneIntersections=50×5 table X Y Lane1 Lane2 AssociatedJunction _______ _______ _____ _____ __________________ 7.2141 -10.697 2 157 1 0.23794 -10.228 2 167 1 3.7272 -10.45 2 184 1 243.41 171.74 3 132 2 7.8098 -4.9072 4 157 1 6.8915 -4.3148 4 173 1 3.9544 -1.9057 4 177 1 9.2719 7.1449 147 157 1 -12.727 9.0921 147 158 1 2.3035 7.7481 147 167 1 -16.218 9.3303 147 178 1 5.7861 7.4374 147 184 1 7.5548 -7.2119 149 157 1 0.58156 -6.7417 149 167 1 -17.049 -5.8496 149 178 1 4.0695 -6.9646 149 184 1 ⋮
Explore the target RoadRunner HD Map scene, which now contains lanes.
targetRRHDMap = roadrunnerHDMap with properties: Author: "" GeoReference: [0 0] GeographicBoundary: [2×3 double] Lanes: [550×1 roadrunner.hdmap.Lane] LaneBoundaries: [710×1 roadrunner.hdmap.LaneBoundary] LaneGroups: [0×1 roadrunner.hdmap.LaneGroup] LaneMarkings: [4×1 roadrunner.hdmap.LaneMarking] Junctions: [2×1 roadrunner.hdmap.Junction] BarrierTypes: [0×1 roadrunner.hdmap.BarrierType] Barriers: [0×1 roadrunner.hdmap.Barrier] SignTypes: [0×1 roadrunner.hdmap.SignType] Signs: [0×1 roadrunner.hdmap.Sign] StaticObjectTypes: [0×1 roadrunner.hdmap.StaticObjectType] StaticObjects: [0×1 roadrunner.hdmap.StaticObject]
Visualize the target scene by using the
helperVisualizeLaneIntersection function. Specify the
laneIntersectionIndex to overlay the lane intersection, to which you have selected to translocate the collision, onto the target scene. The visualized plot has marked selected lane intersection point with red colour and other lane intersection points are marked with blue colour.
helperVisualizeLaneIntersections(targetRRHDMap,filteredLaneIntersections) laneIntersectionIndex = 1; hold on plot(filteredLaneIntersections.X(laneIntersectionIndex),filteredLaneIntersections.Y(laneIntersectionIndex),'r*') hold off
Translocate Collision from Seed Scenario to Target Scene
Compute ego and target actor waypoints for the target scene by using the
[newEgoWayPoints,newTargetWayPoints,targetRRHDMap] = helperTranslocate(targetRRHDMap,egoData,targetData,filteredLaneIntersections(laneIntersectionIndex,:));
Visualize the translocated collision for the target scene by using the
helperVisualizeTranslocate function. The visualization contains the trajectory of the ego and target actors in the seed and target scenarios. The trajectory of the ego actor is represented red and the trajectory of the target actor is represented blue. The start waypoints of the trajectories are represented with green markers and the end waypoints are represented with red markers.
Import Waypoints into RoadRunner
Write the translocated ego and target waypoints to CSV files to use to import them into RoadRunner.
Close the current RoadRunner instance.
Open RoadRunner using the specified path to your project.
rrApp = roadrunner(rrProjectPath);
Open the target scene and create a new scenario.
Import the waypoints you saved as CSV files into RoadRunner by using the
importScenario(rrApp,fullfile(pwd,"ego.csv"),"CSV Trajectory") importScenario(rrApp,fullfile(pwd,"target.csv"),"CSV Trajectory")
In this example, you have explored translocating a collision from a seed scenario to the target scene
LargeFourWayIntersection. You can also select the following target scenes for translocation by updating the
DownTownIntersection— Contains urban road intersections.
You can also add speed variations to the ego vehicle in the seed scenario and perform translocation.To add speed variations, first specify a new speed for the ego vehicle. For example:
newEgoSpeed = 25; % Units are in meters per second.
Then compute the wait times of the ego and target actors required to preserve their collision by using the
[egoData.WaitTime,targetData.WaitTime] = helperComputeWaitTime(ego,target,newEgoSpeed);
Finally, repeat the steps outlined in the Translocate Collision from Seed Scenario to Target Scene section.
Creates a RoadRunner HD Map for a scene that contains a RoadRunner scenario.
function map = helperGetMap(rrApp,sourceScenario) % This function is used to get the RoadRunner HD Map of a % RoadRunner Scenario. openScenario(rrApp,sourceScenario) rrSim = createSimulation(rrApp); rrRawMap = rrSim.getMap; map = matlabshared.roadrunner.createHDMap(rrRawMap.header,rrRawMap.map); end
Copyright 2022 The MathWorks, Inc.
- Overview of Scenario Variant Generation
- Generate Scenario Variants by Modifying Actor Dimensions
- Generate Scenario Variants for Testing AEB Pedestrian Systems
- Generate Scenario Variants for Testing ACC Systems
- Generate Scenario Variants for Lane Keep Assist Testing
- Generate Variants of ACC Target Cut-In Scenario