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 scenario creation, this example explains how to translocate a collision from a seed scenario to a target scene using these steps.
In this example, you:
Configure MATLAB® settings to interact with RoadRunner Scenario.
Explore the seed scenario using RoadRunner.
Extract ego and target actor properties from the seed scenario.
Extract colliding ego and target actor waypoints and their travel distances.
Explore the target scene and fetch filtered locations to translocate the collision.
Translocate the collision from the seed scenario to the target scene, and visualize the collision.
Write translocated ego and target waypoints to CSV files and import them into RoadRunner.
Set Up Environment
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 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:\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.
seedScenario.rrscenario
—
RoadRunner seed scenario, with a collision.
LargeFourWayIntersection
—
Target scene, containing large four-way lanes, into which to translocate the collision.
Specify the filenames of the RoadRunner seed scenario and target scene.
seedScenario = "seedScenario.rrscenario"; targetScene = "LargeFourWayIntersection";
Copy the seedScenario
file to the RoadRunner project. To learn more about the RoadRunner environment, see RoadRunner Project and Scene System (RoadRunner).
copyfile(seedScenario,fullfile(rrProjectPath,"Scenarios"))
Explore Seed Scenario
Open the seed scenario seedScenario.rrscenario.
openScenario(rrApp,seedScenario)
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
Connect to the RoadRunner Scenario server from MATLAB for cosimulation using the createSimulation
function.
rrSim = createSimulation(rrApp);
Connection status: 1 Connected to RoadRunner Scenario server on localhost:53974, with client id {5d254e63-547f-4c26-b149-2efb24b3a401}
Extract properties from the seed scenario, and store these properties in a ScenarioDescriptor
object, descriptor
, by using the getScenarioDescriptor
function.
scenario.SimulatorInstance = rrApp;
scenario.SimulationInstance = rrSim;
descriptor = getScenarioDescriptor(scenario, Simulator="RoadRunner");
Specify the colliding actor IDs as egoID
and targetID
.
egoID = 1; targetID = 2;
Extract the properties for the actors specified by egoID
and targetID
by using the helperGetActorProfiles
function.
egoData = helperGetActorProfiles(descriptor,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(descriptor,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 getCollisionData
function.
c = getCollisionData(descriptor,Actor1ID=egoID,Actor2ID=targetID);
Extract the precollision actor waypoints for the ego and target vehicles by using the helperIntersectWaypoints
function.
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 of the seed scenario by specifying the roadrunner object as an input to the helperGetMap
function.
sourceRRHDMap = helperGetMap(rrApp)
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: [29×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: [1×1 roadrunner.hdmap.SignType] Signs: [4×1 roadrunner.hdmap.Sign] StaticObjectTypes: [2×1 roadrunner.hdmap.StaticObjectType] StaticObjects: [6×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(rrProjectPath,seedScenario,targetScene);
Explore the target RoadRunner HD Map scene, which now contains lanes.
targetRRHDMap
targetRRHDMap = roadrunnerHDMap with properties: Author: "" GeoReference: [0 0] GeographicBoundary: [2×3 double] Lanes: [554×1 roadrunner.hdmap.Lane] LaneBoundaries: [714×1 roadrunner.hdmap.LaneBoundary] LaneGroups: [102×1 roadrunner.hdmap.LaneGroup] LaneMarkings: [4×1 roadrunner.hdmap.LaneMarking] Junctions: [2×1 roadrunner.hdmap.Junction] BarrierTypes: [2×1 roadrunner.hdmap.BarrierType] Barriers: [5×1 roadrunner.hdmap.Barrier] SignTypes: [14×1 roadrunner.hdmap.SignType] Signs: [46×1 roadrunner.hdmap.Sign] StaticObjectTypes: [33×1 roadrunner.hdmap.StaticObjectType] StaticObjects: [729×1 roadrunner.hdmap.StaticObject]
Remove the intersecting lane locations where translocation is not viable by using the helperFilterintersection
function.
filteredLaneIntersections = helperFilterIntersection(sourceRRHDMap,targetRRHDMap,allLaneIntersections,egoData,targetData); disp(filteredLaneIntersections)
X Y Lane1 Lane2 AssociatedJunction _________ _______ _____ _____ __________________ 7.2142 -10.697 2 157 1 0.23798 -10.228 2 167 1 3.7272 -10.45 2 184 1 243.41 171.74 3 132 2 7.8102 -4.9047 4 157 1 6.8965 -4.3152 4 173 1 3.9573 -1.9047 4 177 1 9.2719 7.1449 147 157 1 -12.727 9.0921 147 158 1 2.3035 7.748 147 167 1 -16.218 9.3302 147 178 1 5.7862 7.4374 147 184 1 7.5549 -7.2119 149 157 1 0.58165 -6.7417 149 167 1 -17.049 -5.8496 149 178 1 4.0696 -6.9646 149 184 1 -13.011 4.9045 150 158 1 -4.4278 -9.8617 150 173 1 -14.001 5.6777 150 174 1 -16.369 7.1882 150 178 1 -10.415 2.3496 150 430 1 7.4056 -8.6838 157 172 1 8.8585 3.6671 157 174 1 6.9208 -14.185 157 175 1 9.6608 10.625 157 554 1 -13.259 0.51033 158 166 1 -12.967 5.604 158 174 1 -13.855 -12.999 158 175 1 -13.234 0.97577 158 430 1 -12.455 12.578 158 554 1 -16.728 3.3885 165 166 1 -11.889 5.5231 165 174 1 -16.605 3.4321 165 178 1 -7.126 -12.262 166 173 1 -8.0794 -8.5824 166 177 1 -13.572 0.83149 166 430 1 0.58577 -6.7037 167 173 1 1.8932 4.2732 167 174 1 -0.057668 -13.717 167 175 1 2.6851 11.226 167 554 1 2.9119 -5.6422 172 173 1 4.1095 -6.5984 172 184 1 -6.8783 12.123 172 554 1 -16.459 5.841 174 178 1 5.3742 3.9606 174 184 1 -17.352 -12.843 175 178 1 -15.947 12.818 178 554 1 6.1703 10.917 184 554 1
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 helperTranslocate
function.
[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.
helperVisualizeTranslocate(sourceRRHDMap,egoData.WayPoints,targetData.WayPoints,targetRRHDMap,newEgoWayPoints,newTargetWayPoints)
Import Waypoints into RoadRunner
Write the translocated ego and target waypoints to CSV files to use to import them into RoadRunner.
writetable(newEgoWayPoints,"ego.csv") writetable(newTargetWayPoints,"target.csv")
Open RoadRunner using the specified path to your project.
rrApp = roadrunner(rrProjectPath);
Open the target scene and create a new scenario.
openScene(rrApp,targetScene) newScenario(rrApp)
Import the waypoints you saved as CSV files into RoadRunner by using the importScenario
function.
importScenario(rrApp,fullfile(pwd,"ego.csv"),"CSV Trajectory") importScenario(rrApp,fullfile(pwd,"target.csv"),"CSV Trajectory")
Further Exploration
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 targetScene
variable.
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 helperComputeWaitTime
function.
[egoData.WaitTime,targetData.WaitTime] = helperComputeWaitTime(egoData,targetData,newEgoSpeed);
[newEgoWayPoints,newTargetWayPoints,targetRRHDMap] = helperTranslocate(targetRRHDMap,egoData,targetData,filteredLaneIntersections(laneIntersectionIndex,:),newEgoSpeed);
Finally, repeat the steps outlined in the Import Waypoints into RoadRunner section.
Helper Function
Creates a RoadRunner HD Map for a scene that contains a RoadRunner scenario.
function map = helperGetMap(rrApp) % This function is used to get the RoadRunner HD Map of a % RoadRunner Scenario. rrSim = createSimulation(rrApp); rrRawMap = rrSim.getMap; map = matlabshared.roadrunner.createHDMap(rrRawMap.header,rrRawMap.map); close(rrApp); end
See Also
Functions
Related Topics
- Get Started with Euro NCAP Test Suite
- Generate RoadRunner Scenario Variants by Modifying Actor Assets
- 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