Exemple #1
0
 def test_wrap_to_pi(self):
     self.assertEqual(Pose.wrap_to_pi(0), 0)
     self.assertEqual(Pose.wrap_to_pi(-1), -1)
     self.assertEqual(Pose.wrap_to_pi(1), 1)
     self.assertEqual(Pose.wrap_to_pi(m.pi), -m.pi)
     self.assertEqual(Pose.wrap_to_pi(-m.pi), -m.pi)
     self.assertEqual(Pose.wrap_to_pi(2 * m.pi), 0)
    def __init__(self, p_game_state):
        super().__init__(p_game_state)

        self.add_tactic(0, Stop(self.game_state, 0))
        self.add_tactic(
            0, GoStraightTo(self.game_state, 0, Pose(Position(-500, -500))))
        self.add_tactic(
            0, GoStraightTo(self.game_state, 0, Pose(Position(-1500, -1500))))
        self.add_condition(0, 0, 1, self.condition2)
        self.add_condition(0, 1, 2, self.condition)
        self.add_condition(0, 2, 0, self.condition)

        self.add_tactic(1,
                        GoStraightTo(self.game_state, 1, Pose(Position(0, 0))))
        self.add_tactic(
            1, GoStraightTo(self.game_state, 1, Pose(Position(1000, 0))))
        self.add_tactic(
            1, GoStraightTo(self.game_state, 1, Pose(Position(1000, 1000))))
        self.add_tactic(
            1, GoStraightTo(self.game_state, 1, Pose(Position(0, 1000))))
        self.add_condition(1, 0, 1, self.condition1)
        self.add_condition(1, 1, 2, self.condition1)
        self.add_condition(1, 2, 3, self.condition1)
        self.add_condition(1, 3, 0, self.condition1)

        for i in range(2, 6):
            self.add_tactic(i, Stop(self.game_state, i))
Exemple #3
0
    def update(self, cmd: AICommand) -> Pose():
        #print(cmd.path_speeds)
        self.update_states(cmd)

        # Rotation control
        rotation_cmd = self.angle_controller.update(
            self.pose_error.orientation, dt=self.dt)
        rotation_cmd = self.apply_rotation_constraints(rotation_cmd)
        if abs(self.pose_error.orientation) < 0.2:
            self.rotation_flag = True
        # Translation control
        self.position_flag = False
        if self.position_error.norm(
        ) < MIN_DISTANCE_TO_REACH_TARGET_SPEED * max(1.0, self.cruise_speed):
            if self.target_speed < 0.01:
                self.position_flag = True

        if self.position_flag:
            translation_cmd = Position(
                self.x_controller.update(self.pose_error.position.x,
                                         dt=self.dt),
                self.y_controller.update(self.pose_error.position.y,
                                         dt=self.dt))
        else:
            translation_cmd = self.get_next_velocity()
        # Adjust command to robot's orientation
        # self.ws.debug_interface.add_line(start_point=(self.current_pose.position[0] * 1000, self.current_pose.position[1] * 1000),
        #                                  end_point=(self.current_pose.position[0] * 1000 + translation_cmd[0] * 600, self.current_pose.position[1] * 1000 + translation_cmd[1] * 600),
        #                                  timeout=0.01, color=debug_interface.CYAN.repr())

        compasation_ref_world = translation_cmd.rotate(self.dt * rotation_cmd)
        translation_cmd = translation_cmd.rotate(
            -(self.current_pose.orientation))
        if not self.rotation_flag and cmd.path[-1] is not cmd.path[0]:
            translation_cmd *= translation_cmd * 0.0
            self.next_speed = 0.0
            self.x_controller.reset()
            self.y_controller.reset()
        if self.position_error.norm() > 0.1 and self.rotation_flag:
            self.angle_controller.reset()
            rotation_cmd = 0

        # self.ws.debug_interface.add_line(
        #     start_point=(self.current_pose.position[0] * 1000, self.current_pose.position[1] * 1000),
        #     end_point=(self.current_pose.position[0] * 1000 + compasation_ref_world[0] * 600,
        #                self.current_pose.position[1] * 1000 + compasation_ref_world[1] * 600),
        #     timeout=0.01, color=debug_interface.ORANGE.repr())
        translation_cmd = self.apply_translation_constraints(translation_cmd)
        #if not translation_cmd.norm() < 0.01:
        #    print(translation_cmd, "self.target_reached()", self.target_reached(), "self.next_speed", self.next_speed,"self.target_speed", self.target_speed )
        # self.debug(translation_cmd, rotation_cmd)
        return SpeedPose(translation_cmd, rotation_cmd)
