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 traveling 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
This example requires Automated Driving Toolbox™ Test Suite for Euro NCAP® Protocols support package. Check if the support package is installed.
helperCheckSupportPackageInstalled
In this example, you create a seed scenario to test the ACC CCRm Euro NCAP scenario. Start by specifying the type of ACC test scenario.
ACCTestType = "ACC_CCRm";
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
Specify the ActorID
value of the ego actor and target actor.
egoID = 1; targetID = 2;
Create an array of objects to store variations by using the variationProperties
object. Use the Euro NCAP parameters stored in ACCParams
variable for varying ego and target vehicle speed. Variations can be added using the varyActorProperties
and the varyCollisionProperties
object functions.
switch ACCTestType case {"ACC_CCRs", "ACC_CCRs_CurvedRoad"} numVariations = size(ACCParams.egoSpeed,2); variation = variationProperties.empty(numVariations,0); for vCounter = 1:numVariations variation(vCounter) = variationProperties; % Add speed variation for the ego vehicle varyActorProperties(variation(vCounter),egoID,Speed=ACCParams.egoSpeed(vCounter)); end case "ACC_CCRm" vCounter = 1; numVariations = size(ACCParams.egoSpeed,2)*size(ACCParams.targetSpeed,2); variation = variationProperties.empty(numVariations,0); for i = 1:size(ACCParams.targetSpeed,2) for j = 1:size(ACCParams.egoSpeed,2) variation(vCounter) = variationProperties; % Add multiple speed variations for both the ego and target vehicles varyActorProperties(variation(vCounter),egoID,Speed=ACCParams.egoSpeed(j)); varyActorProperties(variation(vCounter),targetID,Speed=ACCParams.targetSpeed(i)); varyCollisionProperties(variation(vCounter),egoID,targetID,variationType="Waypoints"); vCounter = vCounter + 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
Generate Scenario Variants
Create an array of variant ScenarioDescriptor
objects by using the generateVariants
function.
[variantDescriptors,~] = generateVariants(seedScenarioDescriptor,variation);
Get an array of drivingScenario
objects containing scenario variants from the ScenarioDescriptor
objects by using the getScenario
function.
variantScenarios = getScenario(variantDescriptors,Simulator="DrivingScenario");
Visualize Generated Variants
Get the visualization parameters by using the helperGetVisualizationProperties
function.
visualizationInfo = helperGetVisualizationProperties(ACCParams,ACCTestType);
Visualize the seed scenario and the generated scenario variants by using helperVisualizeVariants
helper function. You can notice the variations in the speed values of the ego vehicle.
helperVisualizeVariants(seedScenario,variantScenarios, ... Title=visualizationInfo.figureTitle,VariantTitles=visualizationInfo.variantTitles, ... SeedTitle=visualizationInfo.seedTitle,Waypoints=visualizationInfo.Waypoints, ... StopAtCollision="on",GridDimension=visualizationInfo.gridDimensions);
Export to ASAM OpenSCENARIO
Export the generated scenario variants to ASAM OpenSCENARIO file format 1.0.
for iter = 1:length(variantScenarios) export(variantScenarios(iter), "OpenSCENARIO", "variantScenario_" + ACCTestType + iter + ".xosc") end
Further Exploration
You can visualize the scenario in a 3D simulation environment by following these steps:
Enter this command to open the scenario in the Driving Scenario Designer app:
drivingScenarioDesigner(variantScenarios(1))
;On the app toolstrip, select 3D Display > View Simulation in 3D Display.
After the app opens the Simulation 3D Viewer window, click Run.
In this example, you have explored scenario variant generation for the 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 visualizationData = helperGetVisualizationProperties(ACCParams,ACCTestType) visualizationData.variantTitles = ""; visualizationData.Waypoints = "on"; switch ACCTestType case "ACC_CCRs" visualizationData.figureTitle = "Variant for ACC Car to Car Rear Stationary (CCRS) - Straight Road Test"; visualizationData.seedTitle = "Ego Speed 36.11 m/s Target Speed 0 m/s"; for i = 1:size(ACCParams.egoSpeed,2) visualizationData.variantTitles(i) = "Ego Speed " + round(ACCParams.egoSpeed(1,i),2) + " m/s Target Speed 0 m/s"; end visualizationData.gridDimensions = [8 1]; case "ACC_CCRs_CurvedRoad" visualizationData.figureTitle = "Variant for ACC Car to Car Rear Stationary (CCRS) - Curved Road Test"; visualizationData.seedTitle = "Ego Speed 36.11 m/s Target Speed 0 m/s"; for i = 1:size(ACCParams.egoSpeed,2) visualizationData.variantTitles(i) = "Ego Speed " + round(ACCParams.egoSpeed(1,i),2) + " m/s Target Speed 0 m/s"; end visualizationData.gridDimensions = [1 8]; visualizationData.Waypoints = "off"; case "ACC_CCRm" visualizationData.figureTitle = "Variant for ACC Car to Car Rear Moving (CCRM)"; visualizationData.seedTitle = "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) visualizationData.variantTitles(counter) = "Ego Speed " + round(ACCParams.egoSpeed(i),2) + " m/s Target Speed " + round(ACCParams.targetSpeed(j),2) + " m/s"; counter = counter + 1; end end visualizationData.gridDimensions = [7 1]; 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