smarts.core.road_map module

class smarts.core.road_map.RoadMap[source]

Base class from which map implementation classes extend.

class Feature[source]

Describes a map feature.

property feature_id: str

The identifier for this feature.

property geometry: List[Point]

The geometry that represents this feature.

property is_dynamic: bool

True if this feature has dynamic state (such as a traffic light); False otherwise.

min_dist_from(point: Point) float[source]

Returns the euclidean (as-the-crow-flies) distance between point and the nearest part of this feature.

property type: FeatureType

The type of this feature.

property type_as_str: str

The type of this feature as a string. This is useful for resolving CUSTOM feature types.

property type_specific_info: Any | None

Can be anything specific to the feature type; defaults to None.

class FeatureType(value)[source]

Built-in feature types usable across all map implementations.

CROSSWALK = 1
CUSTOM = 6
FIXED_LOC_SIGNAL = 5
ROAD_SIGN = 4
SPEED_BUMP = 2
STOP_SIGN = 3
UNKNOWN = 0
class Lane[source]

Describes a lane surface.

property bounding_box

Gets the lane bounding box.

center_at_point(point: Point) Point[source]

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

center_pose_at_point(point: Point) Pose[source]

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

property composite_lane: Lane

Return an abstract Lane composed of one or more RoadMap.Lane segments (including this one) that has been inferred to correspond to one continuous real-world lane. May return same object as self.

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 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.

from_lane_coord(lane_point: RefLinePoint) Point[source]

Get a world point on the lane from the given lane coordinate point.

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_composite: bool

Return True if this Lane object was inferred and composed out of subordinate Lane objects.

property lane_id: str

Unique identifier for this Lane.

