Source code for agents.substep_managers.pedestrian_detection

 1from typing import TYPE_CHECKING
 2
 3from agents.tools.hints import ObstacleDetectionResult
 4from agents.tools.lunatic_agent_tools import detect_vehicles
 5from classes.constants import RoadOption
 6
 7if TYPE_CHECKING:
 8    from agents.lunatic_agent import LunaticAgent
 9
10# TODO: Despite a few constants very similar to vehicle to the collision_detection_manager,
11# might be fusable
12
13
[docs] 14def pedestrian_detection_manager(self: "LunaticAgent") -> ObstacleDetectionResult: 15 """ 16 This module is in charge of warning in case of a collision 17 with any pedestrian. 18 19 :param location: current location of the agent 20 :return vehicle_state: True if there is a walker nearby, False if not 21 :return vehicle: nearby walker 22 :return distance: distance to nearby walker 23 """ 24 walker_list = self.walkers_nearby 25 26 if self.config.live_info.incoming_direction == RoadOption.CHANGELANELEFT: 27 detection_result = detect_vehicles( 28 self, 29 walker_list, 30 self.max_detection_distance("other_lane"), 31 up_angle_th=self.config.obstacles.detection_angles.walkers_lane_change[1], 32 lane_offset=-1, 33 ) 34 elif self.config.live_info.incoming_direction == RoadOption.CHANGELANERIGHT: 35 detection_result = detect_vehicles( 36 self, 37 walker_list, 38 self.max_detection_distance("other_lane"), 39 up_angle_th=self.config.obstacles.detection_angles.walkers_lane_change[1], 40 lane_offset=1, 41 ) 42 else: 43 detection_result = detect_vehicles( 44 self, 45 walker_list, 46 self.max_detection_distance("same_lane"), 47 up_angle_th=self.config.obstacles.detection_angles.walkers_same_lane[1], 48 ) 49 return detection_result