Main Content

setEndCondition

Assign end condition to specified phase

Since R2025a

    Description

    rrCondition = setEndCondition(rrPhase,conditionType) creates and assigns a condition of the specified type to the end of the specified phase.

    Examples

    collapse all

    Assign an end condition to a phase in the RoadRunner scenario logic that instructs the actor car to stop after the specified time has elapsed.

    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.

    srPhase = addPhaseInSerial(rrLogic,initPhase,"ActorActionPhase",Insertion="after");
    chSpd = addAction(srPhase,"ChangeSpeedAction");

    Assign an 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 0. This instructs the assigned actor to change its speed to 0 m/s during simulation.

    srPhase.Actor = car;
    chSpd.Speed = 0;

    Use setEndCondition to Assign End Condition to Phase

    Use the setEndCondition function to create a DurationCondition object, rrCondition, and assign it to the initial phase of the actor car.

    This adds a Duration condition to the initial phase initPhase in the RoadRunner scenario logic that instructs the actor to perform the action specified by initphase until it reaches the value specified by the Duration property of the newly added condition rrCondition.

    rrCondition = setEndCondition(initPhase,"DurationCondition");
    rrCondition.Duration = 3;

    Run the simulation by using the simulateScenario function. The end condition rrCondition specifies for the initial phase initphase to end after 3 seconds, after which the actor car enters the next phase srPhase and changes its speed to 0 m/s.

    simulateScenario(rrApp)

    Input Arguments

    collapse all

    Existing logic phase to which to assign the condition, specified as one of these objects:

    Example: rrCondition = setEndCondition(rrPhase,"ActorSpeedCondition") assigns an Actor Speed end condition, rrCondition, to the phase rrPhase.

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

    • "ActorSpeedCondition" — Specifies for the associated phase to end when an actor reaches the specified speed.

    • "CollisionCondition" — Specifies for the associated phase to end when the one actor collides with another actor.

    • "DistanceToActorCondition" — Specifies for the associated phase to end when an actor is a certain distance away from a reference actor.

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

    • "LongitudinalDistanceToActorCondition" — Specifies for the associated phase to end when an actor reaches a certain longitudinal distance from another actor.

    • "DurationCondition" — Specifies for the associated phase to end after the specified amount of time elapses.

    • "PhaseStateCondition" — Specifies for the associated phase to end 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 associated phase to end when an actor reaches the specified speed.

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

    • CollisionCondition — Represents a Collision condition in the RoadRunner scenario logic that specifies for the associated phase to end when the one actor collides with another actor.

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

    • DistanceToActorCondition — Represents a Distance To Actor condition in the RoadRunner scenario logic that specifies for the associated phase to end 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 associated phase to end 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 associated phase to end when an actor reaches a certain longitudinal distance from another actor.

    Version History

    Introduced in R2025a

    See Also

    | | | |

    Topics