smarts.core.opendrive_road_network module

class smarts.core.opendrive_road_network.LaneBoundary(refline: opendrive2lanelet.opendriveparser.elements.roadPlanView.PlanView, inner: LaneBoundary | None, lane_widths: List[opendrive2lanelet.opendriveparser.elements.roadLanes.LaneWidth], lane_offsets: List[opendrive2lanelet.opendriveparser.elements.roadLanes.LaneOffset], segment_size: float = 0.5)[source]

Describes a lane boundary.

calc_t(s: float, section_s_start: float, lane_idx: int) float[source]

Used to evaluate lane boundary shape.

get_lane_offset(s: float) float[source]

Get the lane offset for this boundary at a given s value.

inner: LaneBoundary | None
lane_offsets: List[opendrive2lanelet.opendriveparser.elements.roadLanes.LaneOffset]
lane_width_at_offset(offset: float) opendrive2lanelet.opendriveparser.elements.roadLanes.LaneWidth[source]

Get the lane width at the given offset.

lane_widths: List[opendrive2lanelet.opendriveparser.elements.roadLanes.LaneWidth]
refline: opendrive2lanelet.opendriveparser.elements.roadPlanView.PlanView
refline_to_linear_segments(s_start: float, s_end: float) List[float][source]

Get segment offsets between the given offsets.

segment_size: float = 0.5
to_linear_segments(s_start: float, s_end: float) List[float][source]

Convert from lane boundary shape to linear segments.

class smarts.core.opendrive_road_network.OpenDriveRoadNetwork(xodr_file: str, map_spec: MapSpec, default_lane_speed=None)[source]

A road map for an OpenDRIVE source.

DEFAULT_LANE_SPEED = 16.67
DEFAULT_LANE_WIDTH = 3.7
class Lane(road_map, lane_id: str, road: Road, index: int, length: float, is_drivable: bool, speed_limit: float, road_plan_view: opendrive2lanelet.opendriveparser.elements.roadPlanView.PlanView)[source]

Describes an OpenDRIVE lane.

property bounding_box: BoundingBox

Get the minimal axis aligned bounding box that contains all geometry in this lane.

center_at_point(point: Point) Point[source]

Get the ‘center’ of the lane closest to the given world coordinate.

property center_polyline: List[Point]

Should return a list of the points along the center-line of the lane, in the order they will be encountered in the direction of travel.

Note: not all map types will be able to implement this method, so use with care. This was added to support those that wish to make use of the SegmentCache class below.

center_pose_at_point(point: Point) Pose[source]

The pose at the center of the lane closest to the given point.

contains_point(point: Point) bool[source]

Returns True if this point is fully contained by this surface. For some regions of some maps, it may not be possible to determine this. In such indeterminate cases, it is recommended to return True.

curvature_radius_at_offset(offset: float, lookahead: int = 5) float[source]

lookahead (in meters) is the size of the window to use to compute the curvature, which must be at least 1 to make sense. This may return math.inf if the lane is straight.

property entry_surfaces: List[Surface]

Surfaces by which one might enter this surface.

property exit_surfaces: List[Surface]

Surfaces by which one might exit this surface.

property foes: List[Lane]

All lanes that in some ways intersect with (cross) this one, including those that have the same outgoing lane as this one, and so might require right-of-way rules. This should only ever happen in junctions.

property in_junction: bool

If this lane is a part of a junction (usually an intersection.)

property incoming_lanes: List[Lane]

Lanes leading into this lane.

property index: int

when not in_junction, 0 is outer / right-most (relative to lane heading) lane on road. otherwise, index scheme is implementation-dependent, but must be deterministic.

property is_drivable: bool

Returns true if this surface is legally and physically drivable.

property lane_id: str

Unique identifier for this Lane.

property lane_polygon: List[Tuple[float, float]]

A list of polygons that describe the shape of the lane.

property lane_to_left: Tuple[Lane | None, bool]

Get the parallel lane to the left side of the direction this current lane.

Note

Left is defined as 90 degrees clockwise relative to the lane heading. (I.e., positive t in the RefLine coordinate system.) Second result is True if lane is in the same direction as this one In junctions, diverging lanes should not be included.

property lane_to_right: Tuple[Lane | None, bool]

Get the parallel lane to the right side of the direction this current lane.

Note

Right is defined as 90 degrees counter-clockwise relative to the lane heading. (I.e., negative t in the RefLine coordinate system.) Second result is True if lane is in the same direction as this one. In junctions, diverging lanes should not be included.

property lanes_in_same_direction: List[Lane]

returns all other lanes on this road where traffic goes in the same direction. it is currently assumed these will be adjacent to one another. In junctions, diverging lanes should not be included.

property length: float

The length of this lane.

oncoming_lanes_at_offset(offset: float) List[Lane][source]

Returns a list of nearby lanes at offset that are (roughly) parallel to this one but go in the opposite direction.

property outgoing_lanes: List[Lane]

Lanes leading out of this lane.

project_along(start_offset: float, distance: float) Set[Tuple[Lane, float]][source]

Starting at start_offset along the lane, project locations (lane, offset tuples) reachable within distance, not including lane changes.

property road: Road

The road that this lane is a part of.

shape(buffer_width: float = 0.0, default_width: float | None = None) Polygon[source]

Returns a convex polygon representing this surface, buffered by buffered_width (which must be non-negative), where buffer_width is a buffer around the perimeter of the polygon. In some situations, it may be desirable to also specify a default_width, in which case the returned polygon should have a convex shape where the distance across it is no less than buffered_width + default_width at any point.

property speed_limit: float | None

The speed limit on this lane. May be None if not defined.

waypoint_paths_at_offset(offset: float, lookahead: int = 30, route: Route | None = None) List[List[Waypoint]][source]

