Main Content

DistanceToPointCondition

Specify Distance To Point condition

Since R2025a

    Description

    A DistanceToPointCondition object represents a Distance To Point condition in the RoadRunner scenario logic. The Distance To Point condition specifies for the associated phase to end when an actor is a certain distance away from a specified point. Specifying DistanceToPointCondition as the condition type when creating an end or fail condition in your scenario adds a Distance To Point condition to the specified phase in the scenario logic. You can use the DistanceToPointCondition object to programmatically modify the attributes of the corresponding Distance To Point condition by changing the property values of the object.

    Creation

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

    Actor to compare against the condition, 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.

    RoadRunner Scenario calculates distance based on the position of Actor relative to Point.

    Note

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

    Point used for distance comparison, specified as a Point object. RoadRunner Scenario compares the position of Point against the position of Actor.

    Note

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

    Rule for distance comparison, specified as one of these options:

    • "le" — The actor satisfies the condition when it is less than or equal to Distance meters from Point.

    • "ge" — The actor satisfies the condition when it is greater than or equal to Distance meters from Point.

    Distance, in meters, at which the actor satisfies the condition, specified as a positive scalar. RoadRunner Scenario uses the method specified by Rule to compare the distance between the actor and Point against the specified value of Distance.

    Data Types: double

    Height of the point above the ground, in meters, specified as a numeric scalar.

    Examples

    collapse all

    Use a DistanceToPointCondition object to specify for the actor to change its lane offset when it reaches a distance of 20 meters from a specified point on the route.

    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 DistanceToPointCondition

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

    srPhase = addPhaseInSerial(rrLogic,initPhase,"ActorActionPhase",Insertion="after");
    chLat = addAction(srPhase,"ChangeLateralOffsetAction");

    Assign the actor car to the new phase by specifying the value of the Actor property of the phase as car. Then, specify for the actor to change its lateral offset by 3 meters over 1 second by setting the LateralOffset property to 3 and the DynamicsValue property to 1.

    srPhase.Actor = car;
    chLat.LateralOffset = 3;
    chLat.DynamicsValue = 1;

    Create an object, carRoute, to represent the Route property of the InitialPoint property of car. Then, use addPoint to add a new point to the route at the specified location.

    If you do not know the exact coordinates at which you want to place the new point, you can quickly align it to the same lane as the actor by using anchorToPoint and specifying the same anchor point anchorPoint as for the actor car. Then, set the ForwardOffset property of your new point to 50 to move it 50 meters in front of car.

    carRoute = car.InitialPoint.Route;
    roadPoint = addPoint(carRoute,[0 0 0]);
    anchorToPoint(roadPoint,anchorPoint,PosePreservation="reset-pose")
    roadPoint.ForwardOffset = 50;

    Use setEndCondition to add a condition, rrCondition, to the initial phase initPhase, specifying the condition type as "DistanceToPointCondition".

    rrCondition = setEndCondition(initPhase,"DistanceToPointCondition");

    Specify for the condition to compare the distance between the actor and the route point by setting the Actor property to car and the Point property to roadPoint. Then, set the Distance property to 20.

    rrCondition.Actor = car;
    rrCondition.Point = roadPoint;
    rrCondition.Distance = 20;

    Run the simulation by using the simulateScenario function. The actor, car changes its lane offset by 3 meters once it reaches a distance within 20 meters of the point roadPoint.

    simulateScenario(rrApp)

    Version History

    Introduced in R2025a