Contenuto principale

PhaseStateCondition

Specify Phase State condition

Since R2025a

    Description

    A PhaseStateCondition object represents a Phase State condition in the RoadRunner scenario logic. The Phase State condition specifies for the associated phase to end when the referenced phase reaches the specified state. Specifying PhaseStateCondition as the condition type when creating an end or fail condition in your scenario adds a Phase State condition to the specified phase in the scenario logic. You can use the PhaseStateCondition object to programmatically modify the attributes of the corresponding Phase State condition by changing the property values of the object.

    Creation

    You can create a PhaseStateCondition 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 "PhaseStateCondition" to create a PhaseStateCondition 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 "PhaseStateCondition" to create a PhaseStateCondition 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 PhaseStateCondition in MATLAB®, but RoadRunner Scenario does not display the Name property of conditions in the user interface.

    Phase to compare against the condition, specified as one of these objects:

    • ActorActionPhase object — Represents a logic phase that executes an action for an actor.

    • SystemActionPhase object — Represents a logic phase that executes an action without an actor.

    • ParallelPhase object — Represents a logic phase that executes child phases concurrently.

    • SerialPhase object — Represents a logic phase that executes child phases sequentially.

    Note

    You must specify a nonempty value for this property before you can run the simulation.

    Phase state that satisfies this condition, specified as one of these options:

    • "idle" — The phase state satisfies the condition when Phase is idle.

    • "start" — The phase state satisfies the condition when Phase starts.

    • "run" — The phase state satisfies the condition when Phase is running.

    • "end" — The phase state satisfies the condition when Phase ends.

    Examples

    collapse all

    Use a PhaseStateCondition object to specify for an actor to change lanes only after the specified phase of the reference actor reaches the "end" state.

    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.

    Design Scenario Using Phase State Condition

    Use addPhaseInSerial to add a new actor action phase, srPhase, in serial after the initial phase. Then, use addAction to specify "ChangeSpeedAction" as the action type of the new phase. srPhase 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 the actor to the new phase by specifying car as the value of the Actor property of the phase. Specify for the actor to change its speed to 50 m/s over 1 second by setting the Speed property to 50, the DynamicsDimension property to "time", and the DynamicsValue property to 1.

    srPhase.Actor = car;
    chSpd.Speed = 50;
    chSpd.DynamicsDimension = "time";
    chSpd.DynamicsValue = 1;

    Add a second actor, car2, to the scenario. Then, reposition it to the lane right of car by specifying a lane offset of 1.

    car2 = addActor(scnro,mySedan,[0 0 0]);
    car2.Name = "car2";
    car2Point = car2.InitialPoint;
    anchorToPoint(car2Point,anchorPoint,PosePreservation="reset-pose")
    car2.InitialPoint.LaneOffset = 1;
    

    Extract the object car2Init to represent the initial phase of the actor car2. Use addPhaseInSerial to add a new actor action phase, car2Phase, after the initial phase. Then, use addAction to specify the action type of the new phase as "ChangeLaneAction". Set the Actor property of car2Phase to car2 and the Direction property of the action chLn to "left".

    car2Init = initialPhaseForActor(rrLogic,car2);
    car2Phase = addPhaseInSerial(rrLogic,car2Init,"ActorActionPhase",Insertion="after");
    chLn = addAction(car2Phase,"ChangeLaneAction");
    car2Phase.Actor = car2;
    chLn.Direction = "left";

    Use setEndCondition to add a condition, rrCondition, to the initial phase for car2, and specify the condition type as "PhaseStateCondition". Then, set the Phase property to srPhase and the PhaseState property to "end".

    rrCondition = setEndCondition(car2Init,"PhaseStateCondition");
    rrCondition.Phase = srPhase;
    rrCondition.PhaseState = "end";

    Run the simulation by using the simulateScenario function. The Phase State condition specifies for car2 to change lanes to the left only after car completes the Change Speed action associated with the phase srPhase.

    simulateScenario(rrApp)

    Version History

    Introduced in R2025a