Exemple #4
0
    def test_to_tuple(self):
        uut = Pose()
        #sanity check
        self.assertNotEqual(type(uut.to_tuple()), type(Pose()))
        self.assertEqual(type(uut.to_tuple()), type(tuple()))

        self.assertEqual(uut.to_tuple(), tuple((0, 0)))

        uut = Pose(Position(557, -778.5), 0)
        self.assertEqual(uut.to_tuple(), tuple((557, -778.5)))
        self.assertNotEqual(uut.to_tuple(), tuple((-42, 3897)))
Exemple #5
0
 def protect_goal(self):
     ball_position = self.game_state.get_ball_position()
     if not self.game_state.game.field.is_inside_goal_area(
             ball_position, self.is_yellow):
         self.next_state = self.protect_goal
     else:
         self.next_state = self.go_behind_ball
     self.target = Pose(self.game_state.get_ball_position())
     return ProtectGoal(self.game_state,
                        self.player,
                        self.is_yellow,
                        minimum_distance=self.game_state.game.field.
                        constant["FIELD_GOAL_RADIUS"])
Exemple #6
0
    def __init__(self, game_state: GameState, player: OurPlayer, target: Pose=Pose(), args: List[str]=None):
        super().__init__(game_state, player, target, args)
        self.current_state = self.get_behind_ball
        self.next_state = self.get_behind_ball
        self.debug_interface = DebugInterface()
        self.move_action = self._generate_move_to()
        self.move_action.status_flag = Flags.SUCCESS
        self.last_ball_position = self.game_state.get_ball_position()
        self.charge_time = 0
        self.last_time = time.time()

        self.orientation_target = 0
        self.target = target
Exemple #7
0
    def __init__(self, game_state, p_player_id, target=Pose(),
                 time_to_live=DEFAULT_TIME_TO_LIVE):
        Tactic.__init__(self, game_state, p_player_id, target)
        assert isinstance(p_player_id, int)
        assert PLAYER_PER_TEAM >= p_player_id >= 0

        self.player_id = p_player_id
        self.current_state = self.protect_goal
        self.next_state = self.protect_goal
        self.status_flag = Flags.INIT
        self.side = None
        self.zone = None
        self._check_side_and_zone()
 def exec(self):
     """
     Exécute le déplacement en tenant compte de la possession de la balle. Le robot se déplace vers la destination,
     mais s'oriente de façon à garder la balle sur le dribleur. C'est la responsabilité de la Tactique de faire les
     corrections de trajectoire nécessaire.
     :return:
     """
     # TODO: Améliorer le comportement en ajoutant l'intervalle d'anle correspondant à la largeur du dribbleur
     destination_orientation = get_angle(
         self.player.pose.position, self.game_state.get_ball_position())
     destination_pose = Pose(self.destination, destination_orientation)
     return AICommand(self.player, AICommandType.MOVE,
                      **{"pose_goal": destination_pose})
Exemple #9
0
 def setUp(self):
     self.game_state = GameState()
     self.empty_graph = Graph()
     self.graph1 = Graph()
     self.tactic1 = Stop(self.game_state, 1)
     self.tactic2 = GoToPosition(self.game_state, 0,
                                 Pose(Position(500, 0), 0))
     self.node1 = Node(self.tactic1)
     self.node2 = Node(self.tactic2)
     self.vertex1 = Vertex(1, foo)
     self.graph1.add_node(self.node1)
     self.graph1.add_node(self.node2)
     self.graph1.add_vertex(0, 1, foo)
    def go_between_ball_and_target(self):
        self.status_flag = Flags.WIP
        ball = self.game_state.get_ball_position()
        ball_velocity = self.game_state.get_ball_velocity().conv_2_np()
        if np.linalg.norm(ball_velocity) > 50:
            self.target = Pose(
                Position.from_np(ball.conv_2_np() - ball_velocity), 0)
            dist_behind = np.linalg.norm(ball_velocity) + 1 / np.sqrt(
                np.linalg.norm(ball_velocity))
        else:
            self.target = None
            dist_behind = 250
        if self.target is None:
            self.target = Pose(
                self.game_state.const["FIELD_THEIR_GOAL_MID_GOAL"], 0)
        if self._is_player_towards_ball_and_target():
            self.next_state = self.grab_ball
        else:
            self.next_state = self.go_between_ball_and_target

        return GoBehind(self.game_state, self.player, ball,
                        self.target.position, dist_behind)