property lane_to_left: Tuple[Lane, 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, 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.

offset_along_lane(world_point: Point) float[source]

Get the offset of the given point imposed on 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.

property speed_limit: float | None

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

to_lane_coord(world_point: Point) RefLinePoint[source]

Convert from the given world coordinate to a lane coordinate point.

vector_at_offset(start_offset: float) ndarray[source]

The lane direction vector at the given offset (not normalized).

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(offset: 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[source]

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

property composite_road: Road

Return an abstract Road composed of one or more RoadMap.Road segments (including this one) that has been inferred to correspond to one continuous real-world road. May return same object as self.

property incoming_roads: List[Road]

All roads that lead into this road.

property is_composite: bool

Returns True if this Road object was inferred and composed out of subordinate Road objects.

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.

property type: int

The type of this road.

property type_as_str: str

The type of this road.

class Route[source]

Describes a route between two roads.

class RouteLane(lane: Lane, road_index: int | None = None)[source]

A Lane within a Route.

lane: Lane
road_index: int | None = None
class RoutePoint(pt: Point, road_index: int | None = None)[source]

A Point within a Route.

pt: Point
road_index: int | None = None
distance_between(start: RoutePoint, end: RoutePoint) float[source]

Distance along route between two points.

distance_from(cur_lane: RouteLane, route_road: RoadMap.Road | None = None) float | None[source]

Returns the distance along the route from the beginning of the current lane to the beginning of the next occurrence of route_road, or if route_road is None, then to the end of the route.

property end_lane: Lane | None

Route’s end lane.

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

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

next_junction(cur_lane: RouteLane, offset: float) Tuple[RoadMap.Lane | None, float][source]

Returns a lane within the next junction along the route from beginning of the current lane to the returned lane it connects with in the junction, and the distance to it from this offset, or (None, inf) if there aren’t any.

project_along(start: RoutePoint, distance: float) Set[Tuple[RoadMap.Lane, float]][source]

Starting at point on the route, returns a set of possible locations (lane and offset pairs) further along the route that are distance away, not including lane changes.

property road_ids: List[str]

A possibly-unordered list of road-ids that this route covers

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

property start_lane: Lane | None

Route’s start lane.

class Surface[source]

Describes a surface.

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 features: List[Feature]

The features that this surface contains.

features_near(pose: Pose, radius: float) List[Feature][source]

The features on this surface near the given pose.

property is_drivable: bool

Returns true if this surface is legally and physically drivable.

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 surface_id: str

The unique identifier for a surface.

property bounding_box: BoundingBox | None

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

property dynamic_features: List[Feature]

All dynamic features associated with this road map.

dynamic_features_near(point: Point, radius: float) List[Tuple[Feature, float]][source]

Find features within radius meters of the given point.

empty_route() Route[source]

Generate an empty route.

feature_by_id(feature_id: str) Feature | None[source]

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

generate_routes(start: RoadMap.Road | RoadMap.Lane, end: RoadMap.Road | RoadMap.Lane, via: Sequence[Road] | None = None, max_to_gen: int = 1) List[Route][source]

Generates routes between two roads. :param start: The beginning road or lane of the generated routes. :param end: The end road or lane of the generated routes. :param via: All edges that the generated routes must pass through. :param max_to_gen: The maximum number of routes to generate.

Returns:

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

property has_overpasses: bool

Whether the map has lanes with overlapping z-coordinates.

is_same_map(map_spec) bool[source]

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

lane_by_id(lane_id: str) Lane | None[source]

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

property map_spec

The map spec that could be used to reconstruct the map.

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

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

nearest_lanes(point: Point, radius: float | None = None, include_junctions=True) 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.

nearest_surfaces(point: Point, radius: float | None = None) List[Tuple[Surface, float]][source]

Find surfaces (lanes, roads, etc.) on this road map that are near the given point.

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

Generate a random route contained in this road map.

Parameters:
  • max_route_len – The total number of roads in the route.

  • starting_road – If specified, the route will start with this road.

  • only_drivable – If True, will restrict the route to only drive-able roads; otherwise can incl. non-drivable roads (such as bike lanes) too.

Returns:

A randomly generated route.

road_by_id(road_id: str) Road | None[source]

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

road_with_point(point: Point, *, lanes_to_search: Sequence[RoadMap.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 scale_factor: float

The ratio between 1 unit on the map and 1 meter.

property source: str

The road map resource source. Generally a file URI.

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: str)[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.

class smarts.core.road_map.RoadMapWithCaches[source]

Base class for map implementations that wish to include a built-in SegmentCache and other LRU caches.

class Lane(lane_id: str, road_map)[source]

Describes a RoadMapWithCaches lane surface.

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.

from_lane_coord(lane_point: RefLinePoint) Point[source]

Get a world point on the lane from the given lane coordinate point.

offset_along_lane(world_point: Point) float[source]

Get the offset of the given point imposed on this lane.

to_lane_coord(world_point: Point) RefLinePoint[source]

Convert from the given world coordinate to a lane coordinate point.

vector_at_offset(offset: float) ndarray[source]

The lane direction vector at the given offset (not normalized).

class smarts.core.road_map.Waypoint(pos: ndarray, heading: Heading, lane_id: str, lane_width: float, speed_limit: float, lane_index: int, lane_offset: float)[source]

Dynamic, based on map and vehicle. Waypoints start abreast of (or near) a vehicle’s present location in the nearest Lane and are evenly spaced. These are returned through a vehicle’s sensors.

dist_to(p) float[source]

Calculates straight line distance to the given 2D point

heading: Heading

Heading angle of lane at this point. Units=rad

lane_id: str

Globally unique identifier of lane under waypoint.

lane_index: int

Index of the lane under this waypoint. Right most lane has index 0 and index increases to the left.

lane_offset: float

Longitudinal distance along lane center-line of this waypoint.

lane_width: float

Width of lane at this point. Units=meters

pos: ndarray

Point positioned on lane center.

property position

The position of the waypoint.

relative_heading(h: Heading) Heading[source]

Computes relative heading between the given angle and the waypoint heading

Returns:

Relative heading in [-pi, pi].

Return type:

float

signed_lateral_error(p) float[source]

Returns the signed lateral distance from the given point to the line formed by the waypoint position and the waypoint heading.

Negative signals right of line and Positive left of line.

speed_limit: float

Lane speed. Units=m/s

smarts.core.road_map.interpolate_waypoints(first_waypoint: Waypoint, second_waypoint: Waypoint, start_relative_offset: float, interval: float) Tuple[List[Waypoint], float][source]

Generate intermediary waypoints between the given waypoints.

Parameters:
  • first_waypoint (Waypoint) – The initial start waypoint.

  • second_waypoint (Waypoint) – The initial end waypoint.

  • start_relative_offset (float) – The starting offset to generate the first waypoint.

  • interval (float) – The interval to generate the waypoints at.

Returns:

The resulting waypoints and the used offset

Return type:

Tuple[List[Waypoint], float]