Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla Lane

From Leeroopedia
Knowledge Sources
Domains Road Network, Simulation
Last Updated 2026-02-15 05:00 GMT

Overview

The Lane class represents a single lane within a lane section of a road, providing lane type classification, width computation, transform calculation, and connectivity to adjacent lanes.

Description

carla::road::Lane is a MovableNonCopyable class that models an individual lane from the OpenDRIVE specification. Key features include:

  • LaneType enum -- a bitmask enum with 21 lane types including Driving, Sidewalk, Biking, Parking, Shoulder, Tram, Rail, Entry, Exit, OnRamp, OffRamp, and the special Any value for matching all types
  • Width computation -- evaluates a cubic polynomial from RoadInfoLaneWidth at a given s coordinate
  • Transform computation -- calculates 3D position and rotation by accumulating lateral offsets from the road center line through all intervening lanes, applying lane offset and elevation corrections, and handling the Unreal Engine Y-axis inversion
  • Corner positions -- computes left and right edge positions of the lane at a given s, with optional extra width for junction driving lanes and a fixed height offset for sidewalks (0.1524m)
  • Straightness check -- determines if the lane geometry is purely linear (no cubic/quadratic terms in geometry, lane offset, or elevation)
  • Connectivity -- provides successor/predecessor lane IDs and lists of next/previous lane pointers

The implementation in Lane.cpp uses a template helper ComputeTotalLaneWidth to accumulate widths across lanes from center (lane 0) to the target lane.

Usage

Use this class to query individual lane properties such as width, type, and transform at a specific road coordinate. It is used extensively by the Map class for waypoint transform computation and by the MeshFactory for road geometry generation.

Code Reference

Source Location

  • Repository: CARLA
  • Files: LibCarla/source/carla/road/Lane.h, LibCarla/source/carla/road/Lane.cpp

Signature

class Lane : private MovableNonCopyable {
public:
  enum class LaneType : int32_t {
    None, Driving, Stop, Shoulder, Biking, Sidewalk, Border,
    Restricted, Parking, Bidirectional, Median, Special1, Special2,
    Special3, RoadWorks, Tram, Rail, Entry, Exit, OffRamp, OnRamp,
    Any = -2
  };

  Lane() = default;
  Lane(LaneSection *lane_section, LaneId id,
       std::vector<std::unique_ptr<element::RoadInfo>> &&info);

  const LaneSection *GetLaneSection() const;
  Road *GetRoad() const;
  LaneId GetId() const;
  LaneType GetType() const;
  bool GetLevel() const;

  template <typename T> const T *GetInfo(const double s) const;
  template <typename T> std::vector<const T*> GetInfos() const;

  const std::vector<Lane *> &GetNextLanes() const;
  const std::vector<Lane *> &GetPreviousLanes() const;
  LaneId GetSuccessor() const;
  LaneId GetPredecessor() const;

  double GetDistance() const;
  double GetLength() const;
  double GetWidth(const double s) const;
  bool IsStraight() const;
  geom::Transform ComputeTransform(const double s) const;
  std::pair<geom::Vector3D, geom::Vector3D> GetCornerPositions(
      const double s, const float extra_width = 0.f) const;
  bool IsPositiveDirection() const;
};

Import

#include "carla/road/Lane.h"

I/O Contract

Input Type Description
double | Distance along the road to evaluate lane properties
float | Additional width for corner position computation (junctions)
Output Type Description
geom::Transform | 3D position and rotation at the lane center
pair<Vector3D, Vector3D> | Right and left edge locations
double | Total lane width evaluated from polynomial

Usage Examples

// Get lane width at a specific s
double width = lane.GetWidth(25.0);

// Compute the 3D transform at the lane center
geom::Transform t = lane.ComputeTransform(25.0);

// Check lane type
if (lane.GetType() == Lane::LaneType::Driving) {
  // Process drivable lane
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment