igp2.opendrive package

Subpackages

Submodules

igp2.opendrive.map module

class igp2.opendrive.map.Map(opendrive: OpenDrive | None = None)[source]

Bases: object

Define a map object based on the OpenDrive standard

JUNCTION_PRECISION_ERROR = 1e-08
LANE_PRECISION_ERROR = 1e-08
ROAD_PRECISION_ERROR = 1e-08
adjacent_lanes_at(point: Point | Tuple[float, float] | ndarray, heading: float | None = None, same_direction: bool = False, drivable_only: bool = False) List[Lane][source]

Return all adjacent lanes on the same Road at the given point and heading.

Parameters:
  • point – Point in cartesian coordinates

  • heading – Heading in radians

  • same_direction – If True, only return lanes in the same direction as the current Lane

  • drivable_only – If True, only return a Lane if it is drivable

Returns:

A list of all adjacent Lane objects on the same Road

best_lane_at(point: Point | Tuple[float, float] | ndarray, heading: float = None, drivable_only: bool = True, max_distance: float = None, goal: Goal = None) Lane | None[source]

Get the lane at the given point whose direction is closest to the given heading and whose distance from the point is the smallest.

Parameters:
  • point – Point in cartesian coordinates

  • heading – Heading in radians

  • drivable_only – If True, only return a Lane if it is drivable

  • max_distance – Maximum error in distance calculations

  • goal – If given, the road on which the best lane will be is chosen based on its distance from the goal

Returns:

A Lane passing through point with its direction closest to the given heading, or None.

best_road_at(point: Point | Tuple[float, float] | ndarray, heading: float = None, drivable: bool = True, goal: Goal = None) Road | None[source]

Get the road at the given point with the closest direction to heading. If no heading is given, then select the first viable road.

Parameters:
  • point – Point in cartesian coordinates

  • heading – Heading in radians

  • drivable – Whether only to consider roads that have drivable lanes

  • goal – If given, the best road is chosen based on its distance from the goal

Returns:

A Road passing through point with its direction closest to the given heading, or None.

property date: str

Date when the map was created

property east: float

East boundary of the map

property geo_reference: str

Geo-reference parameters for geo-location

get_adjacent_lanes(current_lane: Lane, same_direction: bool = True, drivable_only: bool = True) List[Lane][source]

Return all adjacent lanes of the given lane.

Parameters:
  • current_lane – The current lane

  • same_direction – If True, only return lanes that have the same direction as the given lane

  • drivable_only – If True, only return drivable lanes

Returns:

List of adjacent lanes

get_lane(road_id: int, lane_id: int, lane_section_idx: int = 0) Lane[source]

Get a certain lane given the road id and lane id from the given lane section.

Parameters:
  • road_id – Road ID of the road containing the lane

  • lane_id – Lane ID of lane to look up

  • lane_section_idx – The index of the lane section to look-up

Returns:

Lane

in_roundabout(point: Point | Tuple[float, float] | ndarray, heading: float | None = None) bool[source]

Determines whether the vehicle is currently in a roundabout. A roundabout road is either a connector road in a junction with a junction group of type ‘roundabout’ - that is, it is neither an exit from or entry into the roundabout - or it is a road whose predecessor and successor are both in the same roundabout junction group.

Parameters:
  • point – Point in cartesian coordinates

  • heading – Heading in radians

Returns:

True if the vehicle is one a road in a roundabout.

is_valid()[source]

Checks if the Map geometry is valid.

junction_at(point: Point | Tuple[float, float] | ndarray) Junction | None[source]

Get the Junction at a given point within an error given by Map.JUNCTION_PRECISION_ERROR

Parameters:

point – Location to check in cartesian coordinates

Returns:

A Junction object or None

property junction_groups: Dict[int, JunctionGroup]
junction_predecessor_lanes(lane: Lane, in_roundabout: bool = False) List[Lane][source]

Retrieve all predecessor lanes of a lane if the predecessor of the parent road is a junction.

Parameters:
  • lane – The lane to check.

  • in_roundabout – Whether to only check a junction if it is in a roundabout.

property junctions: Dict[int, Junction]
lanes_at(point: Point | Tuple[float, float] | ndarray, drivable_only: bool = False, max_distance: float | None = None) List[Lane][source]

Return all lanes passing through the given point within an error given by Map.LANE_PRECISION_ERROR. The default error is 1.5

Parameters:
  • point – Point in cartesian coordinates

  • drivable_only – If True, only return drivable lanes

  • max_distance – Maximum distance error

Returns:

A list of all viable lanes or empty list

lanes_within_angle(point: Point | Tuple[float, float] | ndarray, heading: float, threshold: float, drivable_only: bool = True, max_distance: float | None = None) List[Lane][source]

Return a list of Lanes whose angular distance from the given heading is within the given threshold and whose distance from the point is within an error as given by Map.LANE_PRECISION_ERROR.

Parameters:
  • point – Point in cartesian coordinates

  • heading – Heading in radians

  • threshold – The threshold in radians

  • drivable_only – If True, only return a Lane if it is drivable

  • max_distance – Maximum error in lane distance calculations

Returns:

List of Lanes

property name: str

Name for the map

property north: float

North boundary of the map

classmethod parse_from_opendrive(file_path: str)[source]

Parse the OpenDrive file and create a new Map instance

Parameters:

file_path – The absolute/relative path to the OpenDrive file

Returns:

A new instance of the Map class

road_in_roundabout(road: Road, iters: int = 7) bool[source]

Calculate whether a road is in a roundabout. A roundabout road is either a connector road in a junction with a junction group of type ‘roundabout’ - that is, it is neither an exit from or entry into the roundabout - or it is a road whose predecessor and successor are both in the same roundabout junction group.

Parameters:
  • road – The Road to check

  • iters – The number of successor roads to check around the roundabout before throwing an error

Returns:

True if the road is part of a roundabout

property roads: Dict[int, Road]

Dictionary of all roads in the map with keys the road IDs

roads_at(point: Point | Tuple[float, float] | ndarray, drivable: bool = False, max_distance: float | None = None) List[Road][source]

Find all roads that pass through the given point within an error given by Map.ROAD_PRECISION_ERROR. The default error is 1e-8.

Parameters:
  • point – Point in cartesian coordinates

  • drivable – Whether the returned roads need to be drivable

  • max_distance – Maximum distance error

Returns:

A list of all viable roads or empty list

roads_within_angle(point: Point | Tuple[float, float] | ndarray, heading: float, threshold: float, max_distance: float | None = None) List[Road][source]

Return a list of Roads whose angular distance from the given heading is within the given threshold. If only one road is available at the given point, then always return that regardless of angle difference. If point is within a junction, then check against all roads of the junction.

Parameters:
  • point – Point in cartesian coordinates

  • heading – Heading in radians

  • threshold – The threshold in radians

  • max_distance – Maximum error in lane distance calculations

Returns:

List of Roads

property south: float

South boundary of the map

property west: float

West boundary of the map

property xodr_path

igp2.opendrive.parser module

igp2.opendrive.parser.calculate_lane_section_lengths(new_road)[source]
igp2.opendrive.parser.parse_opendrive(root_node) OpenDrive[source]

Tries to parse XML tree, returns OpenDRIVE object

Parameters:

root_node – The root node of a parsed OpenDrive XML tree

Returns:

The object representing an OpenDrive specification.

igp2.opendrive.parser.parse_opendrive_header(opendrive, header)[source]
igp2.opendrive.parser.parse_opendrive_junction(opendrive, junction)[source]
igp2.opendrive.parser.parse_opendrive_junction_group(opendrive, junction_group)[source]
igp2.opendrive.parser.parse_opendrive_road(opendrive, road)[source]
igp2.opendrive.parser.parse_opendrive_road_elevation_profile(new_road, road_elevation_profile)[source]
igp2.opendrive.parser.parse_opendrive_road_geometry(new_road, road_geometry)[source]
igp2.opendrive.parser.parse_opendrive_road_lane_offset(new_road, lane_offset)[source]
igp2.opendrive.parser.parse_opendrive_road_lane_section(new_road, lane_section_id, lane_section, program=None)[source]
igp2.opendrive.parser.parse_opendrive_road_lateral_profile(new_road, road_lateral_profile)[source]
igp2.opendrive.parser.parse_opendrive_road_type(road, opendrive_xml_road_type: ElementTree)[source]

Parse opendrive road type and append to road object.

Parameters:
  • road – Road to append the parsed road_type to types.

  • opendrive_xml_road_type – XML element which contains the information.

  • opendrive_xml_road_type – etree.ElementTree:

igp2.opendrive.plot_map module

igp2.opendrive.plot_map.plot_map(odr_map: Map, ax: Axes | None = None, scenario_config=None, **kwargs) Axes[source]

Draw the road layout of the map :param odr_map: The Map to plot :param ax: Axes to draw on :param scenario_config: Scenario configuration

Keyword Arguments:
  • midline – True if the midline of roads should be drawn (default: False)

  • midline_direction – Whether to show directed arrows for the midline (default: False)

  • road_ids – If True, then the IDs of roads will be drawn (default: False)

  • markings – If True, then draw LaneMarkers (default: False)

  • road_color – Plot color of the road boundary (default: black)

  • junction_color – Face color of junctions (default: [0.941, 1.0, 0.420, 0.5])

  • midline_color – Color of the midline

  • plot_background – If true, plot the background image. scenario_config must be given

  • plot_buildings – If true, plot the buildings in the map. scenario_config must be given

  • plot_goals – If true, plot the possible goals for that scenario. scenario_config must be given

  • ignore_roads – If true, we don’t plot the road lines/junctions.

  • drivable – Whether only drivable lanes would be plotted.

  • hide_road_bounds_in_junction – If true, then hide road black boundaries in junctions.

Returns:

The axes onto which the road layout was drawn

Module contents