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 ABCMeta

abstract position(longitudinal: float, lateral: float) 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: 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]

classmethod from_config(config: dict)[source]

Create lane instance from config

Parameters

config – json dict with lane parameters

abstract to_config() dict[source]

Write lane parameters to dict which can be serialized to json

Returns

dict of lane parameters

on_lane(position: ndarray, longitudinal: Optional[float] = None, lateral: Optional[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: ndarray) bool[source]

Whether the lane is reachable from a given world position

Parameters

position – the world position [m]

Returns

is the lane reachable?

distance(position: ndarray)[source]

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

distance_with_heading(position: ndarray, heading: Optional[float], heading_weight: float = 1.0)[source]

Compute a weighted distance in position and heading to the lane.

local_angle(heading: float, long_offset: float)[source]

Compute non-normalised angle of heading to the lane.

class highway_env.road.lane.LineType[source]

A lane side line type.

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

A lane going in straight line.

position(longitudinal: float, lateral: float) 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: 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]

classmethod from_config(config: dict)[source]

Create lane instance from config

Parameters

config – json dict with lane parameters

to_config() dict[source]

Write lane parameters to dict which can be serialized to json

Returns

dict of lane parameters

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

A sinusoidal lane.

position(longitudinal: float, lateral: float) 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: 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]

classmethod from_config(config: dict)[source]

Create lane instance from config

Parameters

config – json dict with lane parameters

to_config() dict[source]

Write lane parameters to dict which can be serialized to json

Returns

dict of lane parameters

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

A lane going in circle arc.

position(longitudinal: float, lateral: float) 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: 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]

classmethod from_config(config: dict)[source]

Create lane instance from config

Parameters

config – json dict with lane parameters

to_config() dict[source]

Write lane parameters to dict which can be serialized to json

Returns

dict of lane parameters

class highway_env.road.lane.PolyLaneFixedWidth(lane_points: List[Tuple[float, float]], width: float = 4, line_types: Optional[Tuple[LineType, LineType]] = None, forbidden: bool = False, speed_limit: float = 20, priority: int = 0)[source]

A fixed-width lane defined by a set of points and approximated with a 2D Hermite polynomial.

position(longitudinal: float, lateral: float) 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]

local_coordinates(position: 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]

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]

classmethod from_config(config: dict)[source]

Create lane instance from config

Parameters

config – json dict with lane parameters

to_config() dict[source]

Write lane parameters to dict which can be serialized to json

Returns

dict of lane parameters

class highway_env.road.lane.PolyLane(lane_points: List[Tuple[float, float]], left_boundary_points: List[Tuple[float, float]], right_boundary_points: List[Tuple[float, float]], line_types: Optional[Tuple[LineType, LineType]] = None, forbidden: bool = False, speed_limit: float = 20, priority: int = 0)[source]

A lane defined by a set of points and approximated with a 2D Hermite polynomial.

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]

to_config() dict[source]

Write lane parameters to dict which can be serialized to json

Returns

dict of lane parameters