Improved agent vehicle detection (#3973)

* Improved agent vehicle detection

* Minor CHANGELOG error

Co-authored-by: Jacopo Bartiromo <32928804+jackbart94@users.noreply.github.com>
This commit is contained in:
glopezdiest 2021-04-27 15:02:18 +02:00 committed by GitHub
parent 144b7417af
commit 3360d27486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 7 deletions

View File

@ -19,6 +19,7 @@
* Fix bug in lidar channel point count * Fix bug in lidar channel point count
* Fix imu: some weird cases were given nan values * Fix imu: some weird cases were given nan values
* When setting a global plan at the LocalPlanner, it is now optional to stop the automatic fill of the waypoint buffer * When setting a global plan at the LocalPlanner, it is now optional to stop the automatic fill of the waypoint buffer
* Improved agent's vehicle detection to also take into account the actor bounding boxes
* API extensions: * API extensions:
- Added `set_wheel_steer_direction()` function to change the bone angle of each wheel of a vehicle - Added `set_wheel_steer_direction()` function to change the bone angle of each wheel of a vehicle
- Added `get_wheel_steer_angle()` function to get the steer angle of a vehicle whee - Added `get_wheel_steer_angle()` function to get the steer angle of a vehicle whee

View File

@ -188,7 +188,6 @@ class Agent(object):
def _is_vehicle_hazard(self, vehicle_list): def _is_vehicle_hazard(self, vehicle_list):
""" """
:param vehicle_list: list of potential obstacle to check :param vehicle_list: list of potential obstacle to check
:return: a tuple given by (bool_flag, vehicle), where :return: a tuple given by (bool_flag, vehicle), where
- bool_flag is True if there is a vehicle ahead blocking us - bool_flag is True if there is a vehicle ahead blocking us
@ -196,22 +195,40 @@ class Agent(object):
- vehicle is the blocker object itself - vehicle is the blocker object itself
""" """
ego_vehicle_location = self._vehicle.get_location() ego_vehicle_transform = self._vehicle.get_transform()
ego_vehicle_waypoint = self._map.get_waypoint(ego_vehicle_location) ego_vehicle_forward_vector = ego_vehicle_transform.get_forward_vector()
ego_vehicle_extent = self._vehicle.bounding_box.extent.x
ego_vehicle_waypoint = self._map.get_waypoint(self._vehicle.get_location())
# Get the transform of the front of the ego
ego_vehicle_front_transform = ego_vehicle_transform
ego_vehicle_front_transform.location += carla.Location(
x=ego_vehicle_extent * ego_vehicle_forward_vector.x,
y=ego_vehicle_extent * ego_vehicle_forward_vector.y,
)
for target_vehicle in vehicle_list: for target_vehicle in vehicle_list:
# do not account for the ego vehicle # do not account for the ego vehicle
if target_vehicle.id == self._vehicle.id: if target_vehicle.id == self._vehicle.id:
continue continue
# if the object is not in our lane it's not an obstacle # if the object is not in our lane it's not an obstacle
target_vehicle_transform = target_vehicle.get_transform()
target_vehicle_forward_vector = target_vehicle_transform.get_forward_vector()
target_vehicle_extent = target_vehicle.bounding_box.extent.x
target_vehicle_waypoint = self._map.get_waypoint(target_vehicle.get_location()) target_vehicle_waypoint = self._map.get_waypoint(target_vehicle.get_location())
if target_vehicle_waypoint.road_id != ego_vehicle_waypoint.road_id or \ if target_vehicle_waypoint.road_id != ego_vehicle_waypoint.road_id or \
target_vehicle_waypoint.lane_id != ego_vehicle_waypoint.lane_id: target_vehicle_waypoint.lane_id != ego_vehicle_waypoint.lane_id:
continue continue
if is_within_distance_ahead(target_vehicle.get_transform(), # Get the transofrm of the back of the vehicle
self._vehicle.get_transform(), target_vehicle_rear_transform = target_vehicle_transform
target_vehicle_rear_transform.location -= carla.Location(
x=target_vehicle_extent * target_vehicle_forward_vector.x,
y=target_vehicle_extent * target_vehicle_forward_vector.y,
)
if is_within_distance_ahead(target_vehicle_rear_transform,
ego_vehicle_front_transform,
self._proximity_vehicle_threshold): self._proximity_vehicle_threshold):
return (True, target_vehicle) return (True, target_vehicle)

View File

@ -45,7 +45,6 @@ def is_within_distance_ahead(target_transform, current_transform, max_distance):
:param target_transform: location of the target object :param target_transform: location of the target object
:param current_transform: location of the reference object :param current_transform: location of the reference object
:param orientation: orientation of the reference object
:param max_distance: maximum allowed distance :param max_distance: maximum allowed distance
:return: True if target object is within max_distance ahead of the reference object :return: True if target object is within max_distance ahead of the reference object
""" """