예제 #1
0
 def __init__(self):
     self.ball = Ball(Point(Constants.ball_start_x, Constants.ball_start_y))
     self.ally1 = Robot(
         Constants.team_us, Constants.ally_1_id,
         Position(Point(Constants.ally_1_start_x, Constants.ally_1_start_y),
                  Angle(Constants.ally_1_start_a, True)))
     self.ally2 = Robot(
         Constants.team_us, Constants.ally_2_id,
         Position(Point(Constants.ally_2_start_x, Constants.ally_2_start_y),
                  Angle(Constants.ally_2_start_a, True)))
     self.opp1 = Robot(
         Constants.team_us, Constants.opp_1_id,
         Position(Point(Constants.opp_1_start_x, Constants.opp_1_start_y),
                  Angle(Constants.opp_1_start_a, True)))
     self.opp2 = Robot(
         Constants.team_us, Constants.opp_2_id,
         Position(Point(Constants.opp_2_start_x, Constants.opp_2_start_y),
                  Angle(Constants.opp_2_start_a, True)))
예제 #2
0
def get_ellipse_position(game_state):
    x_axis = Constants.goalie_dist_from_goal
    y_axis = Constants.goal_box_width / 2
    point = game_state.field.ball.point
    center = Vector(Constants.goal_point_left_x, Constants.goal_point_left_y)
    norm_point = point - center
    swapped_point = Point(norm_point.y,
                          norm_point.x)  # because x < y for ellipse
    return gf.closest_point_on_ellipse(center, x_axis, y_axis, point)
예제 #3
0
def get_smart_goalie_position(game_state, distance):
    """Return a point at specified distance from goal toward the ball

   It will be the closest point from the ball to goal line, where the goal ends
   on top and bottom.

   game_state (GameState) : Current state of game
   distance (Float)       : Distance from goal
   return (Point)         : A point `distance` away from goal in direction of
                            ball

   """
    field_half_w = field_width / 2
    # if game_state.game_info.side == 'away':
    if game_state.game_info.side == 'home':
        field_half_w = -field_half_w

    global count, prev_ball_point, prev_prev_ball_point
    ball_point = game_state.field.ball.point
    count = (count + 1) % 5
    if count == 0:
        prev_prev_ball_point = prev_ball_point
        prev_ball_point = ball_point
    delta_x = prev_ball_point.x - prev_prev_ball_point.x
    if count == 0:
        print 'delta_x = {}'.format(delta_x)
    goal_center_point = field_half_w  # game_state.game_info.get_home_goal_point()
    if abs(delta_x) > 0.01:
        delta_y = prev_ball_point.y - prev_prev_ball_point.y
        dist_to_goal = goal_center_point - prev_prev_ball_point.x
        future_y = delta_y / delta_x * dist_to_goal
    else:
        future_y = ball_point.y
    if future_y > Constants.goal_top_y:
        goal_point = Point(goal_center_point, Constants.goal_top_y)
    elif future_y < Constants.goal_bottom_y:
        goal_point = Point(goal_center_point, Constants.goal_bottom_y)
    else:
        goal_point = Point(goal_center_point, future_y)
    vec = ball_point - goal_point
    angle = vec.get_angle()
    # print "commanded angle: %s" % angle
    offset = angle.get_normalized_vector().get_scaled(distance)
    return Position(goal_point + offset, angle)
예제 #4
0
def test():
    from Models import GameState, Field, GameInfo

    f1 = Field()
    gi1 = GameInfo(Constants.left_side)
    gs1 = GameState(f1, gi1)
    cmds1 = stay_between_goalnball(gs1, f1.ally2)
    print 'cmds1: {}'.format(cmds1)

    f2 = Field()
    f2.ball.point = Point(1.5, -1.0)
    gi2 = GameInfo(Constants.right_side)
    gs2 = GameState(f2, gi2)
    cmds2 = stay_between_goalnball(gs2, f2.ally2)
    print 'cmds2: {}'.format(cmds2)
예제 #5
0
def _pose2d_to_point(pose2d):
    return Point(pose2d.x, pose2d.y)
예제 #6
0
def _pose2d_to_position(pose2d):
    return Position(Point(pose2d.x, pose2d.y), Angle(pose2d.theta, True))
예제 #7
0
 def go_to_center(self):
     # set desired position to be center facing goal
     center_point = Point(0, 0)
     goal_angle = Angle(0, True)
     return Position(center_point, goal_angle)
예제 #8
0
 def __init__(self):
     super(SkillTest, self).__init__()
     self.timer = 0
     self.me = Position(Point(0, 0), Angle(0, True))
     self.ball = Position(Point(0, 0), Angle(0, True))
예제 #9
0
def p2d_2_pos(p):
    return Position(Point(p.x, p.y), Angle(p.theta, False))
예제 #10
0
 def get_opp_goal_point(self):
     return Point(Constants.goal_point_left_x, Constants.goal_point_left_y)
예제 #11
0

# This isn't working yet
def get_ellipse_position(game_state):
    x_axis = Constants.goalie_dist_from_goal
    y_axis = Constants.goal_box_width / 2
    point = game_state.field.ball.point
    center = Vector(Constants.goal_point_left_x, Constants.goal_point_left_y)
    norm_point = point - center
    swapped_point = Point(norm_point.y,
                          norm_point.x)  # because x < y for ellipse
    return gf.closest_point_on_ellipse(center, x_axis, y_axis, point)


count = 0
prev_ball_point = Point(0, 0)
prev_prev_ball_point = Point(0, 0)
field_width = 3.40


def get_smart_goalie_position(game_state, distance):
    """Return a point at specified distance from goal toward the ball

   It will be the closest point from the ball to goal line, where the goal ends
   on top and bottom.

   game_state (GameState) : Current state of game
   distance (Float)       : Distance from goal
   return (Point)         : A point `distance` away from goal in direction of
                            ball