Пример #1
0
    def __init__(self):
        super().__init__(continuous=False)

        #TODO: find a better way to do this so it can be a sub 1-second pause
        self.pause = 0

        for substate in Tune_pid.State:
            self.add_state(substate, behavior.Behavior.State.running)

        self.add_transition(behavior.Behavior.State.start, Tune_pid.State.tune,
                            lambda: True, 'immediately')

        self.add_transition(
            Tune_pid.State.tune, Tune_pid.State.process,
            lambda: self.subbehavior_with_name('move').state == behavior.
            Behavior.State.completed, 'finished moving')

        self.add_transition(Tune_pid.State.process, Tune_pid.State.tune,
                            lambda: self.tune and time.time() - self.pause > 1,
                            'continue tuning')

        self.add_transition(Tune_pid.State.process,
                            behavior.Behavior.State.completed,
                            lambda: not self.tune, 'done tuning')

        xsize = constants.Field.Width / 10

        self.left_point = robocup.Point(-xsize, 2)
        self.right_point = robocup.Point(xsize, 2)

        self.tune = True

        self.pause = 0
Пример #2
0
    def __init__(self):
        super().__init__(continuous=False)

        self._kicker_shell_id = None

        for state in OurKickoff.State:
            self.add_state(state, behavior.Behavior.State.running)

        self.add_transition(behavior.Behavior.State.start,
                            OurKickoff.State.setup, lambda: True,
                            'immediately')

        self.add_transition(OurKickoff.State.setup, OurKickoff.State.kick,
                            lambda: not main.game_state().is_setup_state(),
                            "referee leaves setup")

        self.add_transition(
            OurKickoff.State.kick, behavior.Behavior.State.completed,
            lambda: self.has_subbehavior_with_name('kicker') and self.
            subbehavior_with_name('kicker').is_done_running(),
            "kicker finished")

        # TODO: verify that these values are right - I'm fuzzy on my matrix multiplication...
        idle_positions = [
            robocup.Point(0.7, constants.Field.Length / 2.0 - 0.2),
            robocup.Point(-0.7, constants.Field.Length / 2.0 - 0.2)
        ]
        self.centers = []
        for i, pos_i in enumerate(idle_positions):
            center_i = skills.move.Move(pos_i)
            self.add_subbehavior(center_i,
                                 'center' + str(i),
                                 required=False,
                                 priority=4 - i)
            self.centers.append(center_i)
Пример #3
0
    def create_lineup(self):
        xsize = constants.Field.Width / 2 - .5
        if self._pos.x > 0:
            xsize = -xsize

        return robocup.Segment(robocup.Point(xsize, 1),
                               robocup.Point(xsize, 2.5))
Пример #4
0
    def calculate_area_risk_scores(self, bot):
        max_dist = robocup.Point(constants.Field.Length,
                                 constants.Field.Width).mag()
        our_goal = robocup.Point(0, 0)
        ball_goal_sens = 2.5
        dist_sens = 1.5

        # How far away the robot is from the ball, further is higher
        ball_dist = 1 - pow(1 - dist_sens *
                            (bot.pos - main.ball().pos).mag() / max_dist, 2)
        # How large the angle is between the ball, goal, and opponent, smaller angle is better
        ball_goal_opp = 1 - math.pow(
            math.fabs(
                (main.ball().pos - our_goal).angle_between(our_goal - bot.pos))
            / math.pi, ball_goal_sens)
        # Location on the field based on closeness to the goal line, closer is better
        field_pos = evaluation.field.field_pos_coeff_at_pos(bot.pos, 0, 1, 0,
                                                            False)

        risk_score = WingerWall.AREA_RISK_WEIGHTS[0] * ball_dist + \
                     WingerWall.AREA_RISK_WEIGHTS[1] * ball_goal_opp + \
                     WingerWall.AREA_RISK_WEIGHTS[2] * field_pos

        risk_score /= sum(WingerWall.AREA_RISK_WEIGHTS)

        return risk_score
