Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure ego observation road, lane, lane index fields are filled. #1574

Merged
merged 3 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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