Exemplo n.º 1
0
    def defend_ball(self, robot_id):
        if robot_id != 0:
            return None
        if self.reset_reason != NONE:
            return None

        # GK takes 250ms to perform defense move
        predicted_ball_gk = helper.predict_ball(self.cur_ball, self.prev_ball,
                                                self.reset_reason, 5)

        if predicted_ball_gk[X] < self.cur_posture[robot_id][X] + 0.1:
            # right part of the goal
            if -0.65 < predicted_ball_gk[Y] < -0.07:
                # top part of the goal
                if (predicted_ball_gk[Z] > 0.25):
                    return [0, 0, 0, 0, 7, 0]
                else:
                    return [0, 0, 0, 0, 6, 0]
            # center part of the goal
            if -0.07 < predicted_ball_gk[Y] < 0.07:
                # top part of the goal
                if (predicted_ball_gk[Z] > 0.25):
                    return [0, 0, 0, 0, 8, 0]
                else:
                    return [0, 0, 0, 0, 3, 0]
            # left part of the goal
            if 0.07 < predicted_ball_gk[Y] < 0.65:
                # top part of the goal
                if (predicted_ball_gk[Z] > 0.25):
                    return [0, 0, 0, 0, 9, 0]
                else:
                    return [0, 0, 0, 0, 10, 0]
        else:
            return None
    def update(self, received_frame):

        if received_frame.end_of_frame:

            self._frame += 1

            if (self._frame == 1):
                self.previous_frame = received_frame
                self.get_coord(received_frame)
                self.previous_ball = self.cur_ball

            self.get_coord(received_frame)
            self.predicted_ball = helper.predict_ball(self.cur_ball,
                                                      self.previous_ball, 2)
            self.idx_d = helper.find_closest_robot(self.cur_ball,
                                                   self.cur_posture, [1, 2])
            self.idx_a = helper.find_closest_robot(self.cur_ball,
                                                   self.cur_posture_opp,
                                                   [3, 4])

            #(update the robots wheels)
            # Robot Functions
            self.speeds[4 * self.gk_index:4 * self.gk_index +
                        4] = self.GK.move(self.gk_index, self.idx_d,
                                          self.idx_a, self.cur_posture,
                                          self.cur_posture_opp,
                                          self.previous_ball, self.cur_ball,
                                          self.predicted_ball)
            self.speeds[4 * self.d1_index:4 * self.d1_index +
                        4] = self.D1.move(self.d1_index, self.idx_d,
                                          self.idx_a, self.cur_posture,
                                          self.cur_posture_opp,
                                          self.previous_ball, self.cur_ball,
                                          self.predicted_ball)
            self.speeds[4 * self.d2_index:4 * self.d2_index +
                        4] = self.D2.move(self.d2_index, self.idx_d,
                                          self.idx_a, self.cur_posture,
                                          self.cur_posture_opp,
                                          self.previous_ball, self.cur_ball,
                                          self.predicted_ball)
            self.speeds[4 * self.f1_index:4 * self.f1_index +
                        4] = self.F1.move(self.f1_index, self.idx_d,
                                          self.idx_a, self.cur_posture,
                                          self.cur_posture_opp,
                                          self.previous_ball, self.cur_ball,
                                          self.predicted_ball)
            self.speeds[4 * self.f2_index:4 * self.f2_index +
                        4] = self.F2.move(self.f2_index, self.idx_d,
                                          self.idx_a, self.cur_posture,
                                          self.cur_posture_opp,
                                          self.previous_ball, self.cur_ball,
                                          self.predicted_ball)

            self.set_speeds(self.speeds)

            self.previous_frame = received_frame
            self.previous_ball = self.cur_ball
            self.end_of_frame = False
Exemplo n.º 3
0
    def update(self, received_frame):

        if (received_frame.end_of_frame):
	    
            self._frame += 1

            if (self._frame == 1):
                self.previous_frame = received_frame
                self.get_coord(received_frame)
                self.previous_ball = self.cur_ball

            self.get_coord(received_frame)
            self.predicted_ball = helper.predict_ball(self.cur_ball, self.previous_ball)
            self.idx = helper.find_closest_robot(self.cur_ball, self.cur_posture, self.number_of_robots)
            self.idx_opp = helper.find_closest_robot(self.cur_ball, self.cur_posture_opp, self.number_of_robots)
            self.defense_angle = helper.get_defense_kick_angle(self.predicted_ball, self.field, self.cur_ball)
            self.attack_angle = helper.get_attack_kick_angle(self.predicted_ball, self.field)

