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 towards the stationary target vehicle.
Car-to-car rear moving (CCRm) — The ego vehicle travels forward towards a target vehicle, The target vehicle is also travelling at a constant speed.
In this example, the frontal structure of the ego vehicle will try to strike the rear structure of the target vehicle. You vary the speeds of the ego and target vehicles to generate scenario variants. However, the collision point for each scenario variant remains the same as the seed scenario.
This example generates scenario variants for testing ACC systems using these steps:
Create a seed scenario.
Extract scenario descriptor from the seed scenario.
Define desired parameters for variations.
Generate scenario variants.
Visualize scenario variants
Export the scenario variants to the ASAM OpenSCENARIO® file format.
Create Seed Scenario
This example creates a seed scenario to test CCRm Euro NCAP scenario. Specify the type of ACC scenario.
ACCTestType = "ACC_CCRm";
You can try stationary target as in CCRs Euro NCAP scenario as discussed in Further Exploration. You set ACCTestType
variable as "ACC_CCRs"
value.
In the seed scenario, an ego vehicle travels forward towards a target vehicle and then both collid. Each type of seed scenario specifies dimensions, positions, trajectories, and speed values of actors per 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: [1x2 driving.scenario.Vehicle] Barriers: [0x0 driving.scenario.Barrier] ParkingLots: [0x0 driving.scenario.ParkingLot]
Extract Parameters for Scenario Variant Generation
Extract 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 EURO NCAP parameters for the specified type of ACC scenario using the helperGetNCAPParameters
function.
ACCParams = helperGetNCAPParameters(ACCTestType);
Perform Parameter Variations
Create a HelperScenarioVariant
object, which is a parent object for holding information about all parameter variations. Then, vary the parameters of actors and events, using the HelperActorVariation
object and HelperEventVariation
object, respectively, each of these objects has its children objects to vary specific parameters.
variantParams = HelperScenarioVariant(seedScenarioDescriptor);
Specify the ActorID values of the ego and target actors. You can find the ActorID value and the name of an actor by inspecting the Actors property of the scenario object.
egoID = 1; targetID = 2;
Create an actor variation object by using the HelperActorVariation
class to store actor parameter variations.
actorParamVariation = HelperActorVariation;
Set these actor parameter variations for the seed scenario as required to conduct ACC testing, which are stored in ACCParams
. You can set desired Ego and target actor speed in meters per second. Each addSpeedVariation
or addMultiVariation
results in a scenario variant.
switch ACCTestType case "ACC_CCRs" for i = 1:size(ACCParams.egoSpeed,2) % Add speed variation for Ego addSpeedVariation(actorParamVariation,{egoID},{ACCParams.egoSpeed(1,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 Ego and target addMultiVariation(actorParamVariation,{egoID,targetID},Speed={{ACCParams.egoSpeed(i)},{ACCParams.targetSpeed(j)}}); end end otherwise error("Invalid type of seed scenario. Seed scenario must be ACC_CCRs or ACC_CCRm type.") end variantParams.ActorVariations = actorParamVariation;
Create an event variation object by using the HelperEventVariation
class. It stores collision event parameter variation passed by addCollisionInLine
method of HelperEventVariation
class. This is needed to recreate collision at the same point in all scenario variants.
eventParamVariation = HelperEventVariation; if ACCTestType == "ACC_CCRm" addCollisionInLine(eventParamVariation,variantParams,egoID,targetID); variantParams.EventVariations = eventParamVariation; end
Generate Scenario Variants
Then, generate variants using the generateVariants
function of the HelperScenarioVariant
object. The function returns generated ScenarioDescriptor
objects.
scenarioVariantDescriptors = generateVariants(variantParams);
Get a cell array of scenario objects from ScenarioDescriptor
objects using the getScenario
function.
numVariants=numel(scenarioVariantDescriptors); variantScenario = cell(1,numVariants); warning("off","driving:scenario:SpeedsNotAccurate"); for iter = 1:numVariants variantScenario{iter} = getScenario(scenarioVariantDescriptors{iter},Simulator="DrivingScenario"); end warning("on","driving:scenario:SpeedsNotAccurate");
Visualize Generated Variants
Use the helperVisualizeVariants function to simulate and visualize generated scenario variants. The function plots seed scenario and generated variants in a grid manner. Specify the size of the grid using the row and column arguments.
[heading,gridPlotTitles,seedTitle] = helperSetPlotHeadingData(ACCParams,ACCTestType); helperVisualizeVariants(seedScenario,variantScenario,... heading,gridPlotTitles,SeedTitle=seedTitle,Mode="StandardFit",Row=3,Column=3,Legend="off",Waypoints="on");
Export to ASAM OpenSCENARIO
Export generated scenario variants to ASAM OpenSCENARIO file format V1.0.
warning("off","driving:scenario:ExportOpenScenarioODWarning"); for iter = 1:numVariants export(variantScenario{iter},"OpenSCENARIO","variantScenario_" + ACCTestType + iter + ".xosc"); end warning("on","driving:scenario:ExportOpenScenarioODWarning");
Further Exploration
In this example, you have explored the scenario variant generation for ACC testing with moving target. You can select stationary target scenario by updating the ACCTestType
string variable to "ACC_CCRs"
. Then you create the desired seed scenario using helperCreateNCAPScenario
. These options are in accordance with the Euro NCAP test protocol standards.
ACC_CCRs
- Performs ACC testing with stationary target.ACC_CCRm
- Performs ACC testing with moving target.
ACCTestType = "ACC_CCRs";
seedScenario = helperCreateNCAPScenario(ACCTestType)
Helper Functions
helperSetPlotHeadingData
This function generates the figure heading, individual titles for the grid plots, and title for seed scenario, based on ACC NCAP parameters and selected ACC test type.
function [heading,gridPlotTitles,seedTitle] = helperSetPlotHeadingData(ACCParams,ACCTestType) gridPlotTitles = ""; switch ACCTestType case "ACC_CCRs" heading = "Variant for ACC Car to Car Rear Stationary (CCRS)"; 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_CCRm" heading = "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 seed scenario. Seed scenario must be ACC_CCRs or ACC_CCRm type.") end end
References
[1] European New Car Assessment Programme (Euro NCAP). Test & Assessment Protocol – Highway Assist Systems. Version 1.0. EuroNCAP, September 2020. Available from: https://cdn.euroncap.com/media/58813/euro-ncap-ad-test-and-assessment-protocol-v10.pdf