Main Content

addPhaseInParallel

Create logic phase that executes concurrently during simulation

Since R2025a

    Description

    rrPhase = addPhaseInParallel(rrLogic,existingPhaseSequence,phaseType) creates a logic phase with the specified phase type, and adds it in parallel to the specified existing phase or serial sequence of phases. If the existing phases are not already children of a parallel phase, RoadRunner Scenario creates a new parent parallel phase. If you specify more than one phase, the phases must be consecutive children of a serial phase.

    rrPhase = addPhaseInParallel(rrLogic,existingPhaseSequence,phaseType,Insertion=insertionPosition) also specifies the position in the logic sequence at which to insert the new phase relative to the specified existing phase or serial sequence of phases.

    Examples

    collapse all

    Build a scenario in RoadRunner Scenario in which the actor changes lanes to the right of its current lane while simultaneously accelerating. To do this, add a Change Lane action phase after the initial phase in the RoadRunner scenario logic, then add a Change Speed action phase in parallel to the Change Lane phase. Phases that are parallel to each other in the scenario logic execute simultaneously.

    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 Parallel Phases

    Use addPhaseInSerial to add a new serial phase, srPhase, after the initial phase. Then, use addAction to specify "ChangeLaneAction" as the action type of the new phase. srPhase represents the newly added actor action phase in the RoadRunner scenario logic, and chLn represents the Change Lane action type assigned to srPhase.

    srPhase = addPhaseInSerial(rrLogic,initPhase,"ActorActionPhase",Insertion="after");
    chLn = addAction(srPhase,"ChangeLaneAction");

    Assign the new phase to the actor car by specifying the value of the Actor property of the phase as car. To instruct the actor to change lanes to the right of its current lane during simulation, set the Direction property of the action type chLn to "right".

    srPhase.Actor = car;
    chLn.Direction = "right";

    Use addPhaseInParallel to add a new phase, pllPhase, in parallel to srPhase, and assign it to car. Then, use addAction to specify the action type of the new phase as "ChangeSpeedAction".

    pllPhase = addPhaseInParallel(rrLogic,srPhase,"ActorActionPhase");
    pllPhase.Actor = car;
    chSpeed = addAction(pllPhase,"ChangeSpeedAction");

    To specify for the actor to accelerate to 50 m/s within 1 second, modify the properties of chSpeed so the Speed property is 50 m/s, the DynamicsDimension property is "time", and the DynamicsValue property is 1 second.

    chSpeed.Speed = 50;
    chSpeed.DynamicsDimension = "time";
    chSpeed.DynamicsValue = 1;

    Run the simulation by using the simulateScenario function.

    simulateScenario(rrApp)

    Input Arguments

    collapse all

    Scenario logic object, specified as a PhaseLogic object. The PhaseLogic object represents the root phase for the scenario in the RoadRunner scenario logic and contains all logic components for the scenario.

    Example: rrPhase = addPhaseInParallel(rrLogic,initPhase,"ActorActionPhase"); adds a new "ActorActionPhase" phase to the scenario logic rrLogic in parallel to the existing phase initPhase.

    Existing phase or serial phase sequence, specified as an array of one of these types of objects:

    The function places the new phase in parallel to this phase or phase sequence in the RoadRunner scenario logic. If specified as an array, all objects must be of the same phase type.

    Type of phase to create, specified as one of these values:

    • "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.

    Position of the new phase in the logic sequence, specified as one of these options:

    • "after" — Add the new phase below existingPhaseSequence in the scenario logic.

    • "before" — Add the new phase above existingPhaseSequence in the scenario logic.

    Output Arguments

    collapse all

    Logic phase, returned as one of these objects:

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

    • SystemActionPhase — Represents a logic phase that executes a system action.

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

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

    The value of the phaseType argument determines the type of the returned object.

    Version History

    Introduced in R2025a