Generate Variants of ACC Target Cut-In Scenario
This example shows how to generate scenario variants from a seed scenario in which a target vehicle cuts into the ego lane. Using this example, you can test the adaptive cruise control (ACC) application.
Create Seed Scenario
In this example, you create a seed scenario containing the ego vehicle and a target vehicle in which the target vehicle cuts into the ego lane. The seed scenario specifies the positions, dimensions, speed values, and trajectories of both vehicles per the European New Car Assessment Programme (Euro NCAP®) test protocols. This example assumes that the ego vehicle collides with the target actor in the seed scenario. You generate variants of a seed scenario by varying the ego speed but keep the collision point constant.
Create a seed scenario for ACC target cut-in using the helperCreateNCAPScenario
function.
ACCTestType = "ACCTargetCutIn";
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]
Set Up Parameters for Scenario Variant Generation
Get the predefined parameters for the Euro NCAP ACC cut-in test scenario by using the helperGetNCAPParameters
function. The function retrieves data for one variation that complies with the parameters.
ACCParams = helperGetNCAPParameters(ACCTestType)
ACCParams = struct with fields:
scenarioName: "ACCTargetCutIn"
radiusOfTurning: 250
changeLength: 60
egoSpeed: 33.3333
targetSpeed: 19.4444
timeToCollision: 1.5000
Specify the actor identifiers for the ego and target actors. You can find the ActorID
and the name of an actor by inspecting the Actors
property of the seed scenario object.
actorOfInterest.egoID = 1;
actorOfInterest.targetID = 2;
actorOfInterest.leadID = 3; % Needed for ACCLeadCutOut scenario
Generate Scenario Variants
Create a ScenarioDescriptor
object that contains a scenario variant by using the helperGenerateVariant
function. Additionally, this helper function returns the title to use when visualizing the variant scenario. The function generates the scenario variant by varying the actor and event parameters of the seed scenario.
[variantDescriptors,variantTitles] = helperGenerateVariant(ACCParams.scenarioName,seedScenario,ACCParams,actorOfInterest);
Get a drivingScenario
object that contains a scenario variant from the ScenarioDescriptor
object by using the getScenario
function.
variantScenarios = getScenario(variantDescriptors,Simulator="DrivingScenario");
Visualize Generated Variant
Get the title of the figure, sub-plot title for the seed scenario and grid dimensions using the helperGetVisualizationProperties
function.
[figureTitle,seedTitle] = helperGetVisualizationProperties(ACCParams.scenarioName);
Visualize the seed scenario and the generated variants by using the helperVisualizeVariants
function.
helperVisualizeVariants(seedScenario,variantScenarios,Title=figureTitle, ... VariantTitles=variantTitles,SeedTitle=seedTitle, ... Waypoints="off",StopAtCollision="on");
Export to ASAM OpenSCENARIO
Export the generated scenario variant 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 the scenario variant generation for the ACC testing wherein which a target vehicle cuts into the ego lane.
You can use the same steps to generate variants for other types of seed scenarios by specifying different values of the ACCTestType
variable. This example supports these additional values for the ACCTestType
variable:
ACCTargetCutInModified
— Generate five sets of scenario variants of the ACC target cut-in scenario.ACCLeadCutOut
— Generate scenario variants of the ACC cut-out scenario in which a lead vehicle cuts out of the ego lane to avoid collision with a stationary target vehicle.
For example, to configure the example to generate variants for the ACC cut-out scenario, enter this code:
ACCTestType = "ACCLeadCutOut";
seedScenario = helperCreateNCAPScenario(ACCTestType);
Helper Functions
helperGetVisualizationProperties
This function generates the figure heading, title for the seed scenario, and grid dimensions based on ACC NCAP parameters and selected ACC test type.
function [figureTitle,seedTitle] = helperGetVisualizationProperties(ACCTestType) switch ACCTestType case {"ACCTargetCutIn","ACCTargetCutInModified"} figureTitle = "Variation for ACC Target Cut-In"; seedTitle = "Ego Speed 13.89 m/s, Target Speed 2.78 m/s"; case "ACCLeadCutOut" figureTitle = "Variation for ACC Lead Cut-Out"; seedTitle = "Ego Speed 19.44 m/s, Target Speed 0 m/s, Lead Speed 13.89 m/s"; otherwise error("Invalid type of seed scenario. Seed scenario must be ACC_Cut-In or ACC_Cut-Out type.") end end
References
[1] European New Car Assessment Programme (Euro NCAP). Assisted Driving — Highway Assist Systems Test & Assessment Protocol, Version 1.0. Euro NCAP, September 2020. https://cdn.euroncap.com/media/58813/euro-ncap-ad-test-and-assessment-protocol-v10.pdf