主要内容

getConnectedRoads

R2026b

Query approach roads connected by corner

Since R2026b

    Description

    rrRoads = getConnectedRoads(rrCorners) queries the two approach roads connected to the specified corner. Approach roads are roads that participate in junction creation and provide incoming and outgoing lane connections to the maneuver and corner roads.

    example

    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);
    

    Retrieve the corner roads of the junction by extracting the Corner object from the Corners property of the Junction object.

    rrCorners = rrJunction.Corners
    

    Query the approach roads for the corners using the getConnectedRoads function.

    for i = 1:numel(rrCorners)
      rrRoad = getConnectedRoads(rrCorners(i))
    end 

    Input Arguments

    collapse all

    Corner to query for approach roads, specified as Corner object.

    Output Arguments

    collapse all

    Approach roads connected by the corner, returned as an array of Road objects.

    Version History

    Introduced in R2026b