Main Content

Generate Scenario Variants Using Excel Spreadsheets

This example shows how to generate variants of a seed scenario by using variation parameters such as speed, dimension, waypoint, yaw, and collision, which you specify as tables in Microsoft® Excel® spreadsheet files.

You can generate scenario variants by varying the parameters of a seed scenario, enabling you to perform safety assessments of various automated driving applications. However, manual creation of scenario variants is not scalable, and is prone to human error. Unlike manual creation, this example explains the automatic creation of scenario variants using variation parameters you specify as tables in Excel files. Each row of the table corresponds to a distinct variant, and each column describes a variation parameter of that variant.

In this example, you:

  • Create a seed scenario and extract its parameters.

  • Define parameter variations using an Excel spreadsheet.

  • Create variation properties objects using data from Excel.

  • Generate the scenario variants and visualize them.

Create Seed Scenario and Extract Parameters

In this example, you create a seed scenario where an ego vehicle travels forward toward a moving target vehicle, and then collides with it from behind.

Create a seed scenario by using the helperCreateSeedScenario helper function.

seedScenario = helperCreateSeedScenario;

Extract the properties from the seed scenario and store these properties in a ScenarioDescriptor object by using the getScenarioDescriptor function.

seedScenarioDescriptor = getScenarioDescriptor(seedScenario);

Define Parameter Variations Using Excel Spreadsheet

This example uses a table in an Excel sheet to define variation parameters. Each row in the table represents a unique set of scenario parameters for generating a variant. You must specify the names of one or more of these parameters in the first row of the table in the Excel sheet.

variationParameterTable.png

Note: You can adjust which parameter values you specify in the table, to meet your specific requirements for generating scenario variants.

Create Variation Properties Object Using Data from Excel

Specify the name of the Excel file containing your variation parameters to create a table from it. For this example, use the VariationParameters.xlsx file.

The table you extract from the VariationParameters.xlsx Excel file contains these six rows, specifying parameters to create six scenario variants.

  • The first row specifies ego and target speed variation parameters, and indicates specifies them as colliding actors.

  • The second and third rows specify ego and target speed variation parameters along with variations in the point of collision relative to the collision side of the ego actor and of both actors, respectively.

  • The fourth row specifies ego and target speed and dimension variation parameters, as well as indicating not to maintain collision consistency.

  • The fifth and sixth rows specify ego and target speed variation parameters, as well as target waypoint variation parameters.

filename = "VariationParameters";
parameterTable = readtable(strcat(filename,".xlsx"),Format="auto");
disp(parameterTable);
    Ego_Speed    Target_Speed    Ego_Dimension    Target_Dimension                                                                                       Target_Waypoints                                                                                       CollisionConsistencyFlag    CollisionFraction
    _________    ____________    _____________    ________________    ______________________________________________________________________________________________________________________________________________________________________________________    ________________________    _________________

        60            40          {0×0 char }       {0×0 char }       {0×0 char                                                                                                                                                                            }           {0×0 char}             {0×0 char   }  
        80            40          {0×0 char }       {0×0 char }       {0×0 char                                                                                                                                                                            }           {0×0 char}             {'[0.5 0.5]'}  
        90            20          {0×0 char }       {0×0 char }       {0×0 char                                                                                                                                                                            }           {0×0 char}             {'[0.9 0.1]'}  
        70            30          {'[6 4 3]'}       {'[2 4 3]'}       {0×0 char                                                                                                                                                                            }           {'No'    }             {0×0 char   }  
       100            50          {0×0 char }       {0×0 char }       {'[-3.750 60 0; -3.616 58.005 0; -3.219 56.047 0; -2.565 54.158 0; -1.878 52.298 0;-1.093 50.460 0;-0.560 48.534 0; -0.287 46.554 0; -0.250 44.555 0; -0.250 42.555 0; -0.25 -9.5 0]'}           {'No'    }             {0×0 char   }  
        80            35          {0×0 char }       {0×0 char }       {'[3.25 60 0; 3.116 58.006 0; 2.719 56.047 0; 2.065 54.158 0; 1.378 52.298 0; 0.593 50.460 0; 0.060 48.534 0; -0.212 46.554 0; -0.25 44.555 0;-0.25 42.555 0;-0.25 -9.5 0]'          }           {'No'    }             {0×0 char   }  