Пример #5
0
    def goto_center(self):
        num_robots = 0
        for b in self.all_subbehaviors():
            if b.robot is not None:
                num_robots += 1

        num_robots = max(self.min_robots, num_robots)

        radius = constants.Field.CenterRadius + constants.Robot.Radius + 0.01

        perRobot = math.pi / max(num_robots, 1)

        ball_pos = robocup.Point(0, constants.Field.Length / 2)

        dirvec = (robocup.Point(0, 0) - ball_pos).normalized() * radius
        dirvec.rotate(robocup.Point(0, 0), -perRobot * ((num_robots - 1) / 2))

        for i in range(6):
            pt = ball_pos + dirvec
            self.subbehavior_with_name("robot" + str(i)).pos = pt
            dirvec.rotate(robocup.Point(0, 0), perRobot)

        # set robot attributes
        for b in self.all_subbehaviors():
            if b.robot is not None:
                b.robot.set_avoid_ball_radius(constants.Field.CenterRadius)
                b.robot.face(main.ball().pos)
Пример #6
0
def generate_default_rectangle(kick_point):
    offset_from_edge = 0.25
    offset_from_ball = 0.4
    # offset_from_ball = 0.7

    if kick_point.x > 0:
        # Ball is on right side of field
        toReturn = robocup.Rect(
            robocup.Point(
                0,
                min(constants.Field.Length - offset_from_edge,
                    main.ball().pos.y - offset_from_ball)),
            robocup.Point(
                -constants.Field.Width / 2 + offset_from_edge,
                min(constants.Field.Length * 3 / 4,
                    main.ball().pos.y - 2)))
    else:
        # Ball is on left side of field
        toReturn = robocup.Rect(
            robocup.Point(
                0,
                min(constants.Field.Length - offset_from_edge,
                    main.ball().pos.y - offset_from_ball)),
            robocup.Point(
                constants.Field.Width / 2 - offset_from_edge,
                min(constants.Field.Length * 3 / 4,
                    main.ball().pos.y - 2)))
    return toReturn
Пример #7
0
    def execute_running(self):
        super().execute_running()
        kicker = self.subbehavior_with_name('kicker')
        center1 = self.subbehavior_with_name('center1')
        center2 = self.subbehavior_with_name('center2')

        # see if we have a direct shot on their goal
        win_eval = robocup.WindowEvaluator(main.system_state())
        win_eval.enable_chip = kicker.robot != None and kicker.robot.has_chipper(
        )
        win_eval.min_chip_range = OurGoalKick.MinChipRange
        win_eval.max_chip_range = OurGoalKick.MaxChipRange
        windows, best = win_eval.eval_pt_to_seg(
            main.ball().pos, constants.Field.TheirGoalSegment)

        # note: the min length value is tunable
        if best != None and best.segment.length() > 0.3:
            # we DO have a shot on the goal, take it!
            kicker.target = constants.Field.TheirGoalSegment

            # FIXME: make the other robots get out of the shot path

            center1.target = robocup.Point(0.0, 1.5)
            center2.target = robocup.Point(1.0, 1.5)

        else:
            # no open shot, shoot it in-between the two centers
            center_x = constants.Field.Width * 0.15
            center_y = constants.Field.Length * 0.6

            center1.target = robocup.Point(-center_x, center_y)
            center2.target = robocup.Point(center_x, center_y)

            kicker.target = robocup.Segment(center1.target, center2.target)
Пример #8
0
    def execute_running(self):
        # run subbehaviors
        num_robots = 0
        for b in self.all_subbehaviors():
            if b.robot is not None:
                num_robots+=1

        radius = constants.Field.CenterRadius + constants.Robot.Radius + 0.01

        perRobot = (2 * constants.Robot.Radius * 1.25) / radius * (180.0 / math.pi)

        ball_pos = main.ball().pos if main.ball() != None else robocup.Point(constants.Field.Width / 2, constants.Field.Length / 2)

        dirvec = (robocup.Point(0,0) - ball_pos).normalized() * radius
        dirvec.rotate(robocup.Point(0,0), -perRobot * ((num_robots - 1) / 2))

        for i in range(6):
            pt = ball_pos + dirvec
            self.subbehavior_with_name("robot" + str(i)).pos = pt
            dirvec.rotate(robocup.Point(0,0), perRobot)

        # set robot attributes
        for b in self.all_subbehaviors():
            if b.robot is not None:
                b.robot.set_avoid_ball_radius(constants.Field.CenterRadius)
                b.robot.face(main.ball().pos)
                b.robot.avoid_all_teammates(True)