Exemple #11
0
 def exec(self):
     if self.check_success():
         self.status_flag = Flags.SUCCESS
     else:
         self.status_flag = Flags.WIP
     ball = self.game_state.get_ball_position().conv_2_np()
     target = self.target.position.conv_2_np()
     ball_to_target = target - ball
     orientation = np.arctan2(ball_to_target[1], ball_to_target[0])
     next_action = RotateAround(self.game_state, self.player,
                                Pose(Position.from_np(ball), orientation),
                                90)
     return next_action.exec()
Exemple #12
0
    def __init__(self, p_game_state, player_id, target=Pose()):
        Tactic.__init__(self, p_game_state, player_id, target)
        assert isinstance(player_id, int)
        assert PLAYER_PER_TEAM >= player_id >= 0

        self.player_id = player_id
        self.current_state = self.get_behind_ball
        self.next_state = self.get_behind_ball

        self.move_action = GoToPosition(self.game_state, self.player_id,
                                        self.game_state.get_player_pose(self.player_id))
        self.move_action.status_flag = Flags.SUCCESS
        self.last_ball_position = self.game_state.get_ball_position()
Exemple #13
0
    def protect_goal(self):
        # FIXME : enlever ce hack de merde
        ball_position = self.game_state.get_ball_position()
        if not isInsideGoalArea(ball_position):
            self.next_state = self.protect_goal
        else:
            if canGetBall(self.game_state, self.player_id, ball_position):
                self.next_state = self.grab_ball
            else:
                self.next_state = self.go_behind_ball
        self.target = Pose(self.game_state.get_ball_position())

        return GoToPositionNoPathfinder(self.game_state, self.player_id)
Exemple #14
0
    def test_exec(self):
        self.node1.add_vertex(self.vertex1)
        self.node1.add_vertex(self.vertex2)
        next_ai_command, next_node = self.node1.exec()
        self.assertEqual(next_node, 0)
        expected_aicmd = AICommand(Pose(Position(-4000, 0), 0), 0)
        self.assertEqual(next_ai_command, expected_aicmd)

        self.node2.add_vertex(self.vertex2)
        expected_aicmd = AICommand(None, 0)
        next_ai_command, next_node = self.node2.exec()
        self.assertEqual(next_ai_command, expected_aicmd)
        self.assertEqual(next_node, -1)
Exemple #15
0
    def __init__(self, p_game_state):
        super().__init__(p_game_state)

        self.add_tactic(0, GoalKeeper(self.game_state, 0))
        self.add_tactic(
            1, GoStraightTo(self.game_state, 1, Pose(Position(), 3 * pi / 2)))
        self.add_tactic(
            1, GoStraightTo(self.game_state, 1, Pose(Position(1000, 0), 0)))
        self.add_tactic(
            1,
            GoStraightTo(self.game_state, 1, Pose(Position(1000, 1000),
                                                  pi / 2)))
        self.add_tactic(
            1, GoStraightTo(self.game_state, 1, Pose(Position(0, 1000), pi)))

        self.add_condition(1, 0, 1, self.condition)
        self.add_condition(1, 1, 2, self.condition)
        self.add_condition(1, 2, 3, self.condition)
        self.add_condition(1, 3, 0, self.condition)

        for i in range(2, PLAYER_PER_TEAM):
            self.add_tactic(i, Stop(self.game_state, i))
Exemple #16
0
 def generate_destination(self):
     player = self.player.pose.position.conv_2_np()
     target = self.target.position.conv_2_np()
     player_to_target_orientation = np.arctan2(target[1] - player[1], target[0] - player[0])
     target_orientation = self.target.orientation
     delta_theta = player_to_target_orientation - target_orientation
     delta_theta = min(abs(delta_theta), np.pi/6) * np.sign(delta_theta)
     rotation_matrix = np.array([[np.cos(delta_theta), np.sin(delta_theta)], [-np.sin(delta_theta), np.cos(delta_theta)]])
     player_to_ball_rot = np.dot(rotation_matrix, player - target)
     translation = player_to_ball_rot / np.linalg.norm(player_to_ball_rot) * self.rayon
     destination = translation + target
     orientation = target_orientation
     return Pose(Position.from_np(destination), orientation)
