Main Content

localizeEgoUsingLanes

Localize ego trajectory on map using lane detections

Since R2025a

Description

localizedTrajectory = localizeEgoUsingLanes(trajectory,rrMap,lanedata,startLaneIndex) localizes the ego vehicle trajectory trajectory on a RoadRunner HD Map, rrMap, using the recorded lane boundary data lanedata, and returns the localized trajectory localizedTrajectory. The input startLaneIndex specifies the lane in which the ego is positioned at the start of the simulation.

example

localizedTrajectory = localizeEgoUsingLanes(trajectory,rrApp,lanedata,startLaneIndex) localizes the ego vehicle trajectory trajectory on a scene associated with the input RoadRunner application rrApp, and returns the localized trajectory localizedTrajectory.

localizedTrajectory = localizeEgoUsingLanes(___,ApproxLaneWidth=laneWidth) specifies the approximate width of a lane as a scalar, in meters, in addition to any combination of input arguments from previous syntaxes. The function uses the specified laneWidth to detect lane change events from the lane boundary detections.

[localizedTrajectory,info] = localizeEgoUsingLanes(___) additionally returns the debugging information as a structure, info, which contains information related to the lane and the ego vehicle.

Note

This function requires the Scenario Builder for Automated Driving Toolbox™ support package. You can install the Scenario Builder for Automated Driving Toolbox support package from the Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

Examples

collapse all

Load a MAT file containing an ego trajectory object, a RoadRunner HD Map object, and a lane data object into the workspace.

load("localizeEgoUsingLanesData.mat","laneDetections","rrHDMap","egoTrajectory")

Specify the lane number in which the ego is positioned at the start of simulation, which is the first waypoint in the trajectory.

egoStartLaneIdx = 2;

Localize the ego trajectory on the RoadRunner HD Map using the lane detections and the specified ego start lane index.

localizedTrajectory = localizeEgoUsingLanes(egoTrajectory,rrHDMap,laneDetections,egoStartLaneIdx);

Smooth the localized ego trajectory.

smooth(localizedTrajectory,Method="sgolay",Degree=2,SmoothingFactor=0.1)

Display the raw trajectory and the localized trajectory overlaid on the road network in the RoadRunner HD Map object.

plot(rrHDMap)
hold on
plot3(egoTrajectory.Position(:,1),egoTrajectory.Position(:,2),egoTrajectory.Position(:,3),"ro-")
plot3(localizedTrajectory.Position(:,1),localizedTrajectory.Position(:,2),localizedTrajectory.Position(:,3),"bo-")
legend("Lanes","Lane Boundaries","Raw Trajectory","Localized Trajectory")

Input Arguments

collapse all

Trajectory data, specified as a Trajectory object.

RoadRunner HD Map road data model, specified as a roadrunnerHDMap object. rrMap defines a simple data structure to represent road layouts using lanes, lane boundaries, lane markings, and junctions. This object provides functions that support reading, writing, and plotting HD map data.

Recorded lane boundary data, specified as a laneData object.

RoadRunner application associated with a project, specified as a roadrunner object. This object provides functions for performing common RoadRunner tasks such as opening, closing, and saving scenes and projects. rrApp provides functions that support importing data from files and exporting scenes to other formats from RoadRunner. For more information, see the Ego Localization Using Lane Detections and HD Map for Scenario Generation example.

Lane number of the ego at the start of the simulation, specified as a positive integer.

You can locate the lane index in which the ego is positioned at the start of the simulation by visually inspecting the first image frame of the raw camera data. The Scenario Builder for Automated Driving Toolbox support package indexes lanes in left-to-right order, with respect to the travel direction of the ego vehicle, excluding the shoulder lanes. If a lane detection model detects all lane boundaries in an image frame, you can use the egoLaneIndex object function of the laneData object to calculate the ego lane index.

Data Types: double

Approximate width of a lane, specified as a positive scalar. Units are in meters.

The function uses the specified laneWidth to detect lane change events from the lane boundary detections.

Data Types: double

Output Arguments

collapse all

Ego localized trajectory data, returned as a Trajectory object.

Ego lane information, returned as a structure.

The structure contains these fields:

  • EgoLaneIndex — Indices of the lanes in which the ego is traveling at each timestamp, returned as an N-element row vector of positive integers. N is the number of timestamps in the input laneData object.

  • LaneCenterOffsetFromDetections — Offset from the position of the ego vehicle to the center of the ego lane based on detections, returned as an N-element row vector of positive integers. N is the number of timestamps in the input laneData object. Units are in meters.

  • LaneCenterOffsetFromMap — Offset from the position of the ego vehicle from the center of the ego lane on the map, returned as an N-element row vector of positive integers. N is the number of timestamps in the input laneData object. Units are in meters.

Version History

Introduced in R2025a