Пример #9
0
    def __init__(self):
        super().__init__(continuous=True)

        self.add_transition(behavior.Behavior.State.start,
                            behavior.Behavior.State.running, lambda: True,
                            'immediately')

        # FIXME: this could also be a PivotKick
        kicker = skills.line_kick.LineKick()
        # kicker.use_chipper = True
        kicker.min_chip_range = 0.3
        kicker.max_chip_range = 3.0
        kicker.target = constants.Field.TheirGoalSegment
        self.add_subbehavior(kicker, 'kicker', required=False, priority=5)

        # add two 'centers' that just move to fixed points
        center1 = skills.move.Move(robocup.Point(0, 1.5))
        self.add_subbehavior(center1, 'center1', required=False, priority=4)
        center2 = skills.move.Move(robocup.Point(0, 1.5))
        self.add_subbehavior(center1, 'center2', required=False, priority=3)

        self.add_subbehavior(tactics.defense.Defense(),
                             'defense',
                             required=False)

        self.add_transition(
            behavior.Behavior.State.running, behavior.Behavior.State.completed,
            lambda: kicker.is_done_running(), 'kicker completes')
Пример #10
0
    def execute_setup(self):
        move_goal = main.ball().pos - self._target_line.delta().normalized(
        ) * (self.drive_around_dist + constants.Robot.Radius)

        left_field_edge = robocup.Segment(
            robocup.Point(
                -constants.Field.Width / 2.0 - constants.Robot.Radius, 0),
            robocup.Point(
                -constants.Field.Width / 2.0 - constants.Robot.Radius,
                constants.Field.Length))
        right_field_edge = robocup.Segment(
            robocup.Point(constants.Field.Width / 2.0 + constants.Robot.Radius,
                          0),
            robocup.Point(constants.Field.Width / 2.0 + constants.Robot.Radius,
                          constants.Field.Length))

        # handle the case when the ball is near the field's edge
        field_edge_thresh = 0.3
        behind_line = robocup.Segment(
            main.ball().pos -
            self._target_line.delta().normalized() * self.drive_around_dist,
            main.ball().pos - self._target_line.delta().normalized())
        main.debug_drawer().draw_line(behind_line, constants.Colors.Blue,
                                      "LineKickOld")
        for edge in [left_field_edge, right_field_edge]:
            if edge.near_point(main.ball().pos, field_edge_thresh):
                intersection = behind_line.segment_intersection(edge)
                if intersection != None:
                    move_goal = intersection

        self.robot.set_avoid_ball_radius(self.setup_ball_avoid)
        self.robot.move_to(move_goal)
        self.robot.face(self.robot.pos +
                        (self.aim_target_point - main.ball().pos))
        self.robot.unkick()
Пример #11
0
    def __init__(self):
        super().__init__(continuous=True)

        self.add_transition(behavior.Behavior.State.start,
            behavior.Behavior.State.running,
            lambda: True,
            'immediately')
        self.add_transition(behavior.Behavior.State.running,
            behavior.Behavior.State.completed,
            lambda: self.all_subbehaviors_completed(),
            'all robots reach target positions')
        self.add_transition(behavior.Behavior.State.completed,
            behavior.Behavior.State.running,
            lambda: not self.all_subbehaviors_completed(),
            "robots aren't lined up")

        # Define circle to circle up on
        radius = constants.Field.CenterRadius + constants.Robot.Radius + 0.01

        perRobot = (2 * constants.Robot.Radius* 1.25) / radius

        ball_pos = main.ball().pos if main.ball() != None else robocup.Point(constants.Field.Width / 2, constants.Field.Length / 2)

        dirvec = (robocup.Point(0,0) - ball_pos).normalized() * radius

        for i in range(6):
            pt = ball_pos + dirvec
            self.add_subbehavior(skills.move.Move(pt), name="robot" + str(i), required=False, priority=6 - i)
            dirvec.rotate(robocup.Point(0,0), perRobot)