Exemple #17
0
    def exec(self):
        """
        Place le robot afin qu'il prenne le contrôle de la balle
        :return: Un tuple (Pose, kick) où Pose est la destination du joueur et kick est nul (on ne botte pas)
        """
        ball_position = self.game_state.get_ball_position()
        destination_orientation = (ball_position -
                                   self.player.pose.position).angle()

        return AICommand(self.player,
                         AICommandType.MOVE,
                         pose_goal=Pose(ball_position,
                                        destination_orientation))
Exemple #18
0
    def get_path(self,
                 player: OurPlayer,
                 pose_target: Pose = Pose(),
                 cruise_speed: [int, float] = 1,
                 old_path=None,
                 old_raw_path=Path(Position(99999, 99999),
                                   Position(99999, -99999))):
        self.cruise_speed = cruise_speed
        self.player = player

        i = 0

        self.pose_obstacle = np.zeros(
            (len(self.game_state.my_team.available_players) +
             len(self.game_state.other_team.available_players) - 1, 2))

        for player in self.game_state.my_team.available_players.values():
            if player.id != self.player.id:
                self.pose_obstacle[i, :] = player.pose.position.conv_2_np()
                self.players_obstacles.append(player)
                i += 1
        for player in self.game_state.other_team.available_players.values():
            self.pose_obstacle[i, :] = player.pose.position.conv_2_np()
            self.players_obstacles.append(player)
            i += 1

        # tentative de code pour ne pas recalculer le path a toutes les ittérations (marche un peu mais pas parfait)
        if (old_path
                is not None) and (not self.is_path_collide(old_raw_path)
                                  ) and self.path.goal == old_raw_path.goal:
            old_raw_path.quick_update_path(self.player)
            old_path.quick_update_path(self.player)
            self.path = old_path
            self.path = self.remove_redundant_points()
            self.raw_path = old_raw_path
        else:
            self.path = Path(self.player.pose.position, pose_target.position)
            self.closest_obs_speed = self.find_closest_obstacle(
                self.player.pose.position, self.path)
            self.path = self.fastpathplanner(self.path)
            self.path = self.remove_redundant_points()

            self.raw_path = self.path
            self.path = self.reshaper.reshape_path(self.path, self.player,
                                                   self.cruise_speed)

        if self.is_path_collide(self.raw_path):
            self.path.speeds[1] = 0
        #print("points", self.path.points)
        #print("speeds", self.path.speeds)
        return self.path, self.raw_path
Exemple #19
0
    def handle_joystick(self):
        if self.status_flag is not Flags.FAILURE:
            self.status_flag = Flags.WIP
            pygame.event.pump()

            x, y = self.joy.get_left_axis_vector()
            _, t = self.joy.get_right_axis_vector()

            if self.joy.get_btn_value("X"):
                charge_kick = True
            else:
                charge_kick = False

            if self.joy.get_btn_value("A"):
                kick = 4
            else:
                kick = 0

            if self.joy.get_btn_value("B"):
                dribbler = 2
            else:
                dribbler = 0

            if self.joy.get_btn_value("Y"):
                self.next_state = self.halt

            x_speed = -y * self.inv_y
            y_speed = x * self.inv_x

            speed_pose = Pose(Position(x_speed, y_speed), t * 5)

            if kick == 0:
                next_action = AllStar(
                    self.game_state, self.player, **{
                        "ai_command_type": AICommandType.MOVE,
                        "pose_goal": speed_pose,
                        "control_loop_type": AIControlLoopType.SPEED,
                        "charge_kick": charge_kick,
                        "kick_strength": kick,
                        "dribbler_on": dribbler
                    })
            else:
                next_action = AllStar(
                    self.game_state, self.player, **{
                        "ai_command_type": AICommandType.KICK,
                        "kick_strength": kick
                    })
        else:
            next_action = Idle(self.game_state, self.player)

        return next_action
