def add_shot_obstacle(self, excluded_robots=[]): pt = self.aim_target_point if pt != None: # segment centered at the target point that's @width wide and perpendicular to the shot shot_perp = (main.ball().pos - pt).perp_ccw().normalized() # Make the shot triangle obstacle a fixed width at the end unless # we're aiming at a segment. In that case, just use the length of # the segment. width = 0.5 if isinstance(self.target, robocup.Segment): width = self.target.length() a = pt + shot_perp * width / 2.0 b = pt - shot_perp * width / 2.0 # build the obstacle polygon obs = robocup.Polygon() obs.add_vertex(main.ball().pos) obs.add_vertex(a) obs.add_vertex(b) # tell the bots to not go there for bot in main.our_robots(): if bot not in excluded_robots + [self.robot]: bot.add_local_obstacle(obs)
def add_shot_obstacle(self, excluded_robots=[]): pt = self.aim_target_point if pt != None: # segment centered at the target point that's @width wide and perpendicular to the shot shot_perp = (main.ball().pos - pt).perp_ccw().normalized() width = 0.2 a = pt + shot_perp * width / 2.0 b = pt - shot_perp * width / 2.0 # build the obstacle polygon obs = robocup.Polygon() obs.add_vertex(main.ball().pos) obs.add_vertex(a) obs.add_vertex(b) # tell the bots to not go there for bot in main.our_robots(): if bot not in excluded_robots + [self.robot]: bot.add_local_obstacle(obs)
def check_failure(self): # We wait about 3 frames before freezing the velocity and position of the ball # as it can be unreliable right after kicking. See execute_receiving. if self.stable_frame < PassReceive.StabilizationFrames: return False offset = 0.1 straight_line = robocup.Point(0, 1) pass_segment = self.robot.pos - self.kicked_from pass_distance = pass_segment.mag() + 0.5 pass_dir = pass_segment.normalized() left_kick = robocup.Point(-offset, -offset) right_kick = robocup.Point(offset, -offset) # Create a channel on the left/right of the mouth of the kicker to a bit behind the receiver left_recieve = left_kick + straight_line * pass_distance right_recieve = right_kick + straight_line * pass_distance # Widen the channel to allow for catching the ball. left_recieve.rotate(left_kick, PassReceive.MarginAngle) right_recieve.rotate(right_kick, -PassReceive.MarginAngle) origin = robocup.Point(0, 0) passDirRadians = pass_dir.angle() left_kick.rotate(origin, passDirRadians - math.pi / 2) right_kick.rotate(origin, passDirRadians - math.pi / 2) left_recieve.rotate(origin, passDirRadians - math.pi / 2) right_recieve.rotate(origin, passDirRadians - math.pi / 2) # Add points that create the good_area to a polygon good_area = robocup.Polygon() good_area.add_vertex(self.kicked_from + left_kick) good_area.add_vertex(self.kicked_from + right_kick) good_area.add_vertex(self.kicked_from + right_recieve) good_area.add_vertex(self.kicked_from + left_recieve) main.debug_drawer().draw_raw_polygon(good_area, constants.Colors.Green, "Good Pass Area") return not good_area.contains_point(main.ball().pos)