Main Content

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: [1×2 driving.scenario.Vehicle]
          Barriers: [0×0 driving.scenario.Barrier]
       ParkingLots: [0×0 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,gridPlotTitles] = helperGenerateVariant(ACCParams.scenarioName,seedScenario,ACCParams,actorOfInterest);

Get a drivingScenario object that contains a scenario variant from the ScenarioDescriptor object by using the getScenario function.

numVariants = size(variantDescriptors,2);
variantScenarios = repelem(drivingScenario,numVariants);
for iter = 1:numVariants
    variantScenarios(iter) = getScenario(variantDescriptors(iter),Simulator="DrivingScenario");
end

Visualize Generated Variant

Visualize the seed scenario and the generated variant by using the helperVisualizeVariants function.

[figureTitle,seedTitle,row,column] = helperGetVisualizationProperties(ACCParams.scenarioName);

helperVisualizeVariants(seedScenario,variantScenarios,FigureTitle=figureTitle, ...
    GridPlotTitles=gridPlotTitles,SeedTitle=seedTitle,Row=row,Column=column, ...
    Waypoints="off",StopAtCollision="on");

Export to ASAM OpenSCENARIO

Export the generated scenario variant to ASAM OpenSCENARIO file format 1.0.

for iter = 1:numVariants
    export(variantScenarios(iter),"OpenSCENARIO","VariantScenario" + ACCTestType + iter + ".xosc")
end

Explore Other Scenarios

In this example, you have explored the scenario variant generation for 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 row and column based on ACC NCAP parameters and selected ACC test type.

function [figureTitle,seedTitle,row,column] =  helperGetVisualizationProperties(ACCTestType)
    switch ACCTestType
        case "ACCTargetCutIn"
            figureTitle = "Variation for ACC Target Cut-In";
            seedTitle = "Seed Scenario: Ego Speed 13.89 m/s Target Speed 2.78 m/s";
            row = 1;
            column = 2;
          
        case "ACCTargetCutInModified"
            figureTitle = "Variation for ACC Target Cut-In";
            seedTitle = "Seed Scenario: Ego Speed 13.89 m/s Target Speed 2.78 m/s";
            row = 1;
            column = 6;
    
        case "ACCLeadCutOut"
            figureTitle = "Variation for ACC Lead Cut-Out";
            seedTitle = "Seed Scenario: Ego Speed 19.44 m/s Target Speed 0 m/s Lead Speed 13.89 m/s";
            row = 1;
            column = 2;
           
        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

See Also

Functions

Related Topics