Computes equally-spaced Waypoints for all lane paths up to lookahead waypoints ahead, starting offset into this lane. Constrains paths to the supplied route if specified.

waypoint_paths_for_pose(pose: Pose, lookahead: int, route: Route | None = None) List[List[Waypoint]][source]

Computes equally-spaced Waypoints for all lane paths up to lookahead waypoints ahead, starting in this lane at pose. Constrains paths to the supplied route if specified.

width_at_offset(lane_point_s: float) Tuple[float, float][source]

Get the width of the lane at the given offset as well as a measure of certainty in this width between 0 and 1.0, where 1 indicates that the width is exact and certain, and 0 indicates a width estimate with no confidence.

class Road(road_map, road_id: str, is_junction: bool, length: float, start_pos: float, total_lanes: int)[source]

This is akin to a ‘road segment’ in real life. Many of these might correspond to a single named road in reality.

property bounding_box: BoundingBox | None

Get the minimal axis aligned bounding box that contains all road geometry.

contains_point(point: Point) bool[source]

Returns True if this point is fully contained by this surface. For some regions of some maps, it may not be possible to determine this. In such indeterminate cases, it is recommended to return True.

property entry_surfaces: List[Surface]

Surfaces by which one might enter this surface.

property exit_surfaces: List[Surface]

Surfaces by which one might exit this surface.

property incoming_roads: List[Road]

All roads that lead into this road.

property is_drivable: bool

Returns true if this surface is legally and physically drivable.

property is_junction: bool

Note that a junction can be an intersection (‘+’) or a ‘T’, ‘Y’, ‘L’, etc.

lane_at_index(index: int) Lane[source]

Gets the lane with the given index.

property lanes: List[Lane]

The lanes contained in this road.

property length: float

The length of this road.

oncoming_roads_at_point(point: Point) List[Road][source]

Returns a list of nearby roads to point that are (roughly) parallel to this one but have lanes that go in the opposite direction.

property outgoing_roads: List[Road]

All roads that lead out of this road.

property parallel_roads: List[Road]

Returns roads that start and end at the same point as this one.

property road_id: str

The identifier for this road.

shape(buffer_width: float = 0.0, default_width: float | None = None) Polygon[source]

Returns a convex polygon representing this surface, buffered by buffered_width (which must be non-negative), where buffer_width is a buffer around the perimeter of the polygon. In some situations, it may be desirable to also specify a default_width, in which case the returned polygon should have a convex shape where the distance across it is no less than buffered_width + default_width at any point.

class Route(road_map: RoadMap, roads: List[Road] = [], start_lane: Lane | None = None, end_lane: Lane | None = None)[source]

Describes a route between two OpenDRIVE roads.

property geometry: Sequence[Sequence[Tuple[float, float]]]

A sequence of polygon vertices describing the shape of each road on the route

property road_length: float

The total road length of this route.

property roads: List[Road]

A possibly-unordered list of roads that this route covers

SPEED_CONVERSION = {'km/h': 0.27778, 'm/s': 1.0, 'mph': 0.44704}
class Surface(surface_id: str, road_map)[source]

Describes an OpenDRIVE surface.

property is_drivable: bool

Returns true if this surface is legally and physically drivable.

property surface_id: str

The unique identifier for a surface.

property bounding_box: BoundingBox

The minimum bounding box that contains the map geometry. May return None to indicate the map is unbounded.

empty_route() Route[source]

Generate an empty route.

classmethod from_spec(map_spec: MapSpec)[source]

Generate a road network from the given specification.

is_same_map(map_spec: MapSpec) bool[source]

Check if the MapSpec Object source points to the same RoadMap instance as the current

lane_by_id(lane_id: str) Lane[source]

Find a lane in this road map that has the given identifier.

nearest_lane(point: Point, radius: float | None = None, include_junctions: bool = False) Lane | None[source]

Find the nearest lane on this road map to the given point.

nearest_lanes(point: Point, radius: float | None = None, include_junctions=False) List[Tuple[Lane, float]][source]

Find lanes on this road map that are near the given point. Returns a list of tuples of lane and distance, sorted by distance.

random_route(max_route_len: int = 10, starting_road: Road | None = None, only_drivable: bool = True) Route[source]
road_by_id(road_id: str) Road[source]

Find a road in this road map that has the given identifier.

road_with_point(point: Point, *, lanes_to_search: Sequence[Lane] | None = None) Road | None[source]

Find the road that contains the given point. :param point: The point to check. :param lanes_to_search: A sequence of lanes with their distances. If not provided, the nearest lanes will be used.

Returns:

A list of generated routes that satisfy the given restrictions. Routes will be returned in order of increasing length.

route_from_road_ids(road_ids: Sequence[str], resolve_intermediaries: bool = False) Route[source]

Generate a route containing the specified roads. :param road_ids: The road ids of the route. :type road_ids: Sequence[str] :param resolve_intermediaries: If to fill in the gaps in the route. This may be needed to complete an incomplete route or fill in junctions roads. :type resolve_intermediaries: bool

Returns:

A route that satisfies the given road id restrictions.

property source: str

This is the .xodr file of the OpenDRIVE map.

surface_by_id(surface_id: str) Surface | None[source]

Find a surface within the road map that has the given identifier.

to_glb(glb_dir)[source]

Build a .glb file for camera rendering and envision

waypoint_paths(pose: Pose, lookahead: int, within_radius: float = 5, route: Route | None = None) List[List[Waypoint]][source]

Computes equally-spaced Waypoints for all lane paths up to lookahead waypoints ahead, starting on the Road containing the nearest Lane aligned with the vehicle’s pose within within_radius meters. Constrains paths to the supplied route if specified.