Generate Scenario Variants for Testing ACC Systems
This example shows how to generate variants of a seed scenario to test adaptive cruise control (ACC) systems per the European New Car Assessment (Euro NCAP®) test protocols. Using this example. You can generate variants for these types of Euro NCAP test scenarios:
Car-to-car rear stationary (CCRs) — The ego vehicle travels forward toward a stationary target vehicle.
Car-to-car rear moving (CCRm) — The ego vehicle travels forward toward a target vehicle, The target vehicle is travelling in the same direction as the ego vehicle at a constant speed.
In these scenarios, without intervention, the front of the ego vehicle collides with the rear of the target vehicle. Use these scenarios to model whether your ACC system can adjust the speed of the ego vehicle to maintain distance from the target vehicle and avoid a collision. To generate scenario variants, you must vary the speeds of the ego and target vehicles. However, the collision point for each scenario variant remains the same as in the seed scenario.
This example generates scenario variants for testing ACC systems using these steps:
Create a seed scenario.
Extract a scenario descriptor from the seed scenario and use it to create scenario variants.
Perform parameter variations.
Generate scenario variants.
Visualize scenario variants.
Export the scenario variants to the ASAM OpenSCENARIO® file format.
Create Seed Scenario
In this example, you create a seed scenario to test the CCRm Euro NCAP scenario. Start by specifying the type of ACC test scenario.
ACCTestType = "ACC_CCRs";
In the seed scenario, an ego vehicle travels forward toward a moving target vehicle, and then collides with it from behind. The seed scenario specifies the dimensions, positions, trajectories, and speed values of actors based on the EURO NCAP test protocols.
Create a seed scenario using the helperCreateNCAPScenario
function.
seedScenario = helperCreateNCAPScenario(ACCTestType)
seedScenario = drivingScenario with properties: SampleTime: 0.0100 StopTime: Inf SimulationTime: 0 IsRunning: 1 Actors: [1×2 driving.scenario.Vehicle] Barriers: [0×0 driving.scenario.Barrier] ParkingLots: [0×0 driving.scenario.ParkingLot]
Extract Parameters for Scenario Variant Generation
Extract the properties from the seed scenario and store these properties in a ScenarioDescriptor
object using the getScenarioDescriptor
function.
seedScenarioDescriptor = getScenarioDescriptor(seedScenario,Simulator="DrivingScenario")
seedScenarioDescriptor = ScenarioDescriptor with properties: status: "DescriptorCreated"
Get the EURO NCAP prescribed parameter values relevant to the specified type of ACC scenario by using the helperGetNCAPParameters
function.
ACCParams = helperGetNCAPParameters(ACCTestType);
Perform Parameter Variations
Create a scenario variant object by using the HelperScenarioVariant
object to store scenario parameter variations.
variantParams = HelperScenarioVariant(seedScenarioDescriptor);
Specify the ActorID
value of the ego actor and target actor.
egoID = 1; targetID = 2;
Specify the ego and target actor speed in meters per second and add speed variations for these actors using the Euro NCAP parameters stored in ACCParams
variable.
switch ACCTestType case {"ACC_CCRs","ACC_CCRs_CurvedRoad"} for i = 1:size(ACCParams.egoSpeed,2) % Add speed variation for the ego vehicle addSpeedVariation(variantParams,egoID,struct("egoSpeed",ACCParams.egoSpeed(i))); end case "ACC_CCRm" for i = 1:size(ACCParams.egoSpeed,2) for j = 1:size(ACCParams.targetSpeed,2) % Add multiple speed variations for both the ego and target vehicles addActorMultiVariation(variantParams,[egoID,targetID],Speed=struct("egoSpeed",ACCParams.egoSpeed(i),"targetSpeed",ACCParams.targetSpeed(j))); end end otherwise error("Invalid type of ACC test. ACC test must be 'ACC_CCRs' or 'ACC_CCRs_CurvedRoad' or 'ACC_CCRm' type.") end
Get collision information between the ego and target actors using the getCollisionData
function. Use this information to keep the same collision point in all scenario variants.
if ACCTestType == "ACC_CCRm" collisionsInScenario = getCollisionData(seedScenarioDescriptor,Actor1ID=egoID,Actor2ID=targetID); createCollisionVariant(variantParams,collisionsInScenario.Collision); end
Generate Scenario Variants
Generate scenario variants by using the generateVariants
object function of the HelperScenarioVariant
object. The function returns generated ScenarioDescriptor
objects.
scenarioVariantDescriptors = generateVariants(variantParams);
Get a array of drivingScenario
objects from scenarioVariantDescriptors
by using the getScenario
function.
numVariants = numel(scenarioVariantDescriptors); variantScenario = repelem(drivingScenario,numVariants); for iter = 1:numVariants variantScenario(iter) = getScenario(scenarioVariantDescriptors(iter),Simulator="DrivingScenario"); end
Visualize Generated Variants
Use the helperVisualizeVariants
function to simulate and visualize the generated scenario variants. The function plots the seed scenario and generated variants in a grid. Specify the size of the grid using the Row
and Column
arguments.
[figureTitle,gridPlotTitles,seedTitle,VisualizationMode] = helperGetVisualizationProperties(ACCParams,ACCTestType); helperVisualizeVariants(seedScenario,variantScenario,FigureTitle=figureTitle,GridPlotTitles=gridPlotTitles, ... SeedTitle=seedTitle,Mode=VisualizationMode,Row=3,Column=3,Waypoints="on");
Export to ASAM OpenSCENARIO
Export the generated scenario variants to ASAM OpenSCENARIO file format 1.0.
for iter = 1:numVariants export(variantScenario(iter),"OpenSCENARIO","variantScenario_" + ACCTestType + iter + ".xosc") end
Further Exploration
In this example, you have explored scenario variant generation for ACC testing with a moving target. To generate variants for a stationary target scenario, specify the value of ACCTestType
as "ACC_CCRs
" or "ACC_CCRs_CurvedRoad
". Then, follow the rest of the procedure in this example to generate a seed scenario and scenario variants. These seed scenario options are in accordance with the Euro NCAP test protocol standards.
ACC_CCRs
—ACC_CCRs_CurvedRoad
— ACC testing with a stationary target on a curved road.ACC_CCRm
— ACC testing with a moving target on a straight road.
For example, to generate a seed scenario for a stationary target ACC testing scenario, enter this code.
ACCTestType = "ACC_CCRs";
seedScenario = helperCreateNCAPScenario(ACCTestType)
Helper Functions
helperGetVisualizationProperties
This function generates a figure heading, individual titles for grid plots, title for the seed scenario and the recommended mode for visualization, based on Euro NCAP parameters and the selected ACC test type.
function [figureTitle,gridPlotTitles,seedTitle,VisualizationMode] = helperGetVisualizationProperties(ACCParams,ACCTestType) gridPlotTitles = ""; VisualizationMode = "StandardFit"; switch ACCTestType case "ACC_CCRs" figureTitle = "Variant for ACC Car to Car Rear Stationary (CCRS) - Straight Road Test"; seedTitle = "Seed Scenario: Ego Speed 36.11 m/s Target Speed 0 m/s"; for i = 1:size(ACCParams.egoSpeed,2) gridPlotTitles(i) = "Ego Speed " + round(ACCParams.egoSpeed(1,i),2) + " m/s Target Speed 0 m/s"; end case "ACC_CCRs_CurvedRoad" figureTitle = "Variant for ACC Car to Car Rear Stationary (CCRS) - Curved Road Test"; seedTitle = "Seed Scenario: Ego Speed 36.11 m/s Target Speed 0 m/s"; for i = 1:size(ACCParams.egoSpeed,2) gridPlotTitles(i) = "Ego Speed " + round(ACCParams.egoSpeed(1,i),2) + " m/s Target Speed 0 m/s"; end VisualizationMode = "ChasePlotTopView"; case "ACC_CCRm" figureTitle = "Variant for ACC Car to Car Rear Moving (CCRM)"; seedTitle = "Seed Scenario: Ego Speed 36.11 m/s Target Speed 5.55 m/s"; counter = 1; for i = 1:size(ACCParams.egoSpeed,2) for j = 1:size(ACCParams.targetSpeed,2) gridPlotTitles(counter) = "Ego Speed " + round(ACCParams.egoSpeed(i),2) + " m/s Target Speed " + round(ACCParams.targetSpeed(j),2) + " m/s"; counter = counter + 1; end end otherwise error("Invalid type of ACC test. ACC test must be 'ACC_CCRs' or 'ACC_CCRs_CurvedRoad' or 'ACC_CCRm' type.") end end
References
[1] European New Car Assessment Programme (Euro NCAP). Assisted Driving — Highway Assist Systems — Test & Assessment Protocol, Version 1.1. Euro NCAP, Implementation 2023. https://cdn.euroncap.com/media/75441/euro-ncap-ad-test-and-assessment-protocol-v11.pdf