Exemple #20
0
    def __init__(self, p_game_state):
        super().__init__(p_game_state)
        # ID Robot Indiana Jones : 0
        # ID Robot obstacles mouvants : 1 et 2
        indiana = self.game_state.my_team.available_players[4]
        obs_right = self.game_state.my_team.available_players[5]
        obs_left = self.game_state.my_team.available_players[3]

        # Positions objectifs d'Indiana Jones
        goal_left = (Pose(
            Position(self.game_state.const["FIELD_GOAL_YELLOW_X_LEFT"], 0), 0))
        goal_right = (Pose(
            Position(self.game_state.const["FIELD_GOAL_BLUE_X_RIGHT"], 0), 0))

        # Positions objectifs des obstacles
        y_down = self.game_state.const["FIELD_Y_BOTTOM"] + 500
        y_top = self.game_state.const["FIELD_Y_TOP"] - 500
        x_left = self.game_state.const["FIELD_X_LEFT"] + 500
        x_right = self.game_state.const["FIELD_X_RIGHT"] - 500

        self.add_tactic(
            indiana.id,
            GoToPositionPathfinder(self.game_state, indiana, goal_left))
        self.add_tactic(
            indiana.id,
            GoToPositionPathfinder(self.game_state, indiana, goal_right))
        self.add_condition(indiana.id, 0, 1, partial(self.condition, indiana))
        self.add_condition(indiana.id, 1, 0, partial(self.condition, indiana))

        self.add_tactic(
            obs_left.id,
            GoToPositionPathfinder(self.game_state, obs_left,
                                   Pose(Position(x_left / 2, y_top))))
        self.add_tactic(
            obs_left.id,
            GoToPositionPathfinder(self.game_state, obs_left,
                                   Pose(Position(x_left / 2, y_down))))
        self.add_condition(obs_left.id, 0, 1, partial(self.condition,
                                                      obs_left))
        self.add_condition(obs_left.id, 1, 0, partial(self.condition,
                                                      obs_left))

        self.add_tactic(
            obs_right.id,
            GoToPositionPathfinder(self.game_state, obs_right,
                                   Pose(Position(x_right / 2, y_top))))
        self.add_tactic(
            obs_right.id,
            GoToPositionPathfinder(self.game_state, obs_right,
                                   Pose(Position(x_right / 2, y_down))))
        self.add_condition(obs_right.id, 0, 1,
                           partial(self.condition, obs_right))
        self.add_condition(obs_right.id, 1, 0,
                           partial(self.condition, obs_right))

        for i in range(PLAYER_PER_TEAM):
            if not (i == obs_right.id or i == obs_left.id or i == indiana.id):
                self.add_tactic(i, Stop(self.game_state, i))
Exemple #21
0
            def _bouger(self, joueur):
                #TODO: ajuster la deadzone en fonction du type du goal
                position = self._convertirPosition(self.robot_goals[joueur])
                player = self.team.players[joueur]
                dist = geometry.get_distance(player.pose.position, position)
                deadzone = self._getDeadZone(self.robot_goals[joueur])

                if dist < deadzone: # si la distance est exactement 0, la position n'est pas bonne
                    self._succeed(joueur)
                else:
                    orientation = player.pose.orientation
                    command = Command.MoveToAndRotate(player, self.team,
                                                      Pose(position, orientation))
                    self._send_command(command)
Exemple #22
0
 def grab_ball(self):
     if self._get_distance_from_ball(
     ) < 120 and self._is_player_towards_ball_and_target():
         self.next_state = self.halt
         self.status_flag = Flags.SUCCESS
     else:
         self.next_state = self.grab_ball
     ball_x = self.game_state.get_ball_position().x
     ball_y = self.game_state.get_ball_position().y
     angle_ball_2_target = np.arctan2(self.target.position.y - ball_y,
                                      self.target.position.x - ball_x)
     return MoveToPosition(
         self.game_state, self.player,
         Pose(Position(ball_x, ball_y), angle_ball_2_target))
Exemple #23
0
 def exec(self):
     """
     Exécute le déplacement en tenant compte de la possession de la balle. Le robot se déplace vers la destination,
     mais s'oriente de façon à garder la balle sur le dribleur. C'est la responsabilité de la Tactique de faire les
     corrections de trajectoire nécessaire.
     :return: Un tuple (Pose, kick) où Pose est la destination du joueur kick est faux (on ne botte pas)
     """
     # TODO: Améliorer le comportement en ajoutant l'intervalle d'anle correspondant à la largeur du dribleur
     destination_orientation = get_angle(
         self.game_state.get_player_pose(self.player_id).position,
         self.game_state.get_ball_position())
     destination_pose = Pose(self.destination, destination_orientation)
     kick_strength = 0
     return AICommand(destination_pose, kick_strength)
