示例#1
0
class PotentialFieldAgent(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.occupancy_map = OccupancyGridMap(agent=self, threaded=True)
        self.depth_to_obstacle = ObstacleFromDepth(agent=self, threaded=True)
        self.add_threaded_module(self.occupancy_map)
        self.add_threaded_module(self.depth_to_obstacle)
        # occu_map_file_path = Path("./ROAR_Sim/data/easy_map_cleaned_global_occu_map.npy")
        # self.occupancy_map.load_from_file(occu_map_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 = PotentialFieldPlanner(
            agent=self,
            behavior_planner=self.behavior_planner,
            mission_planner=self.mission_planner,
            controller=self.pid_controller)

    def run_step(self, sensors_data: SensorsData,
                 vehicle: Vehicle) -> VehicleControl:
        super().run_step(sensors_data=sensors_data, vehicle=vehicle)
        if self.kwargs.get("obstacle_coords") is not None:
            self.occupancy_map.update_async(self.kwargs.get("obstacle_coords"))

        control = self.local_planner.run_in_series()
        return control
示例#2
0
class RecordingAgent(Agent):
    def __init__(self, target_speed=20, **kwargs):
        super().__init__(**kwargs)
        # ensure recording status is ON
        self.agent_settings.save_sensor_data = True
        super().__init__(**kwargs)
        self.target_speed = target_speed
        self.logger = logging.getLogger("Recording 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),
                                            target_speed=target_speed)
        self.mission_planner = WaypointFollowingMissionPlanner(agent=self)
        # initiated right after mission plan

        self.behavior_planner = BehaviorPlanner(agent=self)
        self.local_planner = LoopSimpleWaypointFollowingLocalPlanner(
            agent=self,
            controller=self.pid_controller,
            mission_planner=self.mission_planner,
            behavior_planner=self.behavior_planner,
            closeness_threshold=1)
        self.occupancy_map = OccupancyGridMap(
            absolute_maximum_map_size=1000,
            world_coord_resolution=1,
            occu_prob=0.99,
            max_points_to_convert=5000,
            threaded=True,
            should_save=self.agent_settings.save_sensor_data)
        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)
        self.option = "obstacle_coords"
        self.lap_count = 0

    def run_step(self, sensors_data: SensorsData,
                 vehicle: Vehicle) -> VehicleControl:
        super(RecordingAgent, self).run_step(sensors_data=sensors_data,
                                             vehicle=vehicle)
        self.transform_history.append(self.vehicle.transform)
        control = self.local_planner.run_in_series()

        if self.kwargs.get(self.option, None) is not None:
            points = self.kwargs[self.option]
            self.occupancy_map.update_async(points)
            self.occupancy_map.visualize(transform=self.vehicle.transform,
                                         view_size=(200, 200))
        return control
示例#3
0
class RLOccuMapE2ETrainingAgent(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.traditional_local_planner = LoopSimpleWaypointFollowingLocalPlanner(
            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=1000,
                                              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)

    def run_step(self, sensors_data: SensorsData,
                 vehicle: Vehicle) -> VehicleControl:
        super(RLOccuMapE2ETrainingAgent, self).run_step(sensors_data, vehicle)
        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_async(points)

        if self.kwargs.get("control") is None:
            return VehicleControl()
        else:
            return self.kwargs.get("control")
示例#4
0
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
示例#5
0
class OccuDebugAgent(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 = LoopSimpleWaypointFollowingLocalPlanner(
            agent=self,
            controller=self.pid_controller,
            mission_planner=self.mission_planner,
            behavior_planner=self.behavior_planner,
            closeness_threshold=1)
        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(OccuDebugAgent, self).run_step(vehicle=vehicle,
                                             sensors_data=sensors_data)
        self.transform_history.append(self.vehicle.transform)
        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)
        control = self.kwargs.get("control", VehicleControl())
        return control
示例#6
0
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