Create an array of variationProperties objects containing the variations specified in the parameter table by using the helperDefineVariationProperties helper function.

variationPropertiesObj = helperDefineVariationProperties(seedScenarioDescriptor,parameterTable);

Generate Scenario Variants

Generate an array of ScenarioDescriptor object variants from the seed scenario descriptor by using the generateVariants function.

[variantDescriptors,variantInfo] = generateVariants(seedScenarioDescriptor,variationPropertiesObj);

Display the information of the generated variants.

disp(struct2table(variantInfo))
    ValidVariant    ActorVariationProperties    CollisionVariationProperties      Messages  
    ____________    ________________________    ____________________________    ____________

         1                 1×2 struct                   {1×1 struct}            {0×0 double}
         1                 1×2 struct                   {1×1 struct}            {0×0 double}
         1                 1×2 struct                   {1×1 struct}            {0×0 double}
         1                 1×2 struct                   {0×0 double}            {0×0 double}
         1                 1×2 struct                   {0×0 double}            {0×0 double}
         1                 1×2 struct                   {0×0 double}            {0×0 double}

Get an array of drivingScenario objects from the array of ScenarioDescriptor object variants by using the getScenario function.

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

Visualize the generated driving scenario variants.

visualizationInfo = helperGetVisualizationProperties(parameterTable,filename);
helperVisualizeVariants(seedScenario,variantScenarios,Title=visualizationInfo.figureTitle, ...
    VariantTitles=visualizationInfo.gridTitles,SeedTitle=visualizationInfo.seedTitle, ...
    Waypoints=visualizationInfo.Waypoints,GridDimension=[visualizationInfo.Row visualizationInfo.Column],StopAtCollision="on");

Further Exploration

In this example, you have explored the generation of scenario variants containing dimension, speed, waypoint, and collision point variations using an Excel spreadsheet, VariationParameters.xlsx.

This example also contains these Excel files, which you can use to generate scenario variants with speed, dimension, waypoint, and collision parameter variations separately. To generate variants from one of these files, you must specify the corresponding Excel filename as the variable filename in the Create Variation Properties Object Using Data from Excel section, and follow the rest of the procedure in the example.

  • SpeedAndDimensionVariation — Use this Excel file to generate variants containing speed and dimension variations. This figure shows the seed scenario and the scenario variants containing speed and dimension variations.

  • CollisionVariation — Use this Excel file to generate variants containing collision parameter variations. This figure shows the seed scenario and the scenario variants containing collision parameter variations.

  • WaypointVariation — Use this Excel file to generate variants containing actor waypoint variations. This figure shows the seed scenario and the scenario variants containing actor waypoint variations.

You can also create your own seed scenario and explore other variation parameters, defined in the table in the Define Parameter Variations Using Excel Spreadsheet section, to generate variants of interest, such as to simulate Euro NCAP test protocol standards such as Adaptive Cruise Control (ACC), Autonomous Emergency Braking (AEB), and Lane Keep Assist (LKA).

Helper Functions

helperGetVisualizationProperties

This function generates a figure heading, individual titles for grid plots, a title for the seed scenario, and the recommended mode for visualization based on a parameters table and filename.

