smarts.env.custom_observations module

class smarts.env.custom_observations.Adapter(space: gymnasium.Space, transform: Callable)[source]

An adapter for pairing an action/observation transformation method with its gym space representation.

space: gymnasium.Space
transform: Callable
smarts.env.custom_observations.lane_ttc(obs: Observation | Dict) Dict[str, ndarray][source]

Computes time-to-collision (TTC) and distance-to-collision (DTC) using the given agent’s observation. TTC and DTC are numpy arrays of shape (3,) with values for the right lane (at index [0]), current lane (at index [1]), and left lane (at index [2]).

Parameters:

obs (Observation) – Agent observation.

Returns:

Returns a dictionary with the following key value mapping.

  • distance_from_center: Distance to lane center. Shape=(1,).

  • angle_error: Ego heading relative to the closest waypoint. Shape=(1,).

  • speed: Ego speed. Shape=(1,).

  • steering: Ego steering. Shape=(1,).

  • ego_ttc: Time to collision in each lane. Shape=(3,).

  • ego_lane_dist: Closest cars’ distance to ego in each lane. Shape=(3,).

smarts.env.custom_observations.scan_for_vehicle(target_prefix: str, angle_a: float, angle_b: float, activation_dist_squared: float, self_vehicle_state, other_vehicle_state) bool[source]

Sense test for another vehicle within a semi-circle range of a vehicle.

Parameters:
  • target_prefix – The whitelist of vehicles with vehicle_ids starting with this prefix for quick elimination.

  • angle_a – The minimum sweep angle between -pi and pi.

  • angle_b – The maximum sweep angle between -pi and pi.

  • activation_dist_squared – The distance to check for the target.

  • self_vehicle_state – The vehicle state of the vehicle that is scanning.

  • other_vehicle_state – The vehicle to test for.

Returns:

If the tested for vehicle is within the semi-circle range of the base vehicle.

smarts.env.custom_observations.scan_for_vehicles(target_prefix, angle_a, angle_b, activation_dist_squared, self_vehicle_state, other_vehicle_states, short_circuit: bool = False)[source]

Sense test for vehicles within a semi-circle radius of a vehicle.

Parameters:
  • target_prefix – The whitelist of vehicles with vehicle_ids starting with this prefix for quick elimination.

  • angle_a – The minimum sweep angle between -pi and pi.

  • angle_b – The maximum sweep angle between -pi and pi.

  • activation_dist_squared – The distance to check for the target.

  • self_vehicle_state – The vehicle state of the vehicle that is scanning.

  • other_vehicle_states – The set of vehicles to test for.

Returns:

If the tested for vehicle is within the semi-circle range of the base vehicle.