Main Content

addPhase

Create new phase of specified type

Since R2025a

    Description

    rrPhase = addPhase(parentPhase,phaseType) creates a new phase of the specified type and adds it as the last child of the specified serial or parallel phase.

    Examples

    collapse all

    Use the addPhase function to add new action phases as children of a parallel phase in the RoadRunner scenario logic.

    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 addPhase to Add New Phases to Scenario Logic

    Use addPhaseInSerial to add a new parallel phase, pllPhase, in serial to initPhase. Then, use the addPhase function to add two actor action phases, actPhase1 and actPhase2, as children of pllPhase. Assign the new phases to the actor car by specifying the value of the Actor property of each phase as car.

    pllPhase = addPhaseInSerial(rrLogic,initPhase,"ParallelPhase",Insertion="after");
    actPhase1 = addPhase(pllPhase,"ActorActionPhase");
    actPhase1.Actor = car;
    actPhase2 = addPhase(pllPhase,"ActorActionPhase");
    actPhase2.Actor = car;

    Use addAction to specify the action type of actPhase1 as "ChangeSpeedAction" and actPhase2 as "ChangeLaneAction". Modify the properties of chSpd and chLn, which represent a Change Speed and a Change Lane action respectively, to specify for the actor car to accelerate to 50 m/s while changing lanes to the right over 1 second.

    chSpd = addAction(actPhase1,"ChangeSpeedAction");
    chLn = addAction(actPhase2,"ChangeLaneAction");
    
    chSpd.Speed = 50;
    chSpd.DynamicsDimension = "time";
    chSpd.DynamicsValue = 1;
    
    chLn.Direction = "right";
    chLn.DynamicsDimension = "time";
    chLn.DynamicsValue = 1;

    Run the simulation by using the simulateScenario function. Because actPhase1 and actPhase2 are children of the same parallel phase, car performs the Change Speed and Change Lane actions simultaneously during simulation.

    simulateScenario(rrApp)

    Input Arguments

    collapse all

    Parent phase to which to add the new phase, specified as a ParallelPhase object or SerialPhase object.

    Example: rrPhase = addPhase(pllPhase,"ActorActionPhase"); creates a new ActorActionPhase object, rrPhase, and adds it to the parallel phase pllPhase.

    Type of new phase to add, specified as one of these phase types:

    • "ActorActionPhase" — Logic phase that executes an actor action.

    • "SystemActionPhase" — Logic phase that executes a system action.

    • "ParallelPhase" — Logic phase that executes child phases concurrently.

    • "SerialPhase" — Logic phase that executes child phases sequentially.

    Note

    If parentPhase is a SerialPhase object, you cannot specify phaseType as "SerialPhase".

    Output Arguments

    collapse all

    Logic phase, returned as one of these objects:

    • ActorActionPhase — Represents an actor action phase in the RoadRunner scenario logic.

    • SystemActionPhase — Represents a logic phase in the RoadRunner scenario logic that executes actions without an actor.

    • ParallelPhase — Represents a logic phase in the RoadRunner scenario logic that executes child phases concurrently.

    • SerialPhase — Represents a logic phase in the RoadRunner scenario logic that executes child phases sequentially.

    Version History

    Introduced in R2025a