Main Content

setFailCondition

Assign fail condition to simulation

Since R2025a

    Description

    rrCondition = setFailCondition(rootPhase,conditionType) assigns a condition of the specified type to the Fail Conditions of the scenario root phase. The fail condition fails the simulation when triggered during execution. By default, RoadRunner Scenario automatically adds a Collision condition to the scenario Fail Conditions when you create a new scenario. You can modify an existing fail condition by extracting the FailCondition property of the RootPhase property of the scenario PhaseLogic object.

    Examples

    collapse all

    When you create a new scenario, RoadRunner Scenario adds a Collision condition to the scenario Fail Conditions by default. This Collision condition specifies for RoadRunner Scenario to fail the simulation if any actor collides with any other actor. Use the setFailCondition function to change the condition in the scenario Fail Conditions to specify for RoadRunner Scenario to fail the simulation if the actor car exceeds a speed of 30 m/s.

    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.

    Use addPhaseInSerial to add a new actor action phase, srPhase, in serial after the initial phase. Then, use addAction to specify the action of the new phase as "ChangeSpeedAction". The srPhase object represents the newly created actor action phase in the scenario logic, and chSpd represents the Change Speed action assigned to srPhase. Assign the actor to the new phase by specifying car as the value of the Actor property of the phase. Set the Speed property of the chSpd action to 35. This instructs the assigned actor to change its speed to 35 m/s during simulation.

    srPhase = addPhaseInSerial(rrLogic,initPhase,"ActorActionPhase",Insertion="after");
    chSpd = addAction(srPhase,"ChangeSpeedAction");
    srPhase.Actor = car;
    chSpd.Speed = 35;

    Modify Scenario Fail Condition

    To modify the condition type in the scenario Fail Conditions, extract the RootPhase property of the scenario phase logic object rrLogic. The logicRoot object represents the root phase of the RoadRunner scenario logic.

    logicRoot = rrLogic.RootPhase;

    Use setFailCondition to set a different condition in the scenario Fail Conditions by specifying the conditionType argument as "ActorSpeedCondition". Then, set the Actor property of the new fail condition rrCondition to car and the Speed property to 30. This changes the existing fail condition to an Actor Speed condition, and specifies for RoadRunner Scenario to fail the simulation if the actor car exceeds a speed of 30 m/s.

    rrCondition = setFailCondition(logicRoot,"ActorSpeedCondition");
    rrCondition.Actor = car;
    rrCondition.Speed = 30;

    Run the simulation by using the simulateScenario function.

    simulateScenario(rrApp)

    Input Arguments

    collapse all

    Scenario logic root phase, specified as a ParallelPhase object.

    Example: logicRoot = rrLogic.RootPhase; extracts the RootPhase property from the scenario logic object rrLogic, and rrCondition = setFailCondition(logicRoot,"ActorSpeedCondition"); sets the fail condition of that root phase to an Actor Speed condition.

    Type of condition to assign, specified as one of these condition types:

    • "ActorSpeedCondition" — Specifies for the simulation to fail when an actor reaches the specified speed.

    • "CollisionCondition" — Specifies for the simulation to fail when an actor collides with another actor.

    • "DistanceToActorCondition" — Specifies for the simulation to fail when an actor is a certain distance away from a reference actor.

    • "DistanceToPointCondition" — Specifies for the simulation to fail when an actor is a certain distance away from a specified point.

    • "LongitudinalDistanceToActorCondition" — Specifies for the simulation to fail when an actor reaches a certain longitudinal distance from another actor.

    • "DurationCondition" — Specifies for the simulation to fail after the specified amount of time elapses.

    • "PhaseStateCondition" — Specifies for the simulation to fail when the referenced phase reaches the specified state.

    Output Arguments

    collapse all

    Condition assigned to the phase, returned as one of these objects:

    • ActorSpeedCondition — Represents an Actor Speed condition in the RoadRunner scenario logic that specifies for the simulation to fail when an actor reaches the specified speed.

    • DurationCondition — Represents a Duration condition in the RoadRunner scenario logic that specifies for the simulation to fail after the specified amount of time elapses.

    • CollisionCondition — Represents a Collision condition in the RoadRunner scenario logic that specifies for the simulation to fail when an actor collides with another actor.

    • PhaseStateCondition — Represents a Phase State condition in the RoadRunner scenario logic that specifies for the simulation to fail when the referenced phase reaches the specified state.

    • DistanceToActorCondition — Represents a Distance To Actor condition in the RoadRunner scenario logic that specifies for the simulation to fail when an actor is a certain distance away from a reference actor.

    • DistanceToPointCondition — Represents a Distance To Point condition in the RoadRunner scenario logic that specifies for the simulation to fail when an actor is a certain distance away from a specified point.

    • LongitudinalDistanceToActorCondition — Represents a Longitudinal Distance To Actor condition in the RoadRunner scenario logic that specifies for the simulation to fail when an actor reaches a certain longitudinal distance from another actor.

    Version History

    Introduced in R2025a