예제 #1
0
    def process_sensor_data(self, percept_data):
        # feed agent percepts
        print('\n\nprocessing percepts')
        if self.q_size == 0:
            robot_info = self.agent.get_expected_robot_info()
        elif self.q_size == 1:
            ri_old = self.agent.get_robot_info()
            ri_new = self.agent.get_expected_robot_info()
            robot_info = RobotInfo(
                ri_old.get_coord(),
                ri_new.get_orientation()
                if ri_new else ri_old.get_orientation())
        elif self.q_size < 0:
            raise Exception(
                f'move q-size: {self.q_size}\nreceived extra move done before sensor data!'
            )
        else:
            raise Exception(
                f'move q-size: {self.q_size}\n2 last moves were not executed yet! \
                Is there desync between bot and algo?')

        if percept_data:
            obstacle_coord_list, no_obs_coord_list = SensorParser.main_sensor_parser(
                percept_data, robot_info)
        else:
            obstacle_coord_list, no_obs_coord_list = [], []
        print('obstacle list: ')
        obstacle_str = ''
        for coord, distance in obstacle_coord_list:
            obstacle_str += f'({coord.get_x()}, {coord.get_y()}), {distance}, '
        print(obstacle_str)
        return obstacle_coord_list, no_obs_coord_list
예제 #2
0
    def parse_init_data(self, init_data):
        assert (init_data['type'] == 'init')
        # arena string
        mdf_string = init_data['data']['arena'][
            'P2']  # p1 string ignored since always FFFF..
        arena_string = self.convert_mdf_to_binary(
            mdf_string) if init_data['data']['task'] == 'FP' else None

        # robot info
        robot_info = RobotInfo(START_COORD, START_ORIENTATION)

        # agent task
        if init_data['data']['task'] == 'FP':
            agent_task = AgentTask.FAST
        elif init_data['data']['task'] == 'EX':
            agent_task = AgentTask.EXPLORE
        elif init_data['data']['task'] == 'IR':
            agent_task = AgentTask.IMAGEREC
        else:
            raise Exception('Invalid agent task: ' + init_data['data']['task'])

        # end_coord
        end_coord = END_COORD

        return arena_string, robot_info, agent_task, end_coord
예제 #3
0
    def calculate_move(self, current_coord, target_coord) -> MoveCommand:
        displacement = target_coord.subtract(current_coord)
        target_orientation = OT.displacement_to_orientation(displacement)
        turn_angle = OT.calc_degree_of_turn(self.robot_info.get_orientation(),
                                            target_orientation)

        # update expected robot info
        self.expected_robot_info = RobotInfo(target_coord, target_orientation)

        return MoveCommand(turn_angle, displacement.manhattan_distance())
    def init(self, agent_task: AgentTask, arena_string: str, waypoint: Coord):
        self.robot_info = RobotInfo(START_COORD, Orientation.NORTH)
        self.sim_display = SimulationDisplay(self.robot_info)
        self.arena = ArenaStringParser.parse_arena_string(arena_string)

        # send copies of arena and robot info so that simulator and agent do not modify a mutual copy
        empty_arena_string = open(
            "./algorithms/src/simulator/empty_arena_string.txt", "r").read()
        self.agent = Agent(empty_arena_string, self.robot_info.copy(),
                           agent_task, END_COORD, waypoint)
예제 #5
0
 def init(self, agent_task: AgentTask, arena_string: str, waypoint: Coord):
     self.robot_info = RobotInfo(START_COORD, Orientation.NORTH)
     self.sim_display = SimulationDisplay(self.robot_info)
     self.arena = ArenaStringParser.parse_arena_string(arena_string) #used in line 34 and 100
     # self.update_display()
     # arena and robot info are separate so that simulator and agent do not modify a mutual copy
     if agent_task == AgentTask.FAST:
         self.agent = Agent(arena_string, self.robot_info.copy(), agent_task, END_COORD, waypoint)
     else:
         empty_arena_string = open("./algorithms/src/simulator/empty_arena_string.txt", "r").read()
         self.agent = Agent(empty_arena_string, self.robot_info.copy(), agent_task, END_COORD, waypoint)
예제 #6
0
    def get_agent_output_list(self) -> list:
        # Calculate fastest path of coords
        coords_list = []
        cl_to_waypoint = self.algo.get_next_step(self.arena,
                                                 self.robot_info,
                                                 self.end_coord,
                                                 self.waypoint_coord,
                                                 full_path=True)
        last_displacement = cl_to_waypoint[-1].subtract(cl_to_waypoint[-2])
        last_orientation = OT.displacement_to_orientation(last_displacement)
        robot_info_at_waypoint = RobotInfo(cl_to_waypoint[-1],
                                           last_orientation)
        cl_to_end = self.algo.get_next_step(self.arena,
                                            robot_info_at_waypoint,
                                            self.end_coord,
                                            None,
                                            full_path=True)
        coords_list.extend(cl_to_waypoint)
        coords_list.extend(cl_to_end)

        return self.calc_agent_output_full_path(coords_list)