huawei-noah / SMARTS

Scalable Multi-Agent RL Training School for Autonomous Driving
MIT License
944 stars 190 forks source link

relative spatial observations #1493

Open sah-huawei opened 2 years ago

sah-huawei commented 2 years ago

As this seems to be the trend for inputs in many of the ML papers we're seeing these days (so-called "vector representations" of the spatial scene from an egocentric perspective), I propose we add the following to our standard Observations:

To the VehicleObservation and EgoVehicleObservation classes, I propose we add:

Then, in the Observation class, I propose we change the type for neighborhood_vehicle_states to be Optional[Dict[str, Tuple[VehicleObservation, RelativeObservation]]]. The Dict here would be keyed on vehicle_id. The new type RelativeObservation could look like:

@dataclass
class RelativeObservation:
    """Information about the relationship between the vehicle making observations and a target object."""

    target_id: str
    """Unique id of the target object."""
    range: float
    """The 'as-the-crow-flies' Euclidian distance to the target object."""
    bearing: float
    """The angle to the target object relative to north."""
    relative_bearing: float
    """The angle to the target object relative to my own heading."""

Note that relative_bearing is redundant and may not be needed (as it can be computed from bearing and heading) but this seems to be the most useful info here, so we might as well compute it. (... especially if we also consider keeping track of, and reporting, the rate-of-change of the relative_bearing over a time window, which is something very useful to avoiding collisions!)

We may also consider adding other fields to RelativeObservation including relative_speed relative_acceleration (or vectorized versions of these) and even estimated_time_to_contact (although computing this one requires making several assumptions that might be hard to justify/explain).

If we want flexibility (for example, if the overhead is too high), the NeighborhoodVehicles class in agent_interface.py could be augmented to add a boolean flag include_relative_info which, when True, would include the RelativeObservation objects in the output of the sensor.

sah-huawei commented 2 years ago

Note that computing the lane_relative_heading for every vehicle is potentially costly in terms of step time (because it requires computing the lane vector at each vehicle's offset), so it should be cached so as to not do it more than once per vehicle per step. (If using the LocalTrafficProvider, this is already computed each step anyway, but we can make the cache more accessible.)