예제 #1
0
    def compute_wall_segment(self):
        """
            We compute the position where the wall's robot can block the field of view of opposing robot with the ball.
            The field of view is defined as the triangle created by the ball and the goal_line extremities.
        """

        nb_robots = len(self.robots_in_formation)
        wall_segment_length = nb_robots * ROBOT_DIAMETER + GAP_IN_WALL * (nb_robots - 1)

        goal_line = self.game_state.field.our_goal_line
        bisection_angle = angle_between_three_points(goal_line.p2, self.object_to_block.position, goal_line.p1)

        # We calculate the farthest distance from the object which completely block its FOV of the goal
        object_to_center_formation_dist = wall_segment_length / tan(bisection_angle)

        self.bisect_inter = find_bisector_of_triangle(self.object_to_block.position, goal_line.p1, goal_line.p2)
        vec_object_to_goal_line_bisect = self.bisect_inter - self.object_to_block.position

        # The penalty zone used to be a circle and thus really easy to handle, but now it's a rectangle...
        # It easier to first create the smallest circle that fit the rectangle.
        min_radius_over_penality_zone = ROBOT_RADIUS + (self.game_state.field.our_goal_area.upper_left - self.game_state.field.our_goal).norm
        object_to_block_to_center_formation_dist = min(vec_object_to_goal_line_bisect.norm - min_radius_over_penality_zone,
                                                       object_to_center_formation_dist)

        self.center_formation = object_to_block_to_center_formation_dist * normalize(vec_object_to_goal_line_bisect) + self.object_to_block.position

        if self.stay_away_from_ball:
            if (self.game_state.ball_position - self.center_formation).norm < KEEPOUT_DISTANCE_FROM_BALL:
                self.center_formation = self._closest_point_away_from_ball()

        half_wall_segment = 0.5 * wall_segment_length * perpendicular(normalize(vec_object_to_goal_line_bisect))
        self.wall_segment = Line(self.center_formation + half_wall_segment,
                                 self.center_formation - half_wall_segment)
예제 #2
0
def get_away_from_trajectory(position, start, end, min_distance):
    try:
        point = closest_point_on_line(position, start, end)
        dist = position - point
    except ZeroDivisionError:
        point = position
        dist = perpendicular(end - start) * min_distance/2
    if dist.norm < min_distance:
        return point - dist.norm * min_distance
    else:
        return position
예제 #3
0
 def wait_for_ball(self):
     perp_vec = perpendicular(self.player.position - self.game_state.ball.position)
     component_lateral = perp_vec * np.dot(perp_vec.array, normalize(self.game_state.ball.velocity).array)
     small_segment_len = np.sqrt(1 - component_lateral.norm**2)
     latteral_move = component_lateral / small_segment_len * (self.player.position - self.game_state.ball.position).norm
     if self._get_distance_from_ball() < HAS_BALL_DISTANCE:
         self.next_state = self.halt
         return self.halt()
     if not self.is_ball_going_to_collide(threshold=18):
         self.next_state = self.wait_for_ball
         return CmdBuilder().build()
     orientation = (self.game_state.ball_position - self.player.position).angle
     return CmdBuilder().addMoveTo(Pose(self.player.position + latteral_move.view(Position), orientation),
                                   cruise_speed=3,
                                   end_speed=0,
                                   ball_collision=False).addChargeKicker().build()
예제 #4
0
 def wait_for_ball(self):
     perp_vec = perpendicular(self.player.position -
                              self.game_state.ball.position)
     component_lateral = perp_vec * np.dot(
         perp_vec.array,
         normalize(self.game_state.ball.velocity).array)
     small_segment_len = np.sqrt(1 - component_lateral.norm**2)
     latteral_move = component_lateral / small_segment_len * (
         self.player.position - self.game_state.ball.position).norm
     if self._get_distance_from_ball() < HAS_BALL_DISTANCE:
         self.next_state = self.halt
         return self.halt()
     if not self.is_ball_going_to_collide(threshold=18):
         self.next_state = self.wait_for_ball
         return CmdBuilder().build()
     orientation = (self.game_state.ball_position -
                    self.player.position).angle
     return CmdBuilder().addMoveTo(
         Pose(self.player.position + latteral_move.view(Position),
              orientation),
         cruise_speed=3,
         end_speed=0,
         ball_collision=False).addChargeKicker().build()
예제 #5
0
def test_perpendicular_identity():
    assert perpendicular(A_POS) is not A_POS
예제 #6
0
def test_perpendicular_return_type():
    assert isinstance(perpendicular(A_POS), Position)
예제 #7
0
def test_perpendicular_base_case():
    assert perpendicular(A_POS) == A_POS_PERPENDICULAR
예제 #8
0
def test_perpendicular_identity():
    assert perpendicular(A_POS) is not A_POS
예제 #9
0
def test_perpendicular_return_type():
    assert isinstance(perpendicular(A_POS), Position)
예제 #10
0
def test_perpendicular_base_case():
    assert perpendicular(A_POS) == A_POS_PERPENDICULAR