Пример #12
0
    def __init__(self):
        super().__init__(continuous=True)

        self.add_state(Dual_Shot.State.setup, 
            behavior.Behavior.State.running)

        self.add_transition(behavior.Behavior.State.start,
            Dual_Shot.State.setup,
            lambda:True, 'immediately')

        self.add_transition(Dual_Shot.State.setup, 
            Dual_Shot.State.passing,
            lambda: self.all_subbehaviors_completed(),
            'all subbehaviors completed')

        self.add_transition(Dual_Shot.State.passing,
            Dual_Shot.State.scoring,
            lambda: self.all_subbehaviors_completed(),
            'all subbehaviors completed')



        self.shooting_points = [
            robocup.Point(constants.Field.Width/4.0,constants.Field.Length*3/4.0),
            robocup.Point(-constants.Field.Width/4.0,constants.Field.Length*3/4.0)
        ]
Пример #13
0
    def on_enter_passing(self):
        # kickFrom = min(self.shooting_points,
        #     key=lambda pt: pt.dist_to(main.ball().pos))
        # kickFromIdx = self.shooting_points.index(kickFrom)
        # kickToIdx = (kickFromIdx + 1) % len(self.shooting_points)
        # kickToPt = self.shooting_points[kickToIdx]
        line0 = robocup.Segment(
                self.shooting_points[0]-robocup.Point(0.5,0)
                self.shooting_points[0]+robocup.Point(0.5,0))
        line1 = robocup.Segment(
                self.shooting_points[1]-robocup.Point(0.5,0)
                self.shooting_points[1]+robocup.Point(0.5,0)
        if shot.eval_shot(main.ball().pos, line0) > shot.eval_shot(main.ball().pos, line1):
            self.add_subbehavior(tactics.coordinated_pass.CoordinatedPass(self.shooting_points[0]),
                'pass')
        else:
            self.add_subbehavior(tactics.coordinated_pass.CoordinatedPass(self.shooting_points[1]),
                'pass')
        # kickTo = max(shot.eval_shot(main.ball().pos, self.shooting_points[0]), 
        #     shot.eval_shot(main.ball().pos, self.shooting_points[1]),
        #     key=lambda pt: pt.dist_to(main.ball().pos))
        # kickToIdx = self.shooting_points.index(kickTo)

        # self.add_subbehavior(tactics.coordinated_pass.CoordinatedPass(kickToPt),
        #     'pass')

    def on_exit_passing(self):
        self.remove_all_subbehaviors()

    def on_enter_scoring(self):
        self.add_subbehavior(tactics.coordinated_pass.CoordinatedPass(min(pt.dist_to(main.ball().pos))),
            'pass')

    def on_exit_winning(self):
        self.remove_all_subbehaviors()
Пример #14
0
def robot_has_ball(robot):
    mouth_half_angle = 15 * math.pi / 180  # Angle from front
    max_dist_from_mouth = 1.13 * (constants.Robot.Radius +
                                  constants.Ball.Radius)

    # Create triangle between bot pos and two points of the mouth
    A = robot.pos
    B = A + robocup.Point(
        max_dist_from_mouth * math.cos(robot.angle - mouth_half_angle),
        max_dist_from_mouth * math.sin(robot.angle - mouth_half_angle))
    C = A + robocup.Point(
        max_dist_from_mouth * math.cos(robot.angle + mouth_half_angle),
        max_dist_from_mouth * math.sin(robot.angle + mouth_half_angle))
    D = main.ball().pos

    # Barycentric coordinates to solve whether the ball is in that triangle
    area = 0.5 * (-B.y * C.x + A.y * (-B.x + C.x) + A.x *
                  (B.y - C.y) + B.x * C.y)
    s = 1 / (2 * area) * (A.y * C.x - A.x * C.y + (C.y - A.y) * D.x +
                          (A.x - C.x) * D.y)
    t = 1 / (2 * area) * (A.x * B.y - A.y * B.x + (A.y - B.y) * D.x +
                          (B.x - A.x) * D.y)

    # Due to the new camera configuration in the 2019 year,
    # the ball dissapears consistently when we go to capture a ball near the
    # edge of the field. This causes the ball to "appear" inside the robot
    # so we should assume that if the ball is inside, we probably have
    # the ball
    ball_inside_robot = (robot.pos - main.ball().pos).mag() < \
                        constants.Robot.Radius + constants.Ball.Radius

    return (s > 0 and t > 0 and (1 - s - t) > 0) or ball_inside_robot
Пример #15
0
    def goto_center(self):
        num_robots = 0
        for b in self.all_subbehaviors():
            if b.robot is not None:
                num_robots += 1

        #if the number of robots has changed, recreate move behaviors to match new number of robots
        if (self.num_robots != num_robots):
            self.num_robots = num_robots
            self.add_circle_subbehaviors()

        num_robots = max(self.min_robots, num_robots)

        radius = constants.Field.CenterRadius + constants.Robot.Radius + 0.01

        perRobot = math.pi / max(num_robots, 1)

        ball_pos = robocup.Point(0, constants.Field.Length / 2)

        dirvec = (robocup.Point(0, 0) - ball_pos).normalized() * radius
        dirvec.rotate(robocup.Point(0, 0), -perRobot * ((num_robots - 1) / 2))

        #assign points to the behaviors with robots
        for i in range(num_robots):
            pt = ball_pos + dirvec
            self.subbehavior_with_name("robot" + str(i)).pos = pt
            dirvec.rotate(robocup.Point(0, 0), perRobot)

        # set robot attributes
        for b in self.all_subbehaviors():
            if b.robot is not None:
                b.robot.set_avoid_ball_radius(constants.Field.CenterRadius)
                b.robot.face(main.ball().pos)
Пример #16
0
    def __init__(self):
        super().__init__(continuous=True)

        # register states
        self.add_state(TrianglePass.State.setup,
                       behavior.Behavior.State.running)
        self.add_state(TrianglePass.State.passing,
                       behavior.Behavior.State.running)

        self.add_transition(behavior.Behavior.State.start,
                            TrianglePass.State.setup, lambda: True,
                            'immediately')

        self.add_transition(TrianglePass.State.setup,
                            TrianglePass.State.passing,
                            lambda: self.all_subbehaviors_completed(),
                            'all subbehaviors completed')

        self.triangle_points = [
            robocup.Point(0, constants.Field.Length / 2.0),
            robocup.Point(constants.Field.Width / 4,
                          constants.Field.Length / 4),
            robocup.Point(-constants.Field.Width / 4,
                          constants.Field.Length / 4),
        ]
Пример #17
0
    def __init__(self, side=Side.center):
        super().__init__(continuous=True)
        self._block_robot = None
        self._area = None
        self._side = side
        self._opponent_avoid_threshold = 2.0
        self._defend_goal_radius = 0.9
        self._win_eval = evaluation.window_evaluator.WindowEvaluator()

        self._area = robocup.Rect(
            robocup.Point(-constants.Field.Width / 2.0,
                          constants.Field.Length),
            robocup.Point(constants.Field.Width / 2.0, 0))
        if self._side is Defender.Side.right:
            self._area.get_pt(0).x = 0
        if self._side is Defender.Side.left:
            self._area.get_pt(1).x = 0

        self.add_state(Defender.State.marking, behavior.Behavior.State.running)
        self.add_state(Defender.State.area_marking,
                       behavior.Behavior.State.running)

        self.add_transition(behavior.Behavior.State.start,
                            Defender.State.marking, lambda: True,
                            "immediately")
        self.add_transition(
            Defender.State.marking, Defender.State.area_marking,
            lambda: not self._area.contains_point(main.ball().pos) and self.
            block_robot is None, "if ball not in area and no robot to block")
        self.add_transition(
            Defender.State.area_marking, Defender.State.marking,
            lambda: self._area.contains_point(main.ball(
            ).pos) or self.find_robot_to_block() is not None,
            "if ball or opponent enters my area")
Пример #18
0
def num_on_offense():
    # Complementary filter based on...
    #	Distance to their goal
    #	Distance to the ball
    goal_loc = robocup.Point(0, constants.Field.Length)
    corner_loc = robocup.Point(constants.Field.Width / 2, 0)
    ball_loc = main.ball().pos

    max_goal_dis = (goal_loc - corner_loc).mag()
    ball_to_goal = (goal_loc - ball_loc).mag()
    offense_ctr = 0

    filter_coeff = 0.7
    score_cutoff = .3

    # For each of their robots
    for bot in main.their_robots():
        if bot.visible:
            dist_to_ball = (bot.pos - ball_loc).mag()
            dist_to_goal = (bot.pos - goal_loc).mag()

            goal_coeff = dist_to_goal / max_goal_dis
            if ball_to_goal != 0:
                ball_coeff = 1 - (dist_to_ball / ball_to_goal)
            else:
                ball_coeff = 1
            ball_coeff = max(0, ball_coeff * ball_coeff)

            score = filter_coeff * goal_coeff + (1 - filter_coeff) * ball_coeff

            # Only count if their score is above the cutoff
            if (score > score_cutoff):
                offense_ctr += 1

    return offense_ctr
Пример #19
0
	def side(self, value):
		self._side = value
		self._area = robocup.Rect(robocup.Point(-constants.Field.Width/2.0, constants.Field.Length),
			robocup.Point(constants.Field.Width/2.0, 0))
		if self._side is Defender.Side.right:
			self._area.get_pt(0).x = 0
		if self._side is Defender.Side.left:
			self._area.get_pt(1).x = 0
Пример #20
0
    def test_our_goal_zone(self):
        # right in the center of the goal zone
        in_zone = robocup.Point(0, constants.Field.PenaltyDist / 2.0)

        out_zone = robocup.Point(0, constants.Field.Length / 2.0)

        self.assertTrue(
            constants.Field.OurGoalZoneShape.contains_point(in_zone))
Пример #21
0
 def generate_line(self, x_multiplier):
     x = (constants.Field.Width / 2 - constants.Robot.Radius *
          2) * x_multiplier
     y_start = 1.0
     line = robocup.Segment(
         robocup.Point(x, constants.Robot.Radius + y_start), robocup.Point(
             x, (constants.Robot.Radius * 2.3 + 0.1) * 6 + y_start))
     return line
Пример #22
0
class LineUp(composite_behavior.CompositeBehavior):

    y_start = 1.0  # sometimes we have issues if we're right in the corner, so we move it up a bit
    DefaultLine = robocup.Segment(
        robocup.Point(-constants.Field.Width / 2 + constants.Robot.Radius,
                      constants.Robot.Radius + y_start),
        robocup.Point(-constants.Field.Width / 2 + constants.Robot.Radius,
                      (constants.Robot.Radius * 2 + 0.1 + y_start) * 6))

    def __init__(self, line=None):
        super().__init__(continuous=False)

        self.line = line if line != None else LineUp.DefaultLine

        self.add_transition(behavior.Behavior.State.start,
                            behavior.Behavior.State.running, lambda: True,
                            'immediately')
        self.add_transition(behavior.Behavior.State.running,
                            behavior.Behavior.State.completed,
                            lambda: self.all_subbehaviors_completed(),
                            'all robots reach target positions')
        self.add_transition(behavior.Behavior.State.completed,
                            behavior.Behavior.State.running,
                            lambda: not self.all_subbehaviors_completed(),
                            'robots arent lined up')

    # override superclass implementation of all_subbehaviors_completed() to
    # count unassigned subbehaviors as "done running"
    def all_subbehaviors_completed(self):
        for bhvr in self.all_subbehaviors():
            if not bhvr.is_done_running() and (not isinstance(
                    bhvr, SingleRobotBehavior) or bhvr.robot != None):
                return False
        return True

    def execute_running(self):
        for i in range(6):
            pt = self._line.get_pt(0) + (self.diff * float(i))
            self.subbehavior_with_name("robot" + str(i)).pos = pt

    @property
    def line(self):
        return self._line

    @line.setter
    def line(self, value):
        self._line = value
        self.diff = (self._line.get_pt(1) - self._line.get_pt(0)
                     ).normalized() * (self._line.length() / 6.0)

        # add subbehaviors for all robots, instructing them to line up
        self.remove_all_subbehaviors()
        for i in range(6):
            pt = self._line.get_pt(0) + (self.diff * float(i))
            self.add_subbehavior(skills.move.Move(pt),
                                 name="robot" + str(i),
                                 required=False,
                                 priority=6 - i)
Пример #23
0
 def generate_line(self, y_multiplier):
     y = ((constants.Field.Length / 2 - constants.Field.GoalWidth -
           constants.Robot.Radius * 2) *
          y_multiplier) + (constants.Field.Length / 2)
     x_start = -0.8
     line = robocup.Segment(
         robocup.Point(constants.Robot.Radius + x_start, y),
         robocup.Point((constants.Robot.Radius * 2 + 0.1) * 6 + x_start, y))
     return line
Пример #24
0
    def execute_marking(self):
        move = self.subbehavior_with_name('move')
        move.pos = self.move_target

        arc = robocup.Circle(robocup.Point(0,0), self._defend_goal_radius)

        if move.pos != None:
            main.system_state().draw_circle(move.pos, 0.02, constants.Colors.Green, "Mark")
            main.system_state().draw_circle(robocup.Point(0,0), self._defend_goal_radius, constants.Colors.Green, "Mark")
Пример #25
0
    def execute_setup(self):
        penalty_mark = robocup.Point(0, constants.Field.Length - constants.Field.PenaltyDist)
        backoff = 0.5
        if main.ball().pos.near_point(penalty_mark, 0.5):
            self.robot.move_to(main.ball().pos + (main.ball().pos - robocup.Point(0, constants.Field.Length).normalized()) * backoff)
        else:
            self.robot.move_to(penalty_mark - robocup.Point(0, backoff))

        self.robot.face(main.ball().pos)
Пример #26
0
 def _self_goal(self, robot):
     penalty_seg = robocup.Segment(
         robocup.Point(0, -constants.Field.PenaltyLongDist / 2),
         robocup.Point(0, constants.Field.PenaltyLongDist / 2))
     robot_face_seg = robocup.Segment(
         robot.pos, robot.pos +
         robocup.Point.direction(robot.angle) * constants.Field.Length)
     self.robot.face(constants.Field.OurGoalSegment.center())
     return robot_face_seg.segment_intersection(penalty_seg)
Пример #27
0
def eval_single_point(kick_point, ignore_robots, min_pass_dist, field_weights,
                      weights, receive_x, receive_y):

    receive_point = robocup.Point(receive_x, receive_y)

    if kick_point is None:
        if main.ball().valid:
            kick_point = main.ball().pos
        else:
            return 0

    w = constants.Field.Width
    l = constants.Field.Length
    x_offset = .1 * w
    y_offset = .1 * l

    # Check boundaries
    # Can be smoothed for a better solution
    robot_offset = constants.Robot.Radius * 6
    if (receive_point.x - x_offset < w / -2
            or receive_point.x + x_offset > w / 2
            or receive_point.y - y_offset < 0
            or receive_point.y + y_offset > constants.Field.Length
            or constants.Field.TheirGoalZoneShape.contains_point(
                receive_point + robocup.Point(0, y_offset) +
                robocup.Point(robot_offset, robot_offset))
            or constants.Field.TheirGoalZoneShape.contains_point(
                receive_point + robocup.Point(0, y_offset) -
                robocup.Point(robot_offset, robot_offset))):
        return 0

    # Check if we are too close to the ball
    if ((receive_point - kick_point).mag() < min_pass_dist):
        return 0

    shotChance = evaluation.shooting.eval_shot(receive_point, ignore_robots)

    passChance = evaluation.passing.eval_pass(kick_point, receive_point,
                                              ignore_robots)

    space = evaluation.field.space_coeff_at_pos(receive_point, ignore_robots)
    fieldPos = evaluation.field.field_pos_coeff_at_pos(receive_point,
                                                       field_weights[0],
                                                       field_weights[1],
                                                       field_weights[2])
    distance = math.exp(-1 * (kick_point - receive_point).mag())

    # All of the other scores are based on whether the pass will actually make it to it
    # Not worth returning a great position if we cant even get a pass there
    totalChance = passChance * (weights[0] *
                                (1 - space) + weights[1] * fieldPos +
                                weights[2] * shotChance + weights[3] *
                                (1 - distance))

    return totalChance / math.fsum(weights)
Пример #28
0
    def __init__(self, indirect=None):
        super().__init__(continuous=True)

        # If we are indirect we don't want to shoot directly into the goal
        gs = main.game_state()

        if indirect is not None:
            self.indirect = indirect
        elif main.ball().pos.y > constants.Field.Length / 2.0:
            self.indirect = gs.is_indirect()
        else:
            self.indirect = False

        self.add_transition(behavior.Behavior.State.start,
                            behavior.Behavior.State.running, lambda: True,
                            'immediately')

        # FIXME: this could also be a PivotKick
        kicker = skills.line_kick.LineKick()
        # kicker.use_chipper = True
        kicker.min_chip_range = 0.3
        kicker.max_chip_range = 3.0
        # This will be reset to something else if indirect on the first iteration
        kicker.target = constants.Field.TheirGoalSegment

        # add two 'centers' that just move to fixed points
        center1 = skills.move.Move(robocup.Point(0, 1.5))
        self.add_subbehavior(center1, 'center1', required=False, priority=4)
        center2 = skills.move.Move(robocup.Point(0, 1.5))
        self.add_subbehavior(center2, 'center2', required=False, priority=3)

        if self.indirect:
            receive_pt, target_point, probability = evaluation.touchpass_positioning.eval_best_receive_point(
                main.ball().pos)
            pass_behavior = tactics.coordinated_pass.CoordinatedPass(
                receive_pt,
                None,
                (kicker, lambda x: True),
                receiver_required=False,
                kicker_required=False,
                prekick_timeout=9)
            # We don't need to manage this anymore
            self.add_subbehavior(pass_behavior, 'kicker')

            kicker.target = receive_pt
        else:
            kicker = skills.line_kick.LineKick()
            kicker.target = constants.Field.TheirGoalSegment
            self.add_subbehavior(kicker, 'kicker', required=False, priority=5)

        self.add_transition(
            behavior.Behavior.State.running, behavior.Behavior.State.completed,
            lambda: self.subbehavior_with_name('kicker').is_done_running() and self.subbehavior_with_name('kicker').state != tactics.coordinated_pass.CoordinatedPass.State.timeout,
            'kicker completes')
Пример #29
0
    def __init__(self):
        super().__init__(continuous=True)

        self.angle = 0
        point = robocup.Point(0, constants.Field.Length / 4.0)
        self.face_target = point + robocup.Point(math.cos(self.angle),
                                                 math.sin(self.angle))

        self.add_transition(behavior.Behavior.State.start,
                            behavior.Behavior.State.running, lambda: True,
                            'immediately')
Пример #30
0
    def __init__(self):
        super().__init__(continuous=True)

        self.add_transition(behavior.Behavior.State.start,
                            behavior.Behavior.State.running, lambda: True,
                            'immediately')

        # lineup
        line = robocup.Segment(robocup.Point(1.5, 1.3),
                               robocup.Point(1.5, 2.5))
        lineup = tactics.line_up.LineUp(line)
        self.add_subbehavior(lineup, 'lineup')