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: float | None = None, lateral: float | None = 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?
- class highway_env.road.lane.StraightLane(start: ndarray | Sequence[float], end: ndarray | Sequence[float], width: float = AbstractLane.DEFAULT_WIDTH, line_types: tuple[LineType, LineType] | None = None, forbidden: bool = False, speed_limit: float = 20, priority: int = 0)[source]¶
A lane going in straight line.
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
- 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]
- class highway_env.road.lane.SineLane(start: ndarray | Sequence[float], end: ndarray | Sequence[float], amplitude: float, pulsation: float, phase: float, width: float = StraightLane.DEFAULT_WIDTH, line_types: list[LineType] | None = None, forbidden: bool = False, speed_limit: float = 20, priority: int = 0)[source]¶
A sinusoidal lane.
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) 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]
- class highway_env.road.lane.CircularLane(center: ndarray | Sequence[float], radius: float, start_phase: float, end_phase: float, clockwise: bool = True, width: float = AbstractLane.DEFAULT_WIDTH, line_types: list[LineType] | None = 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]
- class highway_env.road.lane.PolyLaneFixedWidth(lane_points: list[tuple[float, float]], width: float = AbstractLane.DEFAULT_WIDTH, line_types: tuple[LineType, LineType] | None = 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]
- 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: tuple[LineType, LineType] | None = 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.