Main Content

Generate Scenario Variants by Modifying Actor Dimensions

This example shows you how to generate scenario variants from a seed scenario by varying the ego vehicle and target actor dimensions. In this example, you will generate variants of a Car-to-Pedestrian Nearside Child (CPNC) collision scenario by modifying the dimensions of the actors in the scenario. The collision point in the generated variant will remain same as that of the seed scenario. The collision point is a position on the ego vehicle at which the ego vehicle and target actor collide. This example assumes that the ego vehicle and the target actor always collide at 90 degrees, and the target actor collides with a point on the front edge of the ego vehicle.

  • If the ego vehicle collides with a target actor multiple times, this example generates scenario variants based on only the first collision instance.

  • If the ego vehicle collides with multiple target actors at different times in a scenario, this example generates scenario variants for only one target actor. You can specify which target actor to consider for generating the scenario variants.

This example uses the drivingScenario object to create a seed scenario and provides helper functions to generate the variants from the seed scenario. The rest of the example demonstrates the steps involved in generating the scenario variants.

  • Create a seed scenario.

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

  • Specify new dimensions for one or more actors in the seed scenario.

  • Add collision event.

  • Generate the scenario variants.

Create Seed Scenario

Create the CPNC seed scenario by using the helperCreateNCAPScenario function.

seedScenario = helperCreateNCAPScenario("AEBModifiedCPNC")
seedScenario = 
  drivingScenario with properties:

        SampleTime: 0.0100
          StopTime: Inf
    SimulationTime: 0
         IsRunning: 1
            Actors: [1x4 driving.scenario.Actor]
          Barriers: [0x0 driving.scenario.Barrier]
       ParkingLots: [0x0 driving.scenario.ParkingLot]

Extract Properties from Seed Scenario

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

seedScenarioDescriptor = getScenarioDescriptor(seedScenario,Simulator="DrivingScenario")
seedScenarioDescriptor = 
  ScenarioDescriptor with properties:

    status: "DescriptorCreated"

Create a scenario variant object by using the helper function HelperScenarioVariant. Use the generated scenario variant object to store the new dimension values required for generating the variants.

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

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

Specify New Actor Dimension Values

Create an actor variation object by using the helper function HelperActorVariation.

actorVariationParameter = HelperActorVariation;

Specify the ActorIDs of the ego and target actors whose dimensions you want to modify. You can find the ActorID and the name of an actor by inspecting the Actors property of the seed scenario stored as a drivingScenario object.

egoID = 1;
targetID = 2;

Modify Dimensions of Ego Vehicle

Specify new dimension value for the ego vehicle by using the addDimensionVariation method of HelperActorVariation object.

egoDimensions = struct(Length=1,Width=1.5,Height=3);
addDimensionVariation(actorVariationParameter,{egoID},{egoDimensions});

To generate multiple variations of the seed scenario with ego vehicle of different dimensions, call the addDimensionVariation method for each variation.

Specify a second dimension value for the ego vehicle to create another scenario variant.

egoDimensions = struct(Length=1.5,Width=2,Height=3.5);
addDimensionVariation(actorVariationParameter,{egoID},{egoDimensions});

Modify Dimensions of Ego Vehicle and Target Actor

To modify the dimensions of both ego vehicle and target actor in the seed scenario, use the addMultiVariation method of HelperActorVariation object.

egoDimensions = struct(Length=0.8,Width=1,Height=2.5);
targetDimensions = struct(Length=2,Width=1,Height=1.8);
addMultiVariation(actorVariationParameter,{egoID,targetID},Dimension={{egoDimensions},{targetDimensions}}); 

Store the new set of actor dimensions the ActorVariations property of the scenario variant object generated by the helper function HelperScenarioVariant.

variantParams.ActorVariations = actorVariationParameter;

Add Collision Event

Use the helper function HelperEventVariation and its method addCollision to add a collision event to the scenarios to be generated for new actor dimensions. The addCollision function examines the possibility of a collision event for the new actor dimensions. If the collision event does not occur, the function uses a wait time modification approach to create the collision event. In this approach, the function checks the arrival time of the ego vehicle and the target actor at the collision point. If the ego vehicle arrives at the collision point ahead of the target actor, the function computes a wait time for the ego vehicle. The ego vehicle waits at its first waypoint for an estimated amount of time to ensure that the ego vehicle collides with the target actor while travelling along its trajectory. Similarly, if the target actor arrives at the collision point ahead of the ego vehicle, the function computes a wait time for the target actor. The target actor waits at its first waypoint for an estimated amount of time to ensure that it collides with the ego vehicle while travelling along its trajectory.

eventVariationParameter = HelperEventVariation();
addCollision(eventVariationParameter,variantParams,egoID,targetID);

Store the computed parameters to the EventVariations property of the scenario variant object generated by the helper function HelperScenarioVariant.

variantParams.EventVariations = eventVariationParameter;

Generate Scenario Variants

Generate variants of the seed scenario by using the helper function generateVariants. The output returned by the generateVariants function is a cell array of scenarioVariantDescriptor object. The function generates a scenario variant for each actor dimension variation specified in the input object. The function returns the generated scenario variations as a scenarioVariantDescriptor object.

scenarioVariantDescriptors = generateVariants(variantParams);

Extract the scenario from the scenarioDescriptor object by using the getScenario function. The getScenario function returns the generated variants as a drivingScenario object.

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

Display the seed scenario and the generated variants by using the helper function helperVisualizeVariants. You can notice that the target actors in each of these scenarios wait at their first waypoint for a particular amount of time before they travel along their trajectory. You can also notice that the wait time of the target actor in each scenario is different in order to ensure the collision event occurs. The collision points in the three generated scenario variations remain as that of the seed scenario.

variationTitle=["Scenario Variant 1:New Ego Dimension", "Scenario Variant 2: New Ego Dimension","Scenario Variant 3: New Ego and Target Dimensions"];
figure
helperVisualizeVariants(seedScenario,variantScenario(1:length(variantScenario)),...
    "Generated Scenario Variations",...
    variationTitle, Mode="StandardFit", Row=2, Column=2, ...
    Legend="off", Waypoints="on", ActorIndicators=targetID);

{"String":"Figure Variant Visualization contains 4 axes objects and other objects of type subplottext, uipanel. Axes object 1 contains 13 objects of type patch, line. Axes object 2 contains 13 objects of type patch, line. Axes object 3 contains 13 objects of type patch, line. Axes object 4 contains 13 objects of type patch, line.","Tex":[],"LaTex":[]}

Future Exploration

You can also use this example to generate variants of a custom seed scenario. If you want to generate variants of a custom seed scenario, you must ensure that the input scenario is stored as a drivingScenario object and validate that a collision event occur in the input scenario. Use the helper function helperCheckScenario to check if the seed scenario meets the following requirements.

  • The ego vehicle and a desired target actor in the scenario are colliding.

  • The actors have atleast three waypoints along their trajectories.

  • The actors travel at a constant speed.

Create a scenarioDescriptor object to extract scenario information from the custom seed scenario. Then, use the helper function helperCheckScenario to validate the seed scenario. The function returns a value of 1 if the seed scenario is a valid scenario. Otherwise, it returns 0.

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

scenarioCheckPassed = helperCheckScenario(egoID,targetID,seedScenarioDes);

If the output returned by the helper function helperCheckScenario is 0, you can modify the seed scenario to a valid scenario by using the helper function helperSetScenarioCollision.

if ~scenarioCheckPassed

seedScenarioDescriptor = helperSetScenarioCollision(egoID,targetID,seedScenarioDes,method="WaitTime");

end

The helperSetScenarioCollision function modifies the scenario according to the following rules:

  • If the ego vehicle or target actor has only two waypoints, the helperSetScenarioCollision function adds the third waypoint at the midpoint between them and sets its speed value to that of the last waypoint.

  • If the ego vehicle or target actor does not travel with a constant speed starting from the first waypoint, the helperSetScenarioCollision function sets their speed values to a constant value of 80 kmph and 10 kmph, respectively.

  • If the ego vehicle and the target vehicle do not collide but have intersecting trajectories, helperSetScenarioCollision checks if a collision is possible by modifying the wait time of the target vehicle. If possible, the function modifies the wait time of the target vehicle to create a collision event. Otherwise, the function returns an error.

Thsi example demonstrates how to generate scenario variants by modifying the dimensions of the actors in the scenario. For information on how to generate scenario variants by modifying the actor dimensions, speed, and collision point, see Generate Scenario Variants for Testing AEB Pedestrian Systems.

References

[1] European New Car Assessment Programme (Euro NCAP). Test Protocol – AEB VRU systems. Version 3.0.4. EuroNCAP, April 2021. Available from: https://cdn.euroncap.com/media/62795/euro-ncap-aeb-vru-test-protocol-v304.pdf.

See Also

Functions

Related Topics