主要内容

addAction

Add action to logic phase

Since R2025a

    Description

    rrAction = addAction(rrPhase,actionType) creates an action of the specified type and adds it as a child of the specified logic phase. For example, rrAction = addAction(rrPhase,"ChangeSpeedAction") creates an object, rrAction, that represents the Change Speed action type and its attributes in the RoadRunner scenario logic and assigns it to rrPhase.

    example

    Examples

    collapse all

    Use addAction to specify the action type for a new 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 addAction to Add Action to New Phase

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

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

    Assign the actor to the new phase by specifying car as the value of the Actor property of the phase. 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";
    

    Run the simulation by using the simulateScenario function.

    simulateScenario(rrApp)

    Input Arguments

    collapse all

    Phase to which to assign the action type, specified as an ActorActionPhase object or SystemActionPhase object.

    Example: rrAction = addAction(rrPhase,"ChangeLaneAction"); specifies for RoadRunner Scenario to add the Change Lane action type to the phase rrPhase. This returns the object rrAction that represents the action type and its properties.

    Type of action to assign to the phase rrPhase, specified as one of these action types:

    • "ChangeLaneAction" — Represents a Change Lane action in the RoadRunner scenario logic. Specifies for the actor to change lanes using the specified properties.

    • "ChangeSpeedAction" — Represents a Change Speed action in the RoadRunner scenario logic. Specifies for the actor to change speed using the specified properties.

    • "ChangeLongitudinalDistanceAction" — Represents a Change Longitudinal Distance action in the RoadRunner scenario logic. Specifies for the actor to change forward distance relative to another actor using the specified properties.

    • "ChangeLateralOffsetAction" — Represents a Change Lateral Offset action in the RoadRunner scenario logic. Specifies for the actor to change lateral offset using the specified properties.

    • "WaitAction" — Represents a Wait action in the RoadRunner scenario logic. Specifies for the simulation to wait in this phase until an associated condition ends the phase.

    Output Arguments

    collapse all

    Action type of the phase, returned as one of these objects:

    • ChangeLaneAction — Represents a Change Lane action in the RoadRunner scenario logic. Specifies for the actor to change lanes using the specified properties.

    • ChangeSpeedAction — Represents a Change Speed action in the RoadRunner scenario logic. Specifies for the actor to change speed using the specified properties.

    • ChangeLongitudinalDistanceAction — Represents a Change Longitudinal Distance action in the RoadRunner scenario logic. Specifies for the actor to change forward distance relative to another actor using the specified properties.

    • ChangeLateralOffsetAction — Represents a Change Lateral Offset action in the RoadRunner scenario logic. Specifies for the actor to change lateral offset using the specified properties.

    • WaitAction — Represents a Wait action in the RoadRunner scenario logic. Specifies for the simulation to wait in this phase until an associated condition ends the phase.

    The rrAction object represents the action type and its attributes for the associated action phase in RoadRunner Scenario.

    Version History

    Introduced in R2025a