主要内容

SynchronizeAction

Specify Synchronize action

Since R2026a

    Description

    The SynchronizeAction object represents a Synchronize action in the RoadRunner scenario logic. The Synchronize action causes an actor to arrive at its specified target point at the same time as a reference actor arrives at another specified target point. The action synchronizes the longitudinal position and speed of the actor in relation to a reference actor. Specifying "SynchronizeAction" as the action type when adding an action to your scenario adds a Synchronize action to the specified phase in the scenario logic. You can use the SynchronizeAction object to programmatically modify the attributes of the corresponding Synchronize action by changing the property values of the object.

    Creation

    Use the addAction function to add an action of the specified type as a child to the specified phase. Specify the actionType argument as "SynchronizeAction" to create a SynchronizeAction object associated with the specified phase.

    Properties

    expand all

    Name of the action, specified as a string scalar or character vector.

    Note

    You can specify the Name property of SynchronizeAction in MATLAB®, but RoadRunner Scenario does not display the Name property of actions in the user interface.

    Phase containing the action, specified as an ActorActionPhase object.

    Target point of the actor, specified as a Point object.

    Distance at which RoadRunner Scenario considers the actor present at the target point, specified as a numeric scalar in meters. To be considered synchronized, the actor must be within TargetThreshold of TargetPoint at the same time ReferenceActor is within ReferenceTargetThreshold of ReferenceTargetPoint.

    Actor has a target speed, specified as a logical 1 (true) or 0 (false).

    Actor target speed, specified as a numeric scalar in meters per second. The target speed is the speed of the actor when it arrives at the target point.

    To use this property, you must set the HasTargetSpeed property to 1 or true.

    Method used to set the speed of the actor, specified as one of these options:

    • "absolute" — The actor travels at TargetSpeed m/s.

    • "actor" — The actor travels at a speed relative to the reference actor, as specified by Direction.

    To use this property, you must set the HasTargetSpeed property to 1 or true.

    Relativity of actor speed to the reference actor speed, specified as one of these options:

    • "faster" — The target speed of the actor is TargetSpeed m/s faster than the reference actor.

    • "slower" — The target speed of the actor is TargetSpeed m/s slower than the reference actor.

    • "same" — The target speed of the actor is the same speed as the reference actor.

    To use this property, you must set the SpeedReference property to "actor".

    Reference actor to synchronize with, specified as one of these objects:

    • Vehicle — Represents a vehicle actor in the RoadRunner scenario.

    • Character — Represents a character actor in the RoadRunner scenario.

    • MovableObject — Represents a movable object actor in the RoadRunner scenario.

    Target point of the reference actor, specified as a Point object.

    Distance at which RoadRunner Scenario considers the reference actor present at the target point, specified as a numeric scalar in meters. To be considered synchronized, the actor must be within TargetThreshold of TargetPoint at the same time ReferenceActor is within ReferenceTargetThreshold of ReferenceTargetPoint.

    Steady state status of the actor target speed, specified as a logical 1 (true) or 0 (false). Enabling this property ensures that the actor reaches its specified target speed within a certain time or distance, as specified by SteadyStateType and SteadyStateValue, of arriving at its target point.

    To use this property, you must set the HasTargetSpeed property to 1 or true.

    Type of steady state, specified as one of these options:

    • "time" — Time, in seconds, before reaching the target point at which the actor achieves the target speed.

    • "distance" — Distance, in meters, before the target point at which the actor achieves the target speed.

    To use this property, you must set the HasSteadyState property to 1 or true.

    Steady state value, specified as a numeric scalar in seconds or meters, depending on the value of SteadyStateType.

    To use this property, you must set the HasSteadyState property to 1 or true.

    Examples

    collapse all

    Use a SynchronizeAction object to synchronize the speed and position of two actors so they both drive parallel to each other during simulation.

    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.

    Add Two Vehicle Actors

    To add two vehicle actors to the scenario, use the getAsset function to extract a VehicleAsset object, mySedan, that represents the Sedan.fbx asset in the project prj. Then, use the addActor function to place two actors, ctrlActor and refActor, by specifying the scenario object scnro, the asset object, and the respective location for each actor.

    mySedan = getAsset(prj,"Vehicles/Sedan.fbx","VehicleAsset");
    ctrlActor = addActor(scnro,mySedan,[0 0 0]);
    refActor = addActor(scnro,mySedan,[0 0 0]);
    

    To relocate the actors so that they align with the lanes on the road, anchor them to the scene anchor ScenarioStart. First, use findSceneAnchor to extract an object, anchorPoint, that represents the ScenarioStart anchor. Then, extract objects for the InitialPoint property of the actors ctrlActor and refActor. Use anchorToPoint to relocate each actor from its current location to the location specified by ScenarioStart.

    anchorPoint = findSceneAnchor(scnro,"ScenarioStart");
    controlPoint = ctrlActor.InitialPoint;
    referencePoint = refActor.InitialPoint;
    anchorToPoint(controlPoint,anchorPoint,PosePreservation="reset-pose")
    anchorToPoint(referencePoint,anchorPoint,PosePreservation="reset-pose")
    

    To move the actors so they are located at different positions on the road, in different lanes, change the ForwardOffset and LaneOffset properties of the InitialPoint for each actor.

    controlPoint.ForwardOffset = 20;
    referencePoint.ForwardOffset = 50;
    referencePoint.LaneOffset = 1;

    Build Routes for Each Actor

    To use a Synchronize action, both actors must have routes. To build a route for the actors ctrlActor and refActor, extract the Route property of the actor initial points controlPoint and referencePoint, respectively. Then, use addPoint to add a two new points to each route: a target point, where synchronization occurs for each actor, and an end point to enable the actors to continue moving along the road after each has reached its target point.

    Specify the locations of the target point for each actor, controlTarget and referenceTarget, for ctrlActor and refActor, respectively, so that the points are positioned parallel to each other in their respective lanes. Then, add an end point for each actor route further down the road.

    controlRoute = controlPoint.Route;
    referenceRoute = referencePoint.Route;
    
    controlTarget = addPoint(controlRoute,[0 -3 0]);
    controlEnd = addPoint(controlRoute,[150 3 0]);
    referenceTarget = addPoint(referenceRoute,[0 -5 0]);
    referenceEnd = addPoint(referenceRoute,[150 0 0]);

    To align the actor routes with the lanes, use autoAnchor to anchor each point to the road.

    autoAnchor(controlTarget,PosePreservation="reset-pose");
    autoAnchor(controlEnd,PosePreservation="reset-pose");
    autoAnchor(referenceTarget,PosePreservation="reset-pose");
    autoAnchor(referenceEnd,PosePreservation="reset-pose");

    Add SynchronizeAction to Scenario Logic

    Use addPhaseInSerial to add a new actor action phase, the controlAction object, in serial after the initial phase controlInitPhase. Then, assign the new action phase to the actor by specifying ctrlActor as the Actor property of controlAction.

    rrLogic = scnro.PhaseLogic;
    controlInitPhase = initialPhaseForActor(rrLogic,ctrlActor);
    controlAction = addPhaseInSerial(rrLogic,controlInitPhase,"ActorActionPhase",Insertion="after");
    controlAction.Actor = ctrlActor;

    To add a Synchronize action, sync, use addAction to specify "SynchronizeAction" as the action of the action phase controlAction. To specify for the ctrlActor actor to synchronize its position with refActor during simulation, specify the TargetPoint property as controlTarget, the ReferenceActor property as refActor, and the ReferenceTargetPoint property as referenceTarget.

    sync = addAction(controlAction,"SynchronizeAction");
    sync.TargetPoint = controlTarget;
    sync.ReferenceActor = refActor;
    sync.ReferenceActorTargetPoint = referenceTarget;
    

    Add Change Speed Action

    Add a Change Speed action in serial after controlAction so that ctrlActor matches the speed of refActor after the point of synchronization. To learn more about the Change Speed action and ChangeSpeedAction object, see Change Speed Actions (RoadRunner Scenario) and ChangeSpeedAction, respectively.

    speedAction = addPhaseInSerial(rrLogic,controlAction,"ActorActionPhase",Insertion="after");
    speedAction.Actor = ctrlActor;
    chSpeed = addAction(speedAction,"ChangeSpeedAction");
    chSpeed.SpeedReference = "actor";
    chSpeed.ReferenceActor = refActor;
    chSpeed.Direction = "same";
    chSpeed.DynamicsDimension = "time";
    chSpeed.DynamicsValue = 0;

    Run the simulation by using the simulateScenario function.

    simulateScenario(rrApp)

    Version History

    Introduced in R2026a