Main Content

Generate Scenario Variants for Lane Keep Assist Testing

This example shows you how to generate scenario variants from a seed scenario to use for lane keep assist (LKA) testing in accordance with the European New Car Assessment Programme (Euro NCAP®) test protocol standards.

Unintentional lane changes by vehicles are the major cause of accidents. Euro NCAP specifies the LKA test procedures to track the lane change behaviour of autonomous vehicles. Based on the LKA test protocols, you can create virtual driving scenarios from a seed scenario and perform safety assessments.

In this example, you:

  • Create a seed scenario specific to Euro NCAP test standards to be used for LKA testing.

  • Extract scenario descriptor from the seed scenario to use to create scenario variants.

  • Collect actor parameters for variations. The variation for the ego vehicle parameters includes actor waypoints, speed, and yaw values to be changed in the seed scenario.

  • Generate scenario variants from actor parameter variations.

  • Visualize the generated scenario variants next to the seed scenario.

  • Export the scenario variants to the ASAM OpenSCENARIO® file format.

Create Seed Scenario

Create seed scenarios for LKA testing by setting LKATestType to "LKASolidLane" for LKA testing with the solid lane. You can try the other two options discussed in Explore Other Scenarios section.

Specify the type of LKA test to create a seed scenario by using the helperCreateNCAPScenario function.

LKATestType = "LKASolidLane";
seedScenario = helperCreateNCAPScenario(LKATestType)
seedScenario = 
  drivingScenario with properties:

        SampleTime: 0.0100
          StopTime: Inf
    SimulationTime: 0
         IsRunning: 1
            Actors: [1x1 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 by using the getScenarioDescriptor function.

seedScenarioDescriptor = getScenarioDescriptor(seedScenario,Simulator="DrivingScenario");

Get LKA testing parameters as per Euro NCAP protocol standards.

LKAParams =  helperGetNCAPParameters("LKA");
countVariatPram = numel(LKAParams.lateralVelocity);

Perform Parameter Variations

Create a scenario variant object by using the HelperScenarioVariant class to store scenario parameter variations.

variantParams = HelperScenarioVariant(seedScenarioDescriptor)
variantParams = 
  HelperScenarioVariant with properties:

           ScenarioData: [1x1 struct]
       VariantGenerator: []
        ActorVariations: []
        SceneVariations: []
        EventVariations: []
    MethodForVariations: "WaitTime"

Specify the ActorID values of the ego actor. You can find the ActorID value and the name of an actor by inspecting the Actors property of the scenario object.

egoID = 1;

Create an actor variation object by using the HelperActorVariation class to store actor parameter variations.

actorParamVariation = HelperActorVariation;

Calculate these actor parameter variations for the seed scenario by using the helperLKATrajectoryInfo function. The parameters required for the calculation are constrained with LKA testing parameters LKAParams.

  • waypoints — Actor positions in the navigation coordinate system, in meters, returned as a P-by-3 matrix. P is the number of waypoints. Each waypoint represents the position of the actor in the form x y z.

  • speed — Ego actor speed in meters per second, returned as a P-element column vector. P is the number of waypoints.

  • yaw — Ego yaw angle in degrees, returned as a P-element column vector. P is the number of waypoints.

for iter = 1:countVariatPram
	[waypoints,speed,yaw] = helperLKATrajectoryInfo(seedScenario,LKAParams.lateralVelocity(iter),LKAParams.d1(iter),LKAParams.d2(iter),LKAParams.yaw(iter));

Store the calculated actor parameter variations to the scenario variant object.

variantParams.ActorVariations = actorParamVariation;

Generate Scenario Variants

Create a cell array of ScenarioDescriptor objects containing generated scenario variants by using the generateVariants method of HelperScenarioVariant class.

scenarioVariantDescriptors = generateVariants(variantParams);

Get a cell array of drivingScenario objects containing scenario variants from scenarioDescriptor objects by using the getScenario function.

numVariants = numel(scenarioVariantDescriptors);
variantScenario = cell(1,numVariants);
for iter = 1:numVariants
	variantScenario{iter} = getScenario(scenarioVariantDescriptors{iter},Simulator="DrivingScenario");

Visualize Generated Variants

Specify the figure heading and grid plot titles.

figHeading = "Variant for " + LKATestType;
gridPlotTitles = "";
for iter = 1:numVariants
    gridPlotTitles(iter) = "Lateral Velocity = " + num2str(LKAParams.lateralVelocity(iter)) + " m/s";

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


{"String":"Figure Variant Visualization contains objects of type subplottext, uipanel.","Tex":[],"LaTex":[]}


Export generated scenario variants to ASAM OpenSCENARIO file format V1.0.

for iter = 1:numVariants
    export(variantScenario{iter},"OpenSCENARIO","variantScenario_" + LKATestType + iter + ".xosc");

Explore Other Scenarios

In this example, you have explored the scenario variant generation for LKA testing with the solid lane. You can select one of the following three LKA tests by updating the LKATestType string variable. Then you create the disured seed scenario using helperCreateNCAPScenario. These options are in accordance with the Euro NCAP test protocol standards.

  • LKASolidLane - Performs solid lane tests.

  • LKADashedLane - Performs dashed lane tests.

  • LKANoLaneMarking - Performs test with no lane marking.

LKATestType = "LKADashedLane";

seedScenario = helperCreateNCAPScenario(LKATestType)


[1] European New Car Assessment Programme (Euro NCAP). Test Protocol – Lane Support Systems. Version 4.0. EuroNCAP, February 2022. Available from:

See Also


Related Topics