function visualizationData = helperGetVisualizationProperties(parameterTable,filename)
visualizationData.gridTitles = "";
visualizationData.Waypoints = "on";
switch filename
    case "VariationParameters"
        visualizationData.figureTitle = "Speed, Dimension, Waypoint, and Collision Parameter Variation for Car to Car Test";
        visualizationData.seedTitle = "Seed Scenario: Ego Speed 36.11 m/s Target Speed 10 m/s";
        visualizationData.gridTitles(1) = "Ego Speed " + round(parameterTable.Ego_Speed(1),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(1),2) + " m/s";
        visualizationData.gridTitles(2) = "Ego Speed " + round(parameterTable.Ego_Speed(2),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(2),2) + " m/s" + " Collision Fraction is " + parameterTable.CollisionFraction(2);
        visualizationData.gridTitles(3) = "Ego Speed " + round(parameterTable.Ego_Speed(3),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(3),2) + " m/s" + " Collision Fraction is " + parameterTable.CollisionFraction(3);
        visualizationData.gridTitles(4) = "Ego Speed " + round(parameterTable.Ego_Speed(4),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(4),2) + " m/s" + " Ego Dimension " + parameterTable.Ego_Dimension(4) + " Target Dimension " + parameterTable.Target_Dimension(4);
        visualizationData.gridTitles(5) = "Ego Speed " + round(parameterTable.Ego_Speed(5),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(5),2) + " m/s" + " Target CutIn Left";
        visualizationData.gridTitles(6) = "Ego Speed " + round(parameterTable.Ego_Speed(6),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(6),2) + " m/s" + " Target CutIn Right";
        visualizationData.Row = 7;
        visualizationData.Column = 1;
    case "SpeedAndDimensionVariation"
        visualizationData.figureTitle = "Speed and Dimension Variation for Car to Car Test";
        visualizationData.seedTitle = "Seed Scenario: Ego Speed 36.11 m/s Target Speed 10 m/s";
        for i = 1:2
            visualizationData.gridTitles(i) = "Ego Speed " + round(parameterTable.Ego_Speed(i),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(i),2) + " m/s";
        end
        visualizationData.gridTitles(3) = "Ego Speed " + round(parameterTable.Ego_Speed(3),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(3),2) + " m/s" + " Ego Dimension " + parameterTable.Ego_Dimension(3);
        visualizationData.gridTitles(4) = "Ego Speed " + round(parameterTable.Ego_Speed(4),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(4),2) + " m/s" + " Target Dimension " + parameterTable.Target_Dimension(4);
        visualizationData.gridTitles(5) = "Ego Speed " + round(parameterTable.Ego_Speed(5),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(5),2) + " m/s" + " Ego Dimension " + parameterTable.Ego_Dimension(5) + " Target Dimension " + parameterTable.Target_Dimension(5);
        visualizationData.Row = 6;
        visualizationData.Column = 1;
    case "CollisionVariation"
        visualizationData.figureTitle = "Collision Parameter Variation for Car to Car Test";
        visualizationData.seedTitle = "Seed Scenario: Ego Speed 36.11 m/s Target Speed 10 m/s";
        for i = 1:size(parameterTable.CollisionFraction)
            visualizationData.gridTitles(i) = "Collision Fraction is " + parameterTable.CollisionFraction(i) + " Ego Speed " + round(parameterTable.Ego_Speed(i),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(i),2) + " m/s";
        end
        visualizationData.Row = 4;
        visualizationData.Column = 1;
    case "WaypointVariation"
        visualizationData.figureTitle = "Waypoint Variation for Target Cut-In Car to Car Test";
        visualizationData.seedTitle = "Seed Scenario: Ego Speed 36.11 m/s Target Speed 10 m/s";
        visualizationData.gridTitles(1) = "Ego Speed " + round(parameterTable.Ego_Speed(1),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(1),2) + " m/s" + " Target CutIn Left";
        visualizationData.gridTitles(2) = "Ego Speed " + round(parameterTable.Ego_Speed(2),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(2),2) + " m/s" + " Target CutIn Left";
        visualizationData.gridTitles(3) = "Ego Speed " + round(parameterTable.Ego_Speed(3),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(3),2) + " m/s" + " Target CutIn Right";
        visualizationData.gridTitles(4) = "Ego Speed " + round(parameterTable.Ego_Speed(4),2) + " m/s Target Speed " + round(parameterTable.Target_Speed(4),2) + " m/s" + " Target CutIn Right";
        visualizationData.Row = 5;
        visualizationData.Column = 1;
    otherwise
        error("Invalid filename. Specify either DimensionAndSpeedVariation, CollisionVariation, or WaypointVariation.")
end
end

See Also

Functions

Related Topics