##############################################################################
            #(update the robots wheels)
            # Robot Functions
            self.speeds[6 * self.gk_index : 6 * self.gk_index + 6] = self.GK.move(self.gk_index, 
                                                                                self.idx, self.idx_opp, 
                                                                                self.defense_angle, self.attack_angle,
                                                                                self.cur_posture, self.cur_posture_opp,
                                                                                self.previous_ball, self.cur_ball, self.predicted_ball)
            self.speeds[6 * self.d1_index : 6 * self.d1_index + 6] = self.D1.move(self.d1_index, 
                                                                                self.idx, self.idx_opp, 
                                                                                self.defense_angle, self.attack_angle,
                                                                                self.cur_posture, self.cur_posture_opp,
                                                                                self.previous_ball, self.cur_ball, self.predicted_ball)
            self.speeds[6 * self.d2_index : 6 * self.d2_index + 6] = self.D2.move(self.d2_index, 
                                                                                self.idx, self.idx_opp, 
                                                                                self.defense_angle, self.attack_angle,
                                                                                self.cur_posture, self.cur_posture_opp,
                                                                                self.previous_ball, self.cur_ball, self.predicted_ball)
            self.speeds[6 * self.f1_index : 6 * self.f1_index + 6] = self.F1.move(self.f1_index, 
                                                                                self.idx, self.idx_opp, 
                                                                                self.defense_angle, self.attack_angle,
                                                                                self.cur_posture, self.cur_posture_opp,
                                                                                self.previous_ball, self.cur_ball, self.predicted_ball)
            self.speeds[6 * self.f2_index : 6 * self.f2_index + 6] = self.F2.move(self.f2_index, 
                                                                                self.idx, self.idx_opp, 
                                                                                self.defense_angle, self.attack_angle,
                                                                                self.cur_posture, self.cur_posture_opp,
                                                                                self.previous_ball, self.cur_ball, self.predicted_ball)
            
            self.set_speeds(self.speeds)
##############################################################################

            self.previous_frame = received_frame
            self.previous_ball = self.cur_ball

            helper.print_debug_flag(self)
Exemplo n.º 4
0
    def update(self, received_frame):

        if (received_frame.end_of_frame):

            self._frame += 1

            if (self._frame == 1):
                self.previous_frame = received_frame
                self.get_coord(received_frame)
                self.previous_ball = self.cur_ball
                self.previous_posture = self.cur_posture
                self.previous_posture_opp = self.cur_posture_opp

            self.get_coord(received_frame)
            self.predicted_ball = helper.predict_ball(
                self.cur_ball, self.previous_ball, received_frame.reset_reason)
            self.idx = helper.find_closest_robot(self.cur_ball,
                                                 self.cur_posture,
                                                 self.number_of_robots)
            self.idx_opp = helper.find_closest_robot(self.cur_ball,
                                                     self.cur_posture_opp,
                                                     self.number_of_robots)
            self.defense_angle = helper.get_defense_kick_angle(
                self.predicted_ball, self.field, self.cur_ball)
            self.attack_angle = helper.get_attack_kick_angle(
                self.predicted_ball, self.field)

            ##############################################################################
            #(update the robots wheels)
            self.speeds = self.team.move(
                self.idx, self.idx_opp, self.defense_angle, self.attack_angle,
                self.cur_posture, self.cur_posture_opp, self.previous_posture,
                self.previous_posture_opp, self.previous_ball, self.cur_ball,
                self.predicted_ball, received_frame.reset_reason,
                received_frame.game_state)
            self.set_speeds(self.speeds)
            ##############################################################################

            self.previous_frame = received_frame
            self.previous_ball = self.cur_ball
            self.previous_posture = self.cur_posture
            self.previous_posture_opp = self.cur_posture_opp