Main Content

CollisionCondition

Specify Collision condition

Since R2025a

    Description

    A CollisionCondition object represents a Collision condition in the RoadRunner scenario logic. The Collision condition specifies for the associated phase to end when the actor specified by FirstActor collides with the actor specified by SecondActor. You can use the CollisionCondition object to programmatically modify the attributes of the corresponding Collision condition by changing the property values of the object.

    Creation

    By default, RoadRunner Scenario automatically adds a Collision condition to the scenario Fail Conditions when you create a new scenario. However, you can also create a CollisionCondition object in these ways:

    • The setEndCondition function creates and assigns a condition of the specified type to the end of a specified phase. Specify the conditionType argument as "CollisionCondition" to create a CollisionCondition object associated with the specified phase.

    • The setFailCondition function assigns a condition of the specified type to the Fail Conditions of the scenario root phase. Specify the conditionType argument as "CollisionCondition" to create a CollisionCondition object associated with the scenario Fail Conditions.

    Properties

    expand all

    Name of the condition, specified as a string scalar or character vector.

    Note

    You can specify the Name property of CollisionCondition in MATLAB®, but RoadRunner Scenario does not display the Name property of conditions in the user interface.

    First actor to check for collision, specified as an empty string or one of these objects:

    • Vehicle — Represents a vehicle actor in the RoadRunner scenario.

    • Character — Represents a character actor in the RoadRunner scenario.

    • MovableObject — Represents a movable object actor in the RoadRunner scenario.

    If left empty, RoadRunner Scenario checks all actors in the scenario against SecondActor.

    Second actor to check for collision, specified as an empty string or one of these objects:

    • Vehicle — Represents a vehicle actor in the RoadRunner scenario.

    • Character — Represents a character actor in the RoadRunner scenario.

    • MovableObject — Represents a movable object actor in the RoadRunner scenario.

    If left empty, RoadRunner Scenario checks all actors in the scenario against FirstActor.

    Examples

    collapse all

    By default, RoadRunner Scenario automatically adds a Collision condition to the scenario Fail Conditions when you create a new scenario. This Collision condition specifies for RoadRunner Scenario to fail the simulation if any actor collides with any other actor.

    Use a CollisionCondition object to modify the properties of the scenario Fail Conditions so that the simulation fails only if the actor car collides with the actor staticCar.

    This example assumes that you have prior knowledge of working with RoadRunner in MATLAB. Before proceeding, follow the steps outlined in Set Up MATLAB Environment for RoadRunner Authoring Functions to set up your scenario using MATLAB functions for scenario authoring.

    Add Additional Actors

    Add two more vehicle actors to the scenario, staticCar and noCollisionCar, and anchor them to the scene anchor anchorPoint.

    staticCar = addActor(scnro,mySedan,[0 0 0]);
    staticCarPoint = staticCar.InitialPoint;
    anchorToPoint(staticCarPoint,anchorPoint,PosePreservation="reset-pose")
    
    noCollisionCar = addActor(scnro,mySedan,[0 0 0]);
    noCollisionCarPoint = noCollisionCar.InitialPoint;
    anchorToPoint(noCollisionCarPoint,anchorPoint,PosePreservation="reset-pose")

    Specify the Name properties of the new actors, so you can more easily distinguish them in the scenario logic. Name staticCar as "StaticCar" and noCollisionCar as "NoCollisionCar".

    staticCar.Name = "StaticCar";
    noCollisionCar.Name = "NoCollisionCar";

    Set the ForwardOffset property values of staticCar and noCollisionCar to 100 m and 30 m, respectively, so they do not overlap the position of car on the road.

    By default, the actors anchored to the "ScenarioStart" anchor in the ScenarioBasic.rrscene scene automatically align to the leftmost lane on the road. Due to the configuration of lanes in the scene, when staticCar relocates to a forward offset position of 100 m, it automatically aligns to a newly formed leftmost lane. To realign staticCar to the same lane as car and noCollisionCar, set its LaneOffset property to 1.

    staticCar.InitialPoint.ForwardOffset = 100;
    noCollisionCar.InitialPoint.ForwardOffset = 30;
    staticCar.InitialPoint.LaneOffset = 1;

    Use initialPhaseForActor to extract objects for the initial phases of staticCar and noCollisionCar. Then, use the findActions function to extract the ChangeSpeedAction objects from each of the actor initial phases and set the Speed properties of the actions to 0 m/s and 10 m/s, respectively.

    staticCarPhase = initialPhaseForActor(rrLogic,staticCar);
    staticCarAction = findActions(staticCarPhase,"ChangeSpeedAction");
    staticCarAction.Speed = 0;
    noCollisionCarPhase = initialPhaseForActor(rrLogic,noCollisionCar);
    noCollisionCarAction = findActions(noCollisionCarPhase,"ChangeSpeedAction");
    noCollisionCarAction.Speed = 10;

    Modify Scenario Fail Condition

    Retrieve the existing CollisionCondition object for the scenario collisionCondition by extracting the FailCondition property of the RootPhase property of the scenario phase logic object rrLogic.

    collisionCondition = rrLogic.RootPhase.FailCondition;

    To modify the condition so RoadRunner Scenario fails the simulation only if car collides with staticCar, set the FirstActor property of collisionCondition to car, and the SecondActor property of collisionCondition to staticCar.

    collisionCondition.FirstActor = car;
    collisionCondition.SecondActor = staticCar;

    Run the simulation by using the simulateScenario function. Due to the modified Collision condition, the simulation continues when the actor car passes through the actor noCollisionCar, and the simulation fails only when car collides with staticCar.

    simulateScenario(rrApp)

    Version History

    Introduced in R2025a