Lane

The geometry of lanes are described by AbstractLane objects, as a parametrized center line curve, providing a local coordinate system.

Conversions between the (longi, lat) coordinates in the Frenet frame and the global \(x,y\) coordinates are ensured by the position() and local_coordinates() methods.

The main implementations are:

API

class highway_env.road.lane.AbstractLane[source]

A lane on the road, described by its central curve.

metaclass__

alias of abc.ABCMeta

DEFAULT_WIDTH: float = 4
VEHICLE_LENGTH: float = 5
length: float = 0
line_types: List['LineType'] = None
abstract position(longitudinal: float, lateral: float) → numpy.ndarray[source]

Convert local lane coordinates to a world position.

Parameters
  • longitudinal – longitudinal lane coordinate [m]

  • lateral – lateral lane coordinate [m]

Returns

the corresponding world position [m]

abstract local_coordinates(position: numpy.ndarray) → Tuple[float, float][source]

Convert a world position to local lane coordinates.

Parameters

position – a world position [m]

Returns

the (longitudinal, lateral) lane coordinates [m]

abstract heading_at(longitudinal: float) → float[source]

Get the lane heading at a given longitudinal lane coordinate.

Parameters

longitudinal – longitudinal lane coordinate [m]

Returns

the lane heading [rad]

abstract width_at(longitudinal: float) → float[source]

Get the lane width at a given longitudinal lane coordinate.

Parameters

longitudinal – longitudinal lane coordinate [m]

Returns

the lane width [m]

on_lane(position: numpy.ndarray, longitudinal: float = None, lateral: float = None, margin: float = 0) → bool[source]

Whether a given world position is on the lane.

Parameters
  • position – a world position [m]

  • longitudinal – (optional) the corresponding longitudinal lane coordinate, if known [m]

  • lateral – (optional) the corresponding lateral lane coordinate, if known [m]

  • margin – (optional) a supplementary margin around the lane width

Returns

is the position on the lane?

is_reachable_from(position: numpy.ndarray) → bool[source]

Whether the lane is reachable from a given world position

Parameters

position – the world position [m]

Returns

is the lane reachable?

after_end(position: numpy.ndarray, longitudinal: float = None, lateral: float = None) → bool[source]
distance(position)[source]

Compute the L1 distance [m] from a position to the lane.

__annotations__ = {'DEFAULT_WIDTH': <class 'float'>, 'VEHICLE_LENGTH': <class 'float'>, 'length': <class 'float'>, 'line_types': typing.List[ForwardRef('LineType')]}
__dict__ = mappingproxy({'__module__': 'highway_env.road.lane', '__annotations__': {'DEFAULT_WIDTH': <class 'float'>, 'VEHICLE_LENGTH': <class 'float'>, 'length': <class 'float'>, 'line_types': typing.List[ForwardRef('LineType')]}, '__doc__': 'A lane on the road, described by its central curve.', 'metaclass__': <class 'abc.ABCMeta'>, 'DEFAULT_WIDTH': 4, 'VEHICLE_LENGTH': 5, 'length': 0, 'position': <function AbstractLane.position>, 'local_coordinates': <function AbstractLane.local_coordinates>, 'heading_at': <function AbstractLane.heading_at>, 'width_at': <function AbstractLane.width_at>, 'on_lane': <function AbstractLane.on_lane>, 'is_reachable_from': <function AbstractLane.is_reachable_from>, 'after_end': <function AbstractLane.after_end>, 'distance': <function AbstractLane.distance>, '__dict__': <attribute '__dict__' of 'AbstractLane' objects>, '__weakref__': <attribute '__weakref__' of 'AbstractLane' objects>})
__module__ = 'highway_env.road.lane'
__weakref__

list of weak references to the object (if defined)

class highway_env.road.lane.LineType[source]

A lane side line type.

NONE = 0
STRIPED = 1
CONTINUOUS = 2
CONTINUOUS_LINE = 3
__dict__ = mappingproxy({'__module__': 'highway_env.road.lane', '__doc__': 'A lane side line type.', 'NONE': 0, 'STRIPED': 1, 'CONTINUOUS': 2, 'CONTINUOUS_LINE': 3, '__dict__': <attribute '__dict__' of 'LineType' objects>, '__weakref__': <attribute '__weakref__' of 'LineType' objects>})
__module__ = 'highway_env.road.lane'
__weakref__

list of weak references to the object (if defined)

class highway_env.road.lane.StraightLane(start: Union[numpy.ndarray, Sequence[float]], end: Union[numpy.ndarray, Sequence[float]], width: float = 4, line_types: Tuple[highway_env.road.lane.LineType, highway_env.road.lane.LineType] = None, forbidden: bool = False, speed_limit: float = 20, priority: int = 0)[source]

A lane going in straight line.

