Main Content

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

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: 10.0000e-003
          StopTime: Inf
    SimulationTime: 0.0000e+000
         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.egoSpeed,2)
            for j = 1:size(ACCParams.targetSpeed,2)
                variation(vCounter) = variationProperties;
                % Add multiple speed variations for both the ego and target vehicles
                varyActorProperties(variation(vCounter),egoID,Speed=ACCParams.egoSpeed(i));
                varyActorProperties(variation(vCounter),targetID,Speed=ACCParams.targetSpeed(j));
                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

Generate variants of the seed scenario by using the generateVariants function. The function generates a scenario variant descriptor for each variation specified in the input object. The output of the function is variantDescriptors which contains the generated ScenarioDescriptor of the variations.

[variantDescriptors,~] = generateVariants(seedScenarioDescriptor,variation);

Get an array of drivingScenario objects from variantDescriptors 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 Variants

Using helperGetVisualizationProperties get the visualization parameters by passing the ACCParams and ACCTestType.

visualizationInfo = helperGetVisualizationProperties(ACCParams,ACCTestType);

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 arguments to customize the plot as per your requirements using visualizationInfo.

helperVisualizeVariants(seedScenario,variantScenarios, ...
    FigureTitle=visualizationInfo.figureTitle,GridPlotTitles=visualizationInfo.gridTitles, ...
    SeedTitle=visualizationInfo.seedTitle,Waypoints=visualizationInfo.Waypoints, ...
    Row=visualizationInfo.Row,Column=visualizationInfo.Column,StopAtCollision="on");

Export to ASAM OpenSCENARIO

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

for iter = 1:numVariants
    export(variantScenarios(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 testing with a stationary target on a straight road.

  • 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.gridTitles = "";
visualizationData.Waypoints = "on";
switch ACCTestType
    case "ACC_CCRs"
        visualizationData.figureTitle = "Variant for ACC Car to Car Rear Stationary (CCRS) - Straight Road Test";
        visualizationData.seedTitle = "Seed Scenario: Ego Speed 36.11 m/s Target Speed 0 m/s";
        for i = 1:size(ACCParams.egoSpeed,2)
            visualizationData.gridTitles(i) = "Ego Speed " + round(ACCParams.egoSpeed(1,i),2) + " m/s Target Speed 0 m/s";
        end
        visualizationData.Row = 8;
        visualizationData.Column = 1;
    case "ACC_CCRs_CurvedRoad"
        visualizationData.figureTitle = "Variant for ACC Car to Car Rear Stationary (CCRS) - Curved Road Test";
        visualizationData.seedTitle = "Seed Scenario: Ego Speed 36.11 m/s Target Speed 0 m/s";
        for i = 1:size(ACCParams.egoSpeed,2)
            visualizationData.gridTitles(i) = "Ego Speed " + round(ACCParams.egoSpeed(1,i),2) + " m/s Target Speed 0 m/s";
        end
        visualizationData.Row = 1;
        visualizationData.Column = 8;
        visualizationData.Waypoints = "off";
    case "ACC_CCRm"
        visualizationData.figureTitle = "Variant for ACC Car to Car Rear Moving (CCRM)";
        visualizationData.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)
                visualizationData.gridTitles(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.Row = 7;
        visualizationData.Column = 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

See Also

Functions

Related Topics