Main Content

addManeuver

R2026b

Add maneuver roads to junction

Since R2026b

    Description

    rrManeuver = addManeuver(rrJunction,fromLanes,toLanes) adds a maneuver road that connects incoming lanes on one approach road to the outgoing lanes on the adjacent approach road within a junction. The function supports both single-lane and multi-lane maneuvers. For bidirectional lanes, you must specify the road end associated with the maneuver connection when the connection cannot be determined automatically.

    example

    rrManeuver = addManeuver(rrJunction,fromLanes,toLanes,Name=Value) adds a adds a maneuver road that connects incoming lanes on one approach road to the outgoing lanes on another approach road within a junction, using optional name-value arguments.

    Examples

    collapse all

    Create a roadrunner object, specifying the path to an existing project. For example, this code shows the path to a project, on a Windows® machine, located at "C:\RR\MyProject". This code assumes that RoadRunner is installed in the default location, and returns an object, rrApp, that provides functions for performing basic tasks such as opening, closing, and saving scenes and projects.

    rrApp = roadrunner(ProjectFolder="C:\RR\MyProject");

    Note

    If you are opening RoadRunner from MATLAB® for the first time, or if you have changed the RoadRunner installation location since you last opened it from MATLAB, you can use the roadrunnerSetup function to specify new default project and installation folders to use when opening RoadRunner. You can save these folders between MATLAB sessions by selecting the Across MATLAB sessions option from the corresponding dropdown.

    Create a new RoadRunner scene in the current project by using the newScene function, specifying the roadrunner object rrApp.

    newScene(rrApp);

    Create a RoadRunner authoring API object, rrAPI, that references the object for the current RoadRunner instance rrApp. The rrApi object enables you to programmatically author scenes, such as by adding and modifying road and lane components, using MATLAB.

    rrApi = roadrunnerAPI(rrApp);
    
    Extract the object for your scene from the Scene property of the authoring API object rrApi. The extracted Scene object enables you to specify the scene in which to add scene components, such as roads and lanes.
    scn = rrApi.Scene
    

    Use the addSegmentedRoad function to add a segmented curve type road to the scene. Specify the starting point of the road as a control point. Next, indicate the forward direction of the road by specifying a second control point. You must specify the positions of these control points along the X- and Y- axes of the RoadRunner local coordinate system.

    startPoint1 = [0 0];
    startRoadDirection1 = [1 0];
    rrRoad1 = addSegmentedRoad(scn,startPoint1,startRoadDirection1);
    

    Extract the horizontal curve of the segmented road. Then, use the addLine function to create a line segment and add it to the horizontal curve.

    segmentedCurve1 = rrRoad1.HorizontalCurve;
    addLine(segmentedCurve1,100);
    

    Extract the reference lane of the road from the ReferenceLane property of the road object rrRoad1. The reference lane defines the center lane, or reference line, of a road in a RoadRunner scene. This lane has no width and serves as the basis for positioning all other lanes, which RoadRunner arranges outward from the reference line.

    refLane1 = rrRoad1.ReferenceLane;

    Use the extracted refLane1 object to add lane on the left side of the reference lane of the road using the addLaneToLeft function. Then, use the LaneType and TravelDirection properties of the added lane to specify the type and travel direction, respectively. Add a driving lane to the left of the horizontal road with a backward travel direction.

    horizontalLane1 = addLaneToLeft(refLane1);
    horizontalLane1.LaneType = "driving";
    horizontalLane1.TravelDirection = "backward";
    

    Configure the width profile for the left lane by specifying the WidthProfile property of the lane. Specify the width of the lane.

    horizontalLane1WidthProfile = horizontalLane1.WidthProfile;
    startNode1 = horizontalLane1WidthProfile.Nodes(1);
    startNode1.EndWidth = 3.5;
    endNode1 = horizontalLane1WidthProfile.Nodes(end);
    endNode1.StartWidth = 3.5;
    

    Use the extracted refLane1 object to add another lane on the right side of the reference lane of the road using the addLaneToRight function. Then, use the LaneType and TravelDirection properties of the lane to specify the type and travel direction, respectively. Add a driving lane to the right of the horizontal road with a forward travel direction.

    horizontalLane2 = addLaneToRight(refLane1);
    horizontalLane2.LaneType = "driving";
    horizontalLane2.TravelDirection = "forward";
    

    Configure the width profile for the right lane by specifying the WidthProfile property of the lane. Specify the width of the lane.

    horizontalLane2WidthProfile = horizontalLane2.WidthProfile;
    startNode2 = horizontalLane2WidthProfile.Nodes(1);
    startNode2.EndWidth = 3.5;
    endNode2 = horizontalLane2WidthProfile.Nodes(end);
    endNode2.StartWidth = 3.5;
    

    Use the addSegmentedRoad function to add another segmented curve type road to the scene. Specify the starting point of the road as a control point. Next, indicate the forward direction of the road by specifying a second control point. You must specify the positions of these control points along the X- and Y- axes of the RoadRunner local coordinate system.

    startPoint2 = [110 0];
    startRoadDirection2 = [1 0];
    rrRoad2 = addSegmentedRoad(scn,startPoint2,startRoadDirection2);

    Extract the horizontal curve of the second segmented road. Then, use the addLine function to create a line segment and add it to the second horizontal curve.

    segmentedCurve2 = rrRoad2.HorizontalCurve;
    addLine(segmentedCurve2,100);

    Extract the reference lane of the road from the ReferenceLane property of the road object rrRoad2.

    refLane2 = rrRoad2.ReferenceLane;

    Use the extracted refLane2 object to add lane on the left side of the second reference lane of the road using the addLaneToLeft function. Then, use the LaneType and TravelDirection properties of the added lane to specify the type and travel direction, respectively. Add a driving lane to the left of the second horizontal road with a backward travel direction.

    horizontalLane3 = addLaneToLeft(refLane2);
    horizontalLane3.LaneType = "driving";
    horizontalLane3.TravelDirection = "backward";
    

    Configure the width profile for the second left lane by specifying the WidthProfile property of the lane. Specify the width of the lane.

    horizontalLane3WidthProfile = horizontalLane3.WidthProfile;
    startNode3 = horizontalLane3WidthProfile.Nodes(1);
    startNode3.EndWidth = 3.5;
    endNode3 = horizontalLane3WidthProfile.Nodes(end);
    endNode3.StartWidth = 3.5;
    

    Use the extracted refLane2 object to add another lane on the right side of the reference lane of the road using the addLaneToRight function. Then, use the LaneType and TravelDirection properties of the lane to specify the type and travel direction, respectively. Add a driving lane to the right of the second horizontal road with a forward travel direction.

    horizontalLane4 = addLaneToRight(refLane2);
    horizontalLane4.LaneType = "driving";
    horizontalLane4.TravelDirection = "forward";
    

    Configure the width profile for the second right lane by specifying the WidthProfile property of the lane. Specify the width of the lane.

    horizontalLane4WidthProfile = horizontalLane4.WidthProfile;
    startNode4 = horizontalLane4WidthProfile.Nodes(1);
    startNode4.EndWidth = 3.5;
    endNode4 = horizontalLane4WidthProfile.Nodes(end);
    endNode4.StartWidth = 3.5;
    

    Create a junction at distance ranges specified by startDistances and endDistances. You must specify these distance ranges as control points along the X- and Y- axes of the RoadRunner local coordinate system.

    roads = [rrRoad1, rrRoad2];
    startDistances = [90, -1];
    endDistances = [-1, 10];
    rrJunction = addJunction(scn, roads, startDistances, endDistances);
    

    Use the getLanes function to retrieve the incoming lanes and outgoing lanes on rrRoad1 and rrRoad2. Use these lanes to define a maneuver that connects the incoming lane fromrrRoad1 to the outgoing lane leaving the junction on rrRoad2 and vice versa.

    direction1 = "incoming";
    direction2 = "outgoing";
    inRoad1 = getLanes(rrJunction, rrRoad1, direction1 );
    outRoad2 = getLanes(rrJunction, rrRoad2, direction2);
    inRoad2 = getLanes(rrJunction, rrRoad2, direction1);
    outRoad1 = getLanes(rrJunction, rrRoad1, direction2);
    

    Add maneuver roads to the junction.

    rrManeuver1 = addManeuver(rrJunction, inRoad1, outRoad2)
    rrManeuver2 = addManeuver(rrJunction, inRoad2, outRoad1)
    

    Input Arguments

    collapse all

    Junction to add maneuvers to, specified as a Junction object.

    Lanes entering the junction, specified as an array of Lane objects.

    Lanes exiting the junction, specified as an array of Lane objects.

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: addManeuver(rrJunction, fromLanes,toLanes, FromRoadEnd="auto")

    Road end for the incoming lane, specified as one of these values—"auto", "start", and "end".

    ValueDescription
    "auto"RoadRunner application determines what value to use and sets the property to that value.
    "start"Road is connected to the corner or maneuver at the start point of the road. The road extends outward from the junction in the direction of increasing road distance.
    "end"Road is connected to the corner or maneuver at the end point of the road. The road extends outward from the junction in the direction of decreasing road distance toward the start of the road.

    This argument identifies which end of the fromLane connects to the maneuver and is only applicable when the incoming lanes are bidirectional.

    Road end for the outgoing lane, specified as one of the values listed in the table.

    ValueDescription
    "auto"RoadRunner application determines what value to use and sets the property to that value.
    "start"Road is connected to the corner or maneuver at the start point of the road. The road extends outward from the junction in the direction of increasing road distance.
    "end"Road is connected to the corner or maneuver at the end point of the road. The road extends outward from the junction in the direction of decreasing road distance toward the start of the road.

    This argument identifies which end of the toLane connects to the maneuver and is only applicable when the outgoing lanes are bidirectional.

    Output Arguments

    collapse all

    Maneuver roads in a junction, specified as a Maneuver object.

    Version History

    Introduced in R2026b