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 a major cause of accidents. The Euro NCAP specifies LKA test procedures to track the lane change behavior of autonomous vehicles. You can create a seed scenario based on the LKA test protocols, and then use the seed scenario to generate virtual driving scenarios to perform safety assessments.

In this example, you:

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

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

  • Collect actor parameters for generating variations. The parameters to vary in the seed scenario, includes actor waypoints, speed, and yaw.

  • Generate variants for input scenario.

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

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

Create Seed Scenario

Create a seed scenario for LKA solid lane test by specifying the type of LKA test to 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 the properties from the seed scenario and store these properties in a ScenarioDescriptor object by using the getScenarioDescriptor function.

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

Get the LKA testing parameters for the Euro NCAP protocol standards by using the helperGetNCAPParameters function.

LKAParams =  helperGetNCAPParameters("LKA");

Perform Parameter Variations

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

Specify the ActorID value of the ego actor.

egoID = 1;

Calculate the actor properties to vary for the seed scenario by using the helperLKATrajectoryInfo function. Use these calculated actor properties as an input to the varyActorProperties object function to add actor variations to the scenario.

  • 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 at that time in the form [x y z].

  • speed — Ego actor speed in meters per second, returned as a P-element column vector. Each row specifies the speed of the actor at the corresponding waypoint.

  • yaw — Ego yaw angle in radians, returned as a P-element column vector. Each row specifies the yaw angle of the actor at the corresponding waypoint.

numVariations = size(LKAParams.lateralVelocity,2);
variants = variationProperties.empty(numVariations,0);
for vCounter = 1:numVariations
    variants(vCounter) = variationProperties;
	[waypoints,speed,yaw] = helperLKATrajectoryInfo(seedScenario,LKAParams.lateralVelocity(vCounter), ...

Generate Scenario Variants

Create an array of ScenarioDescriptor objects containing generated scenario variants by using the generateVariants function.

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

Get a drivingScenario object containing scenario variants from scenarioDescriptor objects by using the getScenario function.

variantScenarios = getScenario(variantDescriptors,Simulator="DrivingScenario");

Visualize Generated Variants

Specify the figure heading and grid plot titles.

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

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

helperVisualizeVariants(seedScenario,variantScenarios,Title=figHeading, ...
    VariantTitles=variantTitles,GridDimension=[3 4],Mode="ChasePlotTopView",Waypoints="off");

Figure Variant Visualization contains objects of type subplottext, uipanel.


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

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

Explore Other Scenarios

You can visualize the scenario in a 3D simulation environment by following these steps:

  1. Enter this command to open the scenario in the Driving Scenario Designer app: drivingScenarioDesigner(variantScenarios(1));

  2. On the app toolstrip, select 3D Display > View Simulation in 3D Display.

  3. After the app opens the Simulation 3D Viewer window, click Run.

Visualization of LKA scenario in 3D simulation environment.

In this example, you have explored scenario variant generation for the LKA testing with a solid lane.

To generate scenario variants for another LKA testing scenario, change the LKATestType variable to the below mentioned test types, and then follow the rest of the procedure in this example to generate a seed scenario and its scenario variants. You can specify one of these options, which are in accordance with the Euro NCAP test protocol standards.

  • LKASolidLane — Solid Lane tests.

  • LKADashedLane — Dashed Lane tests.

  • LKANoLaneMarking — No Lane marking test.

For example, to generate a seed scenario for a dashed lane LKA test, use this code.

LKATestType = "LKADashedLane";

seedScenario = helperCreateNCAPScenario(LKATestType)


[1] European New Car Assessment Programme (Euro NCAP). Test Protocol – Lane Support Systems, Version 4.2. Euro NCAP, November 2022.

See Also


Related Topics