Skip to content

Commit

Permalink
Ensure ego observation road, lane, lane index fields are filled. (#1574)
Browse files Browse the repository at this point in the history
* Ensure ego observation road, lane, lane index fields are filled.

* Avoid lane_index=None in neighbours. (#1583)

Co-authored-by: adai <[email protected]>
  • Loading branch information
Gamenot and Adaickalavan authored Aug 23, 2022
1 parent 4a061ae commit d702bad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Copy and pasting the git commit messages is __NOT__ enough.
- Fixed a bug where traffic providers would leak across instances due to the ~~(awful design decision of python)~~ reference types defaults in arguments sharing across instances.
- Fixed minor bugs causing some Waymo maps not to load properly.
- Fixed bug where `Vehicle.bounding_box` was mirrored over Y causing on shoulder events to fire inappropriately.
- Fixed issue where the ego and neighbour vehicle observation was returning `None` for the nearby `lane_id`, `lane_index`, and `road_id`. These now default to constants `off_lane`, `-1`, and `off_road` respectively.

## [0.6.1]
### Added
Expand Down
18 changes: 11 additions & 7 deletions smarts/core/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

logger = logging.getLogger(__name__)

LANE_ID_CONSTANT = "off_lane"
ROAD_ID_CONSTANT = "off_road"
LANE_INDEX_CONSTANT = -1


class VehicleObservation(NamedTuple):
"""Perceived vehicle information."""
Expand Down Expand Up @@ -248,9 +252,9 @@ def _make_vehicle_observation(road_map, neighborhood_vehicle):
nv_lane_id = nv_lane.lane_id
nv_lane_index = nv_lane.index
else:
nv_road_id = None
nv_lane_id = None
nv_lane_index = None
nv_road_id = ROAD_ID_CONSTANT
nv_lane_id = LANE_ID_CONSTANT
nv_lane_index = LANE_INDEX_CONSTANT

return VehicleObservation(
id=neighborhood_vehicle.actor_id,
Expand Down Expand Up @@ -298,7 +302,7 @@ def observe(sim, agent_id, sensor_state, vehicle) -> Tuple[Observation, bool]:
veh_obs = _make_vehicle_observation(sim.road_map, nv)
nv_lane_pos = None
if (
veh_obs.lane_id is not None
veh_obs.lane_id is not LANE_ID_CONSTANT
and vehicle.subscribed_to_lane_position_sensor
):
nv_lane_pos = vehicle.lane_position_sensor(
Expand Down Expand Up @@ -326,9 +330,9 @@ def observe(sim, agent_id, sensor_state, vehicle) -> Tuple[Observation, bool]:
if vehicle.subscribed_to_lane_position_sensor:
ego_lane_pos = vehicle.lane_position_sensor(closest_lane, vehicle)
else:
ego_lane_id = None
ego_lane_index = None
ego_road_id = None
ego_lane_id = LANE_ID_CONSTANT
ego_lane_index = LANE_INDEX_CONSTANT
ego_road_id = ROAD_ID_CONSTANT
ego_vehicle_state = vehicle.state

acceleration_params = {
Expand Down

0 comments on commit d702bad

Please sign in to comment.