Exemple #24
0
    def test_exec(self):
        next_ai_command = self.graph1.exec()
        expected_ai_command = AICommand(1, AICommandType.STOP)
        self.assertEqual(self.graph1.current_node, 1)
        self.assertEqual(next_ai_command, expected_ai_command)

        self.assertRaises(EmptyGraphException, self.empty_graph.exec)

        self.empty_graph.add_node(self.node2)
        self.empty_graph.add_node(self.node1)
        self.empty_graph.add_vertex(0, 1, foo2)

        next_ai_command = self.empty_graph.exec()
        expected_ai_command = AICommand(
            0, AICommandType.MOVE, **{"pose_goal": Pose(Position(500, 0))})
        self.assertEqual(self.empty_graph.current_node, 0)
        self.assertEqual(next_ai_command, expected_ai_command)

        next_ai_command = self.empty_graph.exec()
        expected_ai_command = AICommand(
            0, AICommandType.MOVE, **{"pose_goal": Pose(Position(500, 0))})
        self.assertEqual(self.empty_graph.current_node, 0)
        self.assertEqual(next_ai_command, expected_ai_command)
Exemple #25
0
    def update_states(self, cmd: AICommand):
        self.dt = self.ws.game_state.game.delta_t

        # Dynamics constraints
        self.setting.translation.max_acc = self.ws.game_state.get_player(
            self.id).max_acc
        self.setting.translation.max_speed = self.ws.game_state.get_player(
            self.id).max_speed
        self.setting.translation.max_angular_acc = self.ws.game_state.get_player(
            self.id).max_angular_acc
        self.setting.rotation.max_speed = self.ws.game_state.get_player(
            self.id).max_angular_speed

        # Current state of the robot
        self.current_pose = self.ws.game_state.game.friends.players[
            self.id].pose.scale(1 / 1000)
        self.current_velocity = self.ws.game_state.game.friends.players[
            self.id].velocity.scale(1 / 1000)
        self.current_speed = self.current_velocity.position.norm()
        self.current_angular_speed = self.current_velocity.orientation
        self.current_orientation = self.current_pose.orientation

        # Desired parameters
        if cmd.path != []:
            current_path_position = Position(cmd.path[0] / 1000)
            if not self.last_position.is_close(
                    current_path_position, 0.1) and self.target_speed < 0.2:
                self.reset()
                self.last_position = current_path_position

            self.target_pose = Pose(cmd.path[0],
                                    cmd.pose_goal.orientation).scale(1 / 1000)
            self.target_turn = cmd.path_turn[1] / 1000
            self.target_speed = cmd.path_speeds[1] / 1000

        else:  # No pathfinder case
            self.target_pose = cmd.pose_goal.scale(1 / 1000)
            self.target_turn = self.target_pose.position
            self.target_speed = 0.0

        self.target_angle = self.target_pose.orientation
        self.pose_error = self.target_pose - self.current_pose  # Pose are always wrap to pi
        self.position_error = self.pose_error.position
        self.angle_error = self.pose_error.orientation
        if self.position_error.norm() != 0.0:
            self.target_direction = (self.target_turn -
                                     self.current_pose.position).normalized()

        self.cruise_speed = cmd.cruise_speed
Exemple #26
0
    def test_eq(self):
        pos1 = Pose()
        pos2 = Pose()

        pos3 = Pose(Position(500, 400), 0)
        pos4 = Pose(Position(500, 400), 1.5)
        pos5 = Pose(Position(500, 400), -1.5)
        pos6 = Pose(Position(400, 500), 0)

        pos7 = Pose(Position(), 1.54679)
        pos8 = Pose(Position(), 1.54671)
        pos9 = Pose(Position(), 1.5466)
        pos10 = Pose(Position(), 1.5468)

        self.assertEqual(pos1, pos2)
        self.assertEqual(pos2, pos1)

        self.assertFalse(pos3 == pos4)
        self.assertFalse(pos3 == pos5)
        self.assertFalse(pos3 == pos6)

        self.assertTrue(pos7 == pos8)
        self.assertFalse(pos7 == pos9)
        self.assertFalse(pos7 == pos10)
Exemple #27
0
    def exec(self):

        if self.check_success():
            self.current_position_index_to_go = random.randint(
                0,
                len(self.grid_of_positions) - 1)
            self.current_position_to_go = self.grid_of_positions[
                self.current_position_index_to_go]
            #self.current_angle_to_go = random.randint(-1, 1) * np.pi / 100.
            self.next_pose = Pose(self.current_position_to_go,
                                  self.current_angle_to_go)
        self.next_state = self.exec

        return GoToPositionPathfinder(self.game_state, self.player,
                                      self.next_pose).exec()
        def _bouger(self, joueur):
            #TODO: ajuster la deadzone en fonction du type du goal
            position = self._convertirPosition(self.robot_goals[joueur])
            player = self.team.players[joueur]
            dist = geometry.get_distance(player.pose.position, position)
            print(dist)
            deadzone = 225  #225 est la deadzone nécessaire pour que le robot ne fonce pas dans la balle

            if 0 < dist < deadzone:  # si la distance est exactement 0, la position n'est pas bonne
                self._succeed(joueur)
            else:
                orientation = player.pose.orientation
                command = Command.MoveToAndRotate(player, self.team,
                                                  Pose(position, orientation))
                self._send_command(command)
Exemple #29
0
    def exec(self):
        for player in self.ws.game_state.my_team.available_players.values():
            if player.ai_command is None:
                continue

            cmd = player.ai_command
            r_id = player.id

            if cmd.command is AICommandType.MOVE:
                if cmd.control_loop_type is AIControlLoopType.POSITION:
                    cmd.speed = self.robot_motion[r_id].update(cmd)

                elif cmd.control_loop_type is AIControlLoopType.SPEED:
                    speed = fixed2robot(cmd.pose_goal.conv_2_np(),
                                        player.pose.orientation)
                    cmd.speed = Pose(Position(speed[Pos.X], speed[Pos.Y]),
                                     speed[Pos.THETA])

                elif cmd.control_loop_type is AIControlLoopType.OPEN:
                    cmd.speed = cmd.pose_goal

            elif cmd.command is AICommandType.STOP:
                cmd.speed = Pose(Position(0, 0), 0)
                self.robot_motion[r_id].stop()
    def __init__(self, p_game_state):
        super().__init__(p_game_state)
        ourgoal = Pose(
            Position(GameState().const["FIELD_OUR_GOAL_X_EXTERNAL"], 0), 0)
        self.theirgoal = Pose(
            Position(GameState().const["FIELD_THEIR_GOAL_X_EXTERNAL"], 0), 0)

        roles_to_consider = [
            Role.FIRST_ATTACK, Role.SECOND_ATTACK, Role.MIDDLE,
            Role.FIRST_DEFENCE, Role.SECOND_DEFENCE
        ]
        role_by_robots = [(i, self.game_state.get_player_by_role(i))
                          for i in roles_to_consider]

        goalkeeper = self.game_state.get_player_by_role(Role.GOALKEEPER)

        self.add_tactic(Role.GOALKEEPER,
                        GoalKeeper(self.game_state, goalkeeper, ourgoal))

        for index, player in role_by_robots:
            if player:
                self.add_tactic(
                    index,
                    PositionForPass(self.game_state,
                                    player,
                                    auto_position=True))
                self.add_tactic(
                    index,
                    GoKick(self.game_state, player, auto_update_target=True))

                self.add_condition(index, 0, 1,
                                   partial(self.is_closest, player))
                self.add_condition(index, 1, 0,
                                   partial(self.is_not_closest, player))
                self.add_condition(index, 1, 1,
                                   partial(self.has_kicked, player))
    def test_exec(self):
        next_ai_command = self.graph1.exec()
        expected_ai_command = Idle(self.game_state, self.a_player).exec()

        self.assertEqual(self.graph1.current_node, 1)
        self.assertEqual(next_ai_command, expected_ai_command)

        self.assertRaises(EmptyGraphException, self.empty_graph.exec)

        self.empty_graph.add_node(self.node2)
        self.empty_graph.add_node(self.node1)
        self.empty_graph.add_vertex(0, 1, foo2)

        next_ai_command = self.empty_graph.exec()
        expected_ai_command = GoToPositionNoPathfinder(
            self.game_state, self.a_player, Pose(Position(500, 0), 0)).exec()
        self.assertEqual(self.empty_graph.current_node, 0)
        self.assertEqual(next_ai_command, expected_ai_command)

        next_ai_command = self.empty_graph.exec()
        expected_ai_command = GoToPositionNoPathfinder(
            self.game_state, self.a_player, Pose(Position(500, 0), 0)).exec()
        self.assertEqual(self.empty_graph.current_node, 0)
        self.assertEqual(next_ai_command, expected_ai_command)