__init__(start: Union[numpy.ndarray, Sequence[float]], end: Union[numpy.ndarray, Sequence[float]], width: float = 4, line_types: Tuple[highway_env.road.lane.LineType, highway_env.road.lane.LineType] = None, forbidden: bool = False, speed_limit: float = 20, priority: int = 0) → None[source]

New straight lane.

Parameters
  • start – the lane starting position [m]

  • end – the lane ending position [m]

  • width – the lane width [m]

  • line_types – the type of lines on both sides of the lane

  • forbidden – is changing to this lane forbidden

  • priority – priority level of the lane, for determining who has right of way

line_types = None
position(longitudinal: float, lateral: float) → numpy.ndarray[source]

Convert local lane coordinates to a world position.

Parameters
  • longitudinal – longitudinal lane coordinate [m]

  • lateral – lateral lane coordinate [m]

Returns

the corresponding world position [m]

heading_at(longitudinal: float) → float[source]

Get the lane heading at a given longitudinal lane coordinate.

Parameters

longitudinal – longitudinal lane coordinate [m]

Returns

the lane heading [rad]

width_at(longitudinal: float) → float[source]

Get the lane width at a given longitudinal lane coordinate.

Parameters

longitudinal – longitudinal lane coordinate [m]

Returns

the lane width [m]

local_coordinates(position: numpy.ndarray) → Tuple[float, float][source]

Convert a world position to local lane coordinates.

Parameters

position – a world position [m]

Returns

the (longitudinal, lateral) lane coordinates [m]

__module__ = 'highway_env.road.lane'
class highway_env.road.lane.SineLane(start: Union[numpy.ndarray, Sequence[float]], end: Union[numpy.ndarray, Sequence[float]], amplitude: float, pulsation: float, phase: float, width: float = 4, line_types: List[highway_env.road.lane.LineType] = None, forbidden: bool = False, speed_limit: float = 20, priority: int = 0)[source]

A sinusoidal lane.

__init__(start: Union[numpy.ndarray, Sequence[float]], end: Union[numpy.ndarray, Sequence[float]], amplitude: float, pulsation: float, phase: float, width: float = 4, line_types: List[highway_env.road.lane.LineType] = None, forbidden: bool = False, speed_limit: float = 20, priority: int = 0) → None[source]

New sinusoidal lane.

Parameters
  • start – the lane starting position [m]

  • end – the lane ending position [m]

  • amplitude – the lane oscillation amplitude [m]

  • pulsation – the lane pulsation [rad/m]

  • phase – the lane initial phase [rad]

position(longitudinal: float, lateral: float) → numpy.ndarray[source]

Convert local lane coordinates to a world position.

Parameters
  • longitudinal – longitudinal lane coordinate [m]

  • lateral – lateral lane coordinate [m]

Returns

the corresponding world position [m]

heading_at(longitudinal: float) → float[source]

Get the lane heading at a given longitudinal lane coordinate.

Parameters

longitudinal – longitudinal lane coordinate [m]

Returns

the lane heading [rad]

local_coordinates(position: numpy.ndarray) → Tuple[float, float][source]

Convert a world position to local lane coordinates.

Parameters

position – a world position [m]

Returns

the (longitudinal, lateral) lane coordinates [m]

__module__ = 'highway_env.road.lane'
line_types = None
class highway_env.road.lane.CircularLane(center: Union[numpy.ndarray, Sequence[float]], radius: float, start_phase: float, end_phase: float, clockwise: bool = True, width: float = 4, line_types: List[highway_env.road.lane.LineType] = None, forbidden: bool = False, speed_limit: float = 20, priority: int = 0)[source]

A lane going in circle arc.

__init__(center: Union[numpy.ndarray, Sequence[float]], radius: float, start_phase: float, end_phase: float, clockwise: bool = True, width: float = 4, line_types: List[highway_env.road.lane.LineType] = None, forbidden: bool = False, speed_limit: float = 20, priority: int = 0) → None[source]

Initialize self. See help(type(self)) for accurate signature.

line_types = None
position(longitudinal: float, lateral: float) → numpy.ndarray[source]

Convert local lane coordinates to a world position.

Parameters
  • longitudinal – longitudinal lane coordinate [m]

  • lateral – lateral lane coordinate [m]

Returns

the corresponding world position [m]

heading_at(longitudinal: float) → float[source]

Get the lane heading at a given longitudinal lane coordinate.

Parameters

longitudinal – longitudinal lane coordinate [m]

Returns

the lane heading [rad]

width_at(longitudinal: float) → float[source]

Get the lane width at a given longitudinal lane coordinate.

Parameters

longitudinal – longitudinal lane coordinate [m]

Returns

the lane width [m]

local_coordinates(position: numpy.ndarray) → Tuple[float, float][source]

Convert a world position to local lane coordinates.

Parameters

position – a world position [m]

Returns

the (longitudinal, lateral) lane coordinates [m]

__module__ = 'highway_env.road.lane'