Main Content

laneBoundaries

Get lane boundaries relative to host vehicle

Since R2023a

Description

example

lbdrys = laneBoundaries(sensorSim,sensorID) gets the lane boundaries lbdrys of the lane in which the vehicle actor hosting the sensor specified by sensorID, is traveling. The lane boundaries are in the coordinate system of the host vehicle.

lbdrys = laneBoundaries(sensorSim,sensorID,Name=Value) specifies additional options using one or more name-value arguments.

Examples

collapse all

Define sensor models in MATLAB®, and add them to vehicle actors in a RoadRunner Scenario. Then, obtain ground truth measurements from RoadRunner Scenario, process them into detections for visualization.

Set Up RoadRunner Scenario — MATLAB Interface

Configure your RoadRunner installation and project folder properties. Open the RoadRunner app.

rrInstallationPath = "C:\Program Files\RoadRunner R2022b\bin\win64";
rrProjectPath = "D:\RR\TestProjects";

s = settings;
s.roadrunner.application.InstallationFolder.PersonalValue = rrInstallationPath;
rrApp = roadrunner(rrProjectPath);

To open the scenario this example uses, you must add the TrajectoryCutIn-longRun.rrscenario file from the example folder to your RoadRunner project folder. Then, open the scenario.

openScenario(rrApp,"TrajectoryCutIn-longRun")

Create a ScenarioSimulation object to connect MATLAB to the RoadRunner Scenario simulation and set the step size.

scenarioSim = createSimulation(rrApp);
stepSize = 0.1;
set(scenarioSim,"StepSize",stepSize);

Create a SensorSimulation object to control the sensor configuration for the RoadRunner Scenario simulation.

sensorSim = get(scenarioSim,"SensorSimulation");

Configure Sensors and Add to RoadRunner Scenario

Configure the sensor model consisting of one vision sensor at the front of the ego vehicle using the visionDetectionGenerator object. If you want to add multiple sensors, specify unique IDs for each sensor.

sensorID = 1;
sensor = visionDetectionGenerator(SensorIndex=sensorID, ...
            SensorLocation=[2.4 0], ...
            MaxRange=50, ...
            DetectorOutput="Objects only", ...
            UpdateInterval=stepSize);

Add the sensor to the ego vehicle actor in the RoadRunner scenario. Specify the Actor ID property for the vehicle.

egoVehicleID = 1;
addSensors(sensorSim,sensor,egoVehicleID)

Set up bird's-eye-plot for visualization.

[lbPlotter,detPlotter,bepAxes] = helperSetupBEP(sensor);

Simulate RoadRunner Scenario and Visualize Sensor Data

Use the ScenarioSimulation object to step through the RoadRunner scenario. Retrieve target poses in the sensor range using the targetPoses function, and process them into detections using the sensor model. Visualize detections and ground truth lane boundaries using birdsEyePlot.

simTime = 0.0;
set(scenarioSim,"SimulationCommand","Start");
set(scenarioSim,"SimulationCommand","Pause");
pause(0.5)
legend(bepAxes,"show")

while ~isequal(get(scenarioSim,"SimulationStatus"),"Stopped")

    % Get ground truth target poses and lane boundaries from the sensor
    tgtPoses = targetPoses(sensorSim,1);
    gTruthLbs = laneBoundaries(sensorSim,1,OutputOption="EgoAdjacentLanes",inHostCoordinate=true);
    
    if ~isempty(gTruthLbs)
        
        % Plot ground-truth lane boundaries
        helperPlotLaneBoundaries(lbPlotter,gTruthLbs)
        
        % Generate detections
        [objDets,numObjDets,objDetsValid] = sensor(tgtPoses,simTime);
        
        % Plot detections
        if objDetsValid
            detPos = cellfun(@(d)d.Measurement(1:2),objDets,UniformOutput=false);
            detPos = vertcat(zeros(0,2),cell2mat(detPos')');
            plotDetection(detPlotter,detPos)
        end
        
    end     

    if ~isequal(get(scenarioSim,"SimulationStatus"),"Stopped")
        set(scenarioSim,"SimulationCommand","Step");
    end

    simTime = simTime + stepSize;
    pause(0.1)
end

Helper Functions

helperSetupBEP function creates a bird's-eye-plot and configures all the plotters for visualization.

helperPlotLaneBoundaries function plots the lane boundaries on the birds'eye-plot.

Input Arguments

collapse all

Sensor simulation object, specified as a SensorSimulation object. The sensor simulation object must correspond to the desired scenario created in RoadRunner Scenario.

Unique index of the sensor in the RoadRunner Scenario, specified as a positive scalar. This must be same as the SensorIndex property of the detection generator object which corresponds to the desired sensor.

Name-Value Arguments

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.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Lane boundaries to output, specified as one of these options:

  • "EgoLane" — The function returns the boundaries for the lane in which the host vehicle actor is traveling.

  • "EgoAdjacentLanes" — The function returns the boundaries for the adjacent left and right lanes along with the lane in which host vehicle actor is traveling.

  • "AllLanes" — The function returns the boundaries for all lanes on the road.

Enable the lane boundaries to be returned in host vehicle coordinates, specified as a logical 1 (true) or 0 (false). Specify this argument as false or 0 to return the lane boundaries in the world coordinates of the RoadRunner scenario.

Output Arguments

collapse all

Lane boundaries, returned as an array of lane boundary structures. This table shows the fields for each structure.

FieldDescription

Coordinates

Lane boundary coordinates, returned as a real-valued N-by-3 matrix, where N is the number of lane boundary coordinates. Lane boundary coordinates define the position of points on the boundary at returned longitudinal distances away from the ego vehicle, along the center of the road.

  • In MATLAB®, specify these distances by using the 'XDistance' name-value pair argument of the laneBoundaries function.

  • In Simulink®, specify these distances by using the Distances from ego vehicle for computing boundaries (m) parameter of the Scenario Reader block or the Distance from parent for computing lane boundaries parameter of the Simulation 3D Vision Detection Generator block.

This matrix also includes the boundary coordinates at zero distance from the ego vehicle. These coordinates are to the left and right of the ego vehicle origin, which is located under the center of the rear axle. Units are in meters.

Curvature

Lane boundary curvature at each row of the Coordinates matrix, returned as a real-valued N-by-1 vector. N is the number of lane boundary coordinates. Units are in radians per meter.

CurvatureDerivative

Derivative of lane boundary curvature at each row of the Coordinates matrix, returned as a real-valued N-by-1 vector. N is the number of lane boundary coordinates. Units are in radians per square meter.

HeadingAngle

Initial lane boundary heading angle, returned as a real scalar. The heading angle of the lane boundary is relative to the ego vehicle heading. Units are in degrees.

LateralOffset

Lateral offset of the ego vehicle position from the lane boundary, returned as a real scalar. An offset to a lane boundary to the left of the ego vehicle is positive. An offset to the right of the ego vehicle is negative. Units are in meters. In this image, the ego vehicle is offset 1.5 meters from the left lane and 2.1 meters from the right lane.

Ego vehicle in a driving lane

BoundaryType

Type of lane boundary marking, returned as one of these values:

  • 'Unmarked' — No physical lane marker exists

  • 'Solid' — Single unbroken line

  • 'Dashed' — Single line of dashed lane markers

  • 'DoubleSolid' — Two unbroken lines

  • 'DoubleDashed' — Two dashed lines

  • 'SolidDashed' — Solid line on the left and a dashed line on the right

  • 'DashedSolid' — Dashed line on the left and a solid line on the right

Strength

Saturation strength of the lane boundary marking, returned as a real scalar from 0 to 1. A value of 0 corresponds to a marking whose color is fully unsaturated. The marking is gray. A value of 1 corresponds to a marking whose color is fully saturated.

Width

Lane boundary width, returned as a positive real scalar. In a double-line lane marker, the same width is used for both lines and for the space between lines. Units are in meters.

Length

Length of dash in dashed lines, returned as a positive real scalar. In a double-line lane marker, the same length is used for both lines.

Space

Length of space between dashes in dashed lines, returned as a positive real scalar. In a dashed double-line lane marker, the same space is used for both lines.

Version History

Introduced in R2023a