class MarkAgent(Agent): def __init__(self, **kwargs): super().__init__(**kwargs) self.route_file_path = Path(self.agent_settings.waypoint_file_path) self.pid_controller = PIDController(agent=self, steering_boundary=(-1, 1), throttle_boundary=(0, 1)) self.mission_planner = WaypointFollowingMissionPlanner(agent=self) # initiated right after mission plan self.behavior_planner = BehaviorPlanner(agent=self) self.local_planner = DynamicWindowsApproach( agent=self, controller=self.pid_controller) occu_map_file_path = Path("./ROAR_Sim/data/easy_map_cleaned_global_occu_map.npy") self.occupancy_map = OccupancyGridMap(absolute_maximum_map_size=550, world_coord_resolution=1, occu_prob=0.99, max_points_to_convert=5000, threaded=True) self.occupancy_map.load_from_file(file_path=occu_map_file_path) # self.obstacle_from_depth_detector = ObstacleFromDepth(agent=self, # threaded=True, # max_detectable_distance=0.3, # max_points_to_convert=10000, # min_obstacle_height=2) # self.add_threaded_module(self.obstacle_from_depth_detector) # self.add_threaded_module(self.occupancy_map) def run_step(self, sensors_data: SensorsData, vehicle: Vehicle) -> VehicleControl: super(MarkAgent, self).run_step(vehicle=vehicle, sensors_data=sensors_data) control = self.local_planner.run_in_series() option = "obstacle_coords" # ground_coords, point_cloud_obstacle_from_depth if self.kwargs.get(option, None) is not None: points = self.kwargs[option] self.occupancy_map.update_async(points) self.occupancy_map.visualize() self.occupancy_map.get_map() return control
class RLLocalPlannerAgent(Agent): def __init__(self, target_speed=40, **kwargs): super().__init__(**kwargs) self.target_speed = target_speed self.logger = logging.getLogger("PID Agent") self.route_file_path = Path(self.agent_settings.waypoint_file_path) self.pid_controller = PIDController(agent=self, steering_boundary=(-1, 1), throttle_boundary=(0, 1)) self.mission_planner = WaypointFollowingMissionPlanner(agent=self) # initiated right after mission plan self.behavior_planner = BehaviorPlanner(agent=self) self.local_planner = RLLocalPlanner(agent=self, controller=self.pid_controller) self.traditional_local_planner = SimpleWaypointFollowingLocalPlanner( agent=self, controller=self.pid_controller, mission_planner=self.mission_planner, behavior_planner=self.behavior_planner, closeness_threshold=1.5) self.absolute_maximum_map_size, self.map_padding = 1000, 40 self.occupancy_map = OccupancyGridMap(agent=self, threaded=True) self.obstacle_from_depth_detector = ObstacleFromDepth(agent=self, threaded=True) self.add_threaded_module(self.obstacle_from_depth_detector) # self.add_threaded_module(self.occupancy_map) self.logger.debug(f"Waypoint Following Agent Initiated. Reading f" f"rom {self.route_file_path.as_posix()}") def run_step(self, vehicle: Vehicle, sensors_data: SensorsData) -> VehicleControl: super(RLLocalPlannerAgent, self).run_step(vehicle=vehicle, sensors_data=sensors_data) self.traditional_local_planner.run_in_series() self.transform_history.append(self.vehicle.transform) option = "obstacle_coords" # ground_coords, point_cloud_obstacle_from_depth if self.kwargs.get(option, None) is not None: points = self.kwargs[option] self.occupancy_map.update(points) control = self.local_planner.run_in_series() return control def get_obs(self): ch1 = self.occupancy_map.get_map(transform=self.vehicle.transform, view_size=(100, 100)) ch1 = np.expand_dims((ch1 * 255).astype(np.uint8), -1) ch2 = np.zeros(shape=(100, 100, 1)) ch3 = np.zeros(shape=ch2.shape) obs = np.concatenate([ch1, ch2, ch3], axis=2) print(np.shape(obs)) return obs
class OccupancyMapAgent(Agent): def __init__(self, vehicle: Vehicle, agent_settings: AgentConfig, **kwargs): super().__init__(vehicle, agent_settings, **kwargs) self.route_file_path = Path(self.agent_settings.waypoint_file_path) self.pid_controller = PIDController(agent=self, steering_boundary=(-1, 1), throttle_boundary=(0, 1)) self.mission_planner = WaypointFollowingMissionPlanner(agent=self) # initiated right after mission plan self.behavior_planner = BehaviorPlanner(agent=self) self.local_planner = SimpleWaypointFollowingLocalPlanner( agent=self, controller=self.pid_controller, mission_planner=self.mission_planner, behavior_planner=self.behavior_planner, closeness_threshold=1.5 ) self.occupancy_map = OccupancyGridMap(absolute_maximum_map_size=800, world_coord_resolution=1, occu_prob=0.99, max_points_to_convert=10000, threaded=True) self.obstacle_from_depth_detector = ObstacleFromDepth(agent=self, threaded=True, max_detectable_distance=0.5, max_points_to_convert=20000, min_obstacle_height=2) self.add_threaded_module(self.obstacle_from_depth_detector) self.add_threaded_module(self.occupancy_map) # self.vis = o3d.visualization.Visualizer() # self.vis.create_window(width=500, height=500) # self.pcd = o3d.geometry.PointCloud() # self.points_added = False def run_step(self, sensors_data: SensorsData, vehicle: Vehicle) -> VehicleControl: super().run_step(sensors_data=sensors_data, vehicle=vehicle) control = self.local_planner.run_in_series() option = "obstacle_coords" # ground_coords, point_cloud_obstacle_from_depth if self.kwargs.get(option, None) is not None: points = self.kwargs[option] self.occupancy_map.update_async(points) arb_points = [self.local_planner.way_points_queue[0].location] m = self.occupancy_map.get_map(transform=self.vehicle.transform, view_size=(200, 200), vehicle_value=-1, arbitrary_locations=arb_points, arbitrary_point_value=-5) # print(np.where(m == -5)) # cv2.imshow("m", m) # cv2.waitKey(1) # occu_map_vehicle_center = np.array(list(zip(*np.where(m == np.min(m))))[0]) # correct_next_waypoint_world = self.local_planner.way_points_queue[0] # diff = np.array([correct_next_waypoint_world.location.x, # correct_next_waypoint_world.location.z]) - \ # np.array([self.vehicle.transform.location.x, # self.vehicle.transform.location.z]) # correct_next_waypoint_occu = occu_map_vehicle_center + diff # correct_next_waypoint_occu = np.array([49.97, 44.72596359]) # estimated_world_coord = self.occupancy_map.cropped_occu_to_world( # cropped_occu_coord=correct_next_waypoint_occu, vehicle_transform=self.vehicle.transform, # occu_vehicle_center=occu_map_vehicle_center) # print(f"correct o-> {correct_next_waypoint_occu}" # f"correct w-> {correct_next_waypoint_world.location} | " # f"estimated = {estimated_world_coord.location.x}") # cv2.imshow("m", m) # cv2.waitKey(1) # print() # if self.points_added is False: # self.pcd = o3d.geometry.PointCloud() # point_means = np.mean(points, axis=0) # self.pcd.points = o3d.utility.Vector3dVector(points - point_means) # self.vis.add_geometry(self.pcd) # self.vis.poll_events() # self.vis.update_renderer() # self.points_added = True # else: # point_means = np.mean(points, axis=0) # self.pcd.points = o3d.utility.Vector3dVector(points - point_means) # self.vis.update_geometry(self.pcd) # self.vis.poll_events() # self.vis.update_renderer() if self.local_planner.is_done(): self.mission_planner.restart() self.local_planner.restart() return control