示例#1
0
def pRightWing(team, workingPlay):
    """position right winger"""
    workingPlay.setSubRole(PBConstants.RIGHT_WING)
    midpoint = (PBConstants.WING_MAX_X - PBConstants.WING_MIN_X)*.5
    scale = (PBConstants.WING_MAX_X - midpoint)/(PBConstants.PICKER_X_THRESH -
                                                 midpoint)
    x = -1*scale*(team.brain.ball.loc.x - midpoint)
    y = PBConstants.RIGHT_WING_Y
    dest = Location(x, y)
    h = dest.headingTo(team.brain.ball.loc)

    pos = (x, y, h)
    workingPlay.setPosition(pos)
示例#2
0
def pStriker(team, workingPlay):
    """position striker"""
    workingPlay.setSubRole(PBConstants.STRIKER)
    x = PBConstants.STRIKER_X
    if team.brain.ball.loc.y < NogginConstants.CENTER_FIELD_Y:
        y = PBConstants.LEFT_STRIKER_Y
    else:
        y = PBConstants.RIGHT_STRIKER_Y
    dest = Location(x, y)
    h = dest.headingTo(team.brain.ball.loc)

    pos = (x, y, h)
    workingPlay.setPosition(pos)
示例#3
0
def passToFieldCross(player):
    if player.firstFrame():
        player.passBack = False
        if roleConstants.isFirstChaser(player.role):
            player.brain.tracker.repeatFastNarrowPan()
            fieldCross = Location(nogginC.LANDMARK_OPP_FIELD_CROSS[0],
                                  nogginC.LANDMARK_OPP_FIELD_CROSS[1])
            player.brain.nav.goTo(fieldCross, Navigator.GENERAL_AREA,
                                  Navigator.QUICK_SPEED, True, False, True,
                                  False)

        elif roleConstants.isSecondChaser(
                player.role) or roleConstants.isCherryPicker(player.role):
            if not constants.ballIsLost(player):
                decider = KickDecider.KickDecider(player.brain)
                # player.kick = decider.bigKicksOnGoal()
                # player.kick = decider.sweetMovesOnGoal()
                # player.kick = decider.sweetMoveCrossToCenter()
                player.kick = decider.decidingStrategy()
                player.finishedPlay = True
                player.inKickingState = True
                return player.goNow('approachBall')
            else:
                player.inKickOffPlay = False
                return player.goNow('findBall')
        else:
            return player.goNow('playOffBall')

        return player.stay()

    if roleConstants.isFirstChaser(player.role):
        fieldCross = Location(nogginC.LANDMARK_OPP_FIELD_CROSS[0],
                              nogginC.LANDMARK_OPP_FIELD_CROSS[1])
        player.brain.nav.updateDest(fieldCross)
        if constants.shouldStopWalkingToCross(player):
            player.inKickOffPlay = False
            return player.goNow('approachBall')

    return player.stay()
示例#4
0
def spinSearch(player):
    """
    spins and looks to the direction where the ball is thought to be
    """

    if player.firstFrame():
        my = player.brain.loc
        ball = Location(player.brain.ball.x, player.brain.ball.y)
        spinDir = my.spinDirToPoint(ball)
        player.setWalk(0, 0, spinDir * speeds.SPEED_SIX)
        player.brain.tracker.repeatFixedPitchLookAhead()

    if player.stateTime >= constants.SPEED_SIX_SPUN_ONCE_TIME / 2:
        return player.goNow("fastPan")
示例#5
0
def spinForwardSearch(player):

    if player.firstFrame():
        my = player.brain.loc
        ball = Location(player.brain.ball.x, player.brain.ball.y)
        spinDir = my.spinDirToPoint(ball)
        X = constants.FRONT_SPIN_SEARCH_SPEED_X
        Y = constants.FRONT_SPIN_SEARCH_SPEED_Y
        H = constants.FRONT_SPIN_SEARCH_SPEED_H
        player.setWalk(X, Y * spinDir, H * spinDir)
        player.brain.tracker.lookToAngle(spinDir *
                                         constants.FRONT_SPIN_LOOK_TO_ANGLE)
    if transitions.spunOnce(player):
        return player.goLater('playOffBall')
示例#6
0
    def notTowardOurGoal(self, kick):
        # do not kick into our goalbox
        ball = self.brain.ball

        inBox = (ball.x > nogginC.GREEN_PAD_X
                 and ball.x < nogginC.BLUE_GOALBOX_RIGHT_X
                 and ball.y < nogginC.BLUE_GOALBOX_TOP_Y
                 and ball.y > nogginC.BLUE_GOALBOX_BOTTOM_Y)
        intoBox = (kick.destinationX > nogginC.GREEN_PAD_X
                   and kick.destinationX < nogginC.BLUE_GOALBOX_RIGHT_X
                   and kick.destinationY < nogginC.BLUE_GOALBOX_TOP_Y
                   and kick.destinationY > nogginC.BLUE_GOALBOX_BOTTOM_Y)

        if intoBox and not inBox:
            return False

        else:
            goalCenter = Location(nogginC.FIELD_WHITE_LEFT_SIDELINE_X,
                                  nogginC.MIDFIELD_Y)
            ball = Location(ball.x, ball.y)
            kickDestination = Location(kick.destinationX, kick.destinationY)

            return goalCenter.distTo(ball) < goalCenter.distTo(kickDestination)
示例#7
0
 def genLocations(self, filePath):
     print("\t" + "[GEN LOCATIONS]")
     locationConfig = open("config/locations.txt", "r")
     locLine = locationConfig.readline().rstrip('\n')
     id = 0
     while locLine:
         self.locations.append(Location.Location(id, locLine, random.randint(0,len(self.expansions)-1)))
         id = id + 1
         locLine = locationConfig.readline().rstrip('\n')
     if os.path.exists(filePath):
         os.remove(filePath)
     for i in range(0, len(self.locations)):
         self.sqlmaker.insertify("Locations", self.locations[i].getAttributes(), filePath)
     locationConfig.close();
示例#8
0
def pKickoffStriker(team, workingPlay):
    """position kickoff striker"""
    workingPlay.setSubRole(PBConstants.KICKOFF_STRIKER)
    x = PBConstants.KICKOFF_OFFENDER_X

    if team.kickoffFormation == 0:
        y = PBConstants.KICKOFF_OFFENDER_0_Y
    else:
        y = PBConstants.KICKOFF_OFFENDER_1_Y

    # We want to face the center (where the ball is, from our location)
    dest = Location(x,y)
    h = dest.headingTo(PBConstants.CENTER_FIELD)

    pos = (x,y,h)
    workingPlay.setPosition(pos)
示例#9
0
def pCenterBack(team, workingPlay):
    """position center back"""
    workingPlay.setSubRole(PBConstants.CENTER_BACK)
    x,y = team.getPointBetweenBallAndGoal(team.brain.ball,
                                          PBConstants.DEFENDER_BALL_DIST)
    x = MyMath.clip(x,
                    PBConstants.SWEEPER_X,
                    PBConstants.STOPPER_X)
    y = MyMath.clip(y,
                    PBConstants.MIN_CENTER_BACK_Y,
                    PBConstants.MAX_CENTER_BACK_Y)
    dest = Location(x, y)
    h = dest.headingTo(team.brain.ball.loc)

    pos = (x, y, h)
    workingPlay.setPosition(pos)
示例#10
0
def findStrikerHome(ball, hh):
    if not hasattr(findStrikerHome, 'upperHalf'):
        findStrikerHome.upperHalf = (ball.y -
                                     NogginConstants.CENTER_FIELD_Y) >= 0

    # the buffer zone is twice this because its this distance on each side of midfield
    # the buffer keeps us from oscillating sides of the field when the ball is near the center line
    oscBuff = 50
    if findStrikerHome.upperHalf and (
            ball.y - NogginConstants.CENTER_FIELD_Y) < -1 * oscBuff:
        findStrikerHome.upperHalf = False
    elif not findStrikerHome.upperHalf and (
            ball.y - NogginConstants.CENTER_FIELD_Y) > oscBuff:
        findStrikerHome.upperHalf = True

    goalCenter = Location(NogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X,
                          NogginConstants.MIDFIELD_Y)
    ballToGoal = Location(goalCenter.x - ball.x,
                          goalCenter.y - ball.y)  # vector

    # avoid divide by zeros
    if ballToGoal == Location(0, 0):
        ballToGoal = Location(1, 0)

    # the point at which we draw our normal vector from
    percentageToPivot = 0.8
    pivotPoint = Location(ball.x + ballToGoal.x * 0.8,
                          ball.y + ballToGoal.y * 0.8)

    # two possible normal vectors. If ball.y is greater than midfield.y choose (dy, -dx)
    # else choose (-dy, dx)
    if findStrikerHome.upperHalf:
        normalVect = Location(ballToGoal.y, -1 * ballToGoal.x)
    else:
        normalVect = Location(-1 * ballToGoal.y, ballToGoal.x)

    # normalize the vector and make its magnitude to the desired value
    normalVectLength = 100
    normalizeMag = normalVectLength / normalVect.distTo(Location(0, 0))
    normalVect.x *= normalizeMag
    normalVect.y *= normalizeMag

    return RobotLocation(pivotPoint.x + normalVect.x,
                         pivotPoint.y + normalVect.y, hh)
示例#11
0
def pReadyChaser(team, workingPlay):
    workingPlay.setSubRole(PBConstants.READY_CHASER)
    kickOff = team.brain.gameController.ownKickOff
    if kickOff:
        x = PBConstants.READY_KICKOFF_CHASER_X
        y = PBConstants.READY_KICKOFF_CHASER_Y
    else:
        x = PBConstants.READY_NON_KICKOFF_CHASER_X
        if team.kickoffFormation == 0:
            y = PBConstants.READY_NON_KICKOFF_CHASER_0_Y
        else:
            y = PBConstants.READY_NON_KICKOFF_CHASER_1_Y

    dest = Location(x, y)
    h = dest.headingTo(PBConstants.CENTER_FIELD)

    pos = (x,y,h)
    workingPlay.setPosition(pos)
示例#12
0
def spinToBall(player):
    if player.firstFrame():
        player.brain.tracker.trackBall()
        player.brain.nav.stand()

    if transitions.shouldFindBall(player):
        return player.goLater('chase')

    if transitions.shouldStopSpinningToBall(player):
        return player.goNow('approachBall')
    else:
        spinDir = player.brain.loc.spinDirToPoint(
            Location(player.brain.ball.x, player.brain.ball.y))
        if fabs(player.brain.ball.bearing_deg) > constants.CHANGE_SPEED_THRESH:
            speed = Navigator.GRADUAL_SPEED
        else:
            speed = Navigator.SLOW_SPEED
        player.setWalk(0, 0, spinDir * speed)
        return player.stay()
示例#13
0
def afterKick(player):
    """
    State to follow up after a kick.
    """
    if player.firstFrame():
        # player.stand()        # stand up right, ready to walk
        player.brain.tracker.afterKickScan(player.kick.name)
        return player.stay()

    if player.penaltyKicking:
        return player.stay()

    elif player.passBack:
        return player.goNow('passToFieldCross')

    elif transitions.shouldKickAgain(player):
        player.kick = kicks.chooseAlignedKickFromKick(player, player.kick)
        if player.motionKick:
            player.motionKick = False
            return player.goNow('spinToBall')
        else:
            return player.goNow('positionForKick')

    elif player.kickedOut:
        player.kickedOut = False
        return player.goNow('spinSearch')

    elif transitions.shouldChaseBall(player):
        return player.goLater('approachBall')
    elif player.stateTime > 2:
        destinationOfKick = Location(player.kick.destinationX,
                                     player.kick.destinationY)
        player.brain.nav.goTo(destinationOfKick,
                              precision=nav.GENERAL_AREA,
                              speed=nav.QUICK_SPEED,
                              avoidObstacles=True,
                              fast=True,
                              pb=False)

    if player.stateTime > 4:
        return player.goLater('approachBall')

    return player.stay()
示例#14
0
def dribble(player):
    if transitions.shouldNotDribble(player):
        if player.lastDiffState == 'orbitBall':
            return player.goNow('approachBall')
        return player.goNow('orbitBall')
    ball = player.brain.ball
    relH = player.decider.normalizeAngle(player.brain.loc.h)
    if ball.distance < constants.LINE_UP_X and not (
            relH > -constants.ORBIT_GOOD_BEARING
            and relH < constants.ORBIT_GOOD_BEARING):
        player.setWalk(0, 0, 0)
        return player.goLater('orbitBall')

    if player.brain.ball.vis == True:
        if transitions.inGoalBox(player):
            player.brain.nav.walk(0.8, 0, 0)
        else:
            player.brain.nav.goTo(Location(ball.x, ball.y),
                                  Navigator.GENERAL_AREA, speeds.SPEED_SIX)
    else:
        player.brain.nav.walk(0.6, 0, 0)
    return player.stay()
示例#15
0
    def determineChaseTime(self):
        """
        Attempt to define a time in seconds to get to the ball.
        Can give penalties in certain situations.
        @ return: returns a time in seconds with penalties.
        Note: Don't give bonuses. It can result in negative chase times
              which can screw up the math later on. --Wils (06/25/11)
        """
        ballLocation = Location(self.brain.ball.x, self.brain.ball.y)
        headingBallToGoal = ballLocation.headingTo(OPP_GOAL)

        relLocToBall = RelRobotLocation(self.brain.ball.rel_x,
                                        self.brain.ball.rel_y,
                                        headingBallToGoal)

        time = self.determineTimeToDest(relLocToBall)

        # Give a penalty for not seeing the ball if we aren't in a kickingState
        if (self.brain.ball.vis.frames_off > 45
                and  # TODO: unify this constant with shouldFindBall
                not self.brain.player.inKickingState):
            time += BALL_OFF_PENALTY

        if DEBUG_DETERMINE_DEST_TIME:
            print "\tChase time after ball on bonus " + str(time)

        # HACK RoboCup 2013
        if PBConstants.HACK_D1 or PBConstants.HACK_D2:
            if self.brain.ball.x > PBConstants.DEFENDER_BOX_LIMIT_X:
                time += 15000

        if PBConstants.HACK_O:
            if self.brain.ball.distance > PBConstants.OFFENDER_DISTANCE_LIMIT:
                time += 15000

        return time
示例#16
0
from objects import (RobotLocation, Location, RelRobotLocation)
from math import fabs, degrees
import noggin_constants as NogginConstants
from ..playbook import PBConstants

OPP_GOAL = Location(NogginConstants.OPP_GOALBOX_RIGHT_X,
                    NogginConstants.OPP_GOALBOX_MIDDLE_Y)
OPP_GOAL_LEFT_POST = Location(NogginConstants.LANDMARK_OPP_GOAL_LEFT_POST_X,
                              NogginConstants.LANDMARK_OPP_GOAL_LEFT_POST_Y)
OPP_GOAL_RIGHT_POST = Location(NogginConstants.LANDMARK_OPP_GOAL_RIGHT_POST_X,
                               NogginConstants.LANDMARK_OPP_GOAL_RIGHT_POST_Y)

DEFAULT_GOALIE_NUMBER = 1
DEFAULT_DEFENDER_NUMBER = 2
DEFAULT_MIDDIE_NUMBER = 3
DEFAULT_OFFENDER_NUMBER = 4
DEFAULT_CHASER_NUMBER = 5
DEBUG_DETERMINE_DEST_TIME = False
SEC_TO_MILLIS = 1000.0
WALK_SPEED = 20.00  #cm/sec          # How fast we walk
CHASE_TIME_SCALE = 0.45  # How much new measurement is used in IIR.
BALL_OFF_PENALTY = 100.  # Big penalty for not seeing the ball.

# Behavior constants
BALL_TEAMMATE_DIST_GRABBING = 35
BALL_TEAMMATE_BEARING_GRABBING = 45.
BALL_TEAMMATE_DIST_DRIBBLING = 20

# Ball on?
BALL_FRAMES = 20
示例#17
0
                          fast = True, pb = False)

    if shared.navAtPosition(player) and player.brain.loc.distTo(playerFourSearchBehavior.dest) < 60:
        if playerFourSearchBehavior.pointIndex % len(playerFourPoints) == 0:
            adjustHeading.desiredHeading = 180
            return player.goNow("adjustHeading")
        elif playerFourSearchBehavior.pointIndex % len(playerFourPoints) == 1:
            adjustHeading.desiredHeading = -90
            return player.goNow("adjustHeading")
        else:
            adjustHeading.desiredHeading = 90
            return player.goNow("adjustHeading")

    player.brain.nav.updateDest(playerFourSearchBehavior.dest)

playerFourWayPoint1 = Location(NogginConstants.CENTER_FIELD_X - 160, NogginConstants.CENTER_FIELD_Y - 40)
playerFourWayPoint2 = Location(NogginConstants.CENTER_FIELD_X + 170, NogginConstants.MY_GOALBOX_TOP_Y + 110)
playerFourWayPoint3 = Location(NogginConstants.CENTER_FIELD_X + 70, NogginConstants.MY_GOALBOX_BOTTOM_Y - 110)
playerFourPoints = [playerFourWayPoint1, playerFourWayPoint2, playerFourWayPoint3]
playerFourSearchBehavior.pointIndex = -1
playerFourSearchBehavior.pointsWalked = 0
playerFourSearchBehavior.dest = playerFourWayPoint1

@superState('playOffBall')
@stay
def playerFiveSearchBehavior(player):

    if player.firstFrame():
        player.brain.tracker.trackBall()
        if playerFiveSearchBehavior.pointIndex == -1:
示例#18
0
 def getBearingToGoal(self):
     """returns bearing to goal"""
     opp_goal = Location(NogginConstants.OPP_GOALBOX_RIGHT_X,
                         NogginConstants.OPP_GOALBOX_MIDDLE_Y)
     return self.getRelativeBearing(opp_goal)
示例#19
0
    def addPassesToFieldCross(self):
        betweenFieldCrossAndGoalBoxLeft = (nogginC.LANDMARK_OPP_FIELD_CROSS[0] +
                                           nogginC.OPP_GOALBOX_LEFT_X) / 2.
        location = Location(betweenFieldCrossAndGoalBoxLeft,nogginC.CENTER_FIELD_Y)

        self.addPassesTo(location)
示例#20
0
    def forwardProgress(self, kick):
        goalCenter = Location(nogginC.FIELD_WHITE_RIGHT_SIDELINE_X, nogginC.MIDFIELD_Y)
        ball = Location(self.brain.ball.x, self.brain.ball.y)
        kickDestination = Location(kick.destinationX, kick.destinationY)

        return goalCenter.distTo(ball) > goalCenter.distTo(kickDestination)
示例#21
0
 def gen_random_location(self):
     loc = Location.Location(random.randint(0, self.width), random.randint(0, self.height))
     return loc
示例#22
0
文件: Play.py 项目: suthumb/nbites
 def getPositionCoord(self):
     return Location(self.position.x, self.position.y)
示例#23
0
def afterKick(player):
    """
    State to follow up after a kick.
    """
    if player.firstFrame():
        # player.stand()        # stand up right, ready to walk
        afterKick.numTimes += 1
        player.brain.tracker.afterKickScan(player.kick.name)
        return player.stay()

    if not player.brain.motion.calibrated:
        # Wait until sensors are calibrated before moving
        return player.stay()

    print "afterKick.numTimes = " + str(afterKick.numTimes)

    if afterKick.numTimes >= 5:
        afterKick.numTimes = 0
        print "Too many afterkick numtimes, going into spinsearch"
        return player.goNow('spinSearch')    

    if player.penaltyKicking:
        return player.stay()

    elif player.passBack:
        return player.goNow('passToFieldCross')

    elif transitions.shouldKickAgain(player):
        destinationOfKick = Location(player.kick.destinationX,
                                     player.kick.destinationY)
        if player.kick.destinationX == 0 and player.kick.destinationY == 0:
            afterKick.numTimes = 0
            print "transitions.shouldkickagain, going into spinsearch"
            player.goNow('spinSearch')

        if not player.brain.ball.vis.frames_on > 5:
            player.brain.nav.goTo(destinationOfKick, precision = nav.PLAYBOOK,
                          speed = speeds.SPEED_SIX, avoidObstacles = True,
                          fast = True, pb = False)

        player.kick = kicks.chooseAlignedKickFromKick(player, player.kick)
        # if player.motionKick:
        #     player.motionKick = False
        #     return player.goNow('spinToBall')
        # else:
        
        afterKick.numTimes = 0
        return player.goNow('positionForKick')

    elif player.kickedOut:
        player.kickedOut = False
        afterKick.numTimes = 0
        return player.goNow('spinSearch')

    # James little wth is this ????????? jeezus
    if player.counter < 300:
        print "going to chaseAfterBall"
        # afterKick.numTimes = 0
        return player.goNow('chaseAfterBall')



    # while not transitions.shouldChaseBall(player) and player.counter < 300:
    #     print "Walking forward"
    #     player.brain.nav.destinationWalkTo(RelRobotLocation(10, 0, 0))
        # print "Standing"
        # player.brain.nav.stand()
        # print "Performing head move"
        # player.brain.tracker.performHeadMove(kicks.FAST_TWO_INTERVAL)
    # elif transitions.shouldChaseBall(player):
    #     return player.goLater('approachBall')
    # elif player.stateTime > 2:
    # destinationOfKick = Location(player.kick.destinationX,
    #                              player.kick.destinationY)
    # # print "Let's go to the kick destination: " + str(destinationOfKick)
    # player.brain.nav.goTo(destinationOfKick, precision = nav.GENERAL_AREA,
    #                       speed = speeds.SPEED_EIGHT, avoidObstacles = True,
    #                       fast = True, pb = False)

    if player.stateTime > 12: # https://www.youtube.com/watch?v=YMufkQo5pvA
        # print "goLater: approachBall -- from afterKick"
        return player.goLater('approachBall')

    return player.stay()
示例#24
0
def pChaser(team, workingPlay):
    """ never called. now handled entirely in player behavior """
    workingPlay.setSubRole(PBConstants.CHASE_NORMAL)
    ball = Location(team.brain.ball.x, team.brain.ball.y)
    pos = (ball.x, ball.y, team.brain.loc.headingTo(ball))
    workingPlay.setPosition(pos)
示例#25
0
                              precision=nav.GRAINY,
                              speed=nav.QUICK_SPEED,
                              avoidObstacles=True,
                              fast=True,
                              pb=False)
        searchFieldByQuad.quadIndex = points.index(searchFieldByQuad.dest)
        searchFieldByQuad.quadsWalked = 0

    if shared.navAtPosition(player) and player.brain.loc.distTo(
            searchFieldByQuad.dest) < 60:
        searchFieldByQuad.quadIndex += 1
        searchFieldByQuad.quadsWalked += 1
        searchFieldByQuad.dest = points[searchFieldByQuad.quadIndex %
                                        len(points)]

    if searchFieldByQuad.quadsWalked > 3:
        return player.goLater('playOffBall')

    player.brain.nav.updateDest(searchFieldByQuad.dest)


quad1Center = Location(NogginConstants.CENTER_FIELD_X * .6,
                       NogginConstants.CENTER_FIELD_Y * .6)
quad2Center = Location(NogginConstants.CENTER_FIELD_X * 1.4,
                       NogginConstants.CENTER_FIELD_Y * 1.4)
quad3Center = Location(NogginConstants.CENTER_FIELD_X * 1.4,
                       NogginConstants.CENTER_FIELD_Y * .6)
quad4Center = Location(NogginConstants.CENTER_FIELD_X * .6,
                       NogginConstants.CENTER_FIELD_Y * 1.4)
points = [quad1Center, quad2Center, quad3Center, quad4Center]
示例#26
0
# |  |             O |
# 0  |             __|
# |  |            /  |
# |G |      +    |  C+
# |  |            \__|
# 0  |  D            |
# |__|               |
# |__________________|
#
# Above is our ready position_0 when kicking-off. Can mirror for position_1
# Chaser: In optimal position to kick.
# Offender: On the wing ready to recieve a pass if chaser is crowded.
# Defender: Back in case something goes wrong. Also can potentially block opposing players' view of goalpost
# Goalie: At home.

CENTER_FIELD = Location(NogginConstants.CENTER_FIELD_X,
                        NogginConstants.CENTER_FIELD_Y)
"""DEFENDER"""
READY_KICKOFF_DEFENDER_X = (
    (NogginConstants.CENTER_FIELD_X - NogginConstants.GREEN_PAD_X) * 0.3 + 15 +
    NogginConstants.GREEN_PAD_X)
READY_KICKOFF_DEFENDER_0_Y = NogginConstants.LANDMARK_MY_GOAL_RIGHT_POST_Y
READY_KICKOFF_DEFENDER_1_Y = NogginConstants.LANDMARK_MY_GOAL_LEFT_POST_Y
"""OFFENDER"""
READY_KICKOFF_OFFENDER_X = (NogginConstants.CENTER_FIELD_X -
                            NogginConstants.CENTER_CIRCLE_RADIUS * 0.5)
READY_KICKOFF_OFFENDER_OFFSET = 165.  # Can be as large as you want as long as robot can side-kick that distance
READY_KICKOFF_OFFENDER_0_Y = (NogginConstants.CENTER_FIELD_Y +
                              READY_KICKOFF_OFFENDER_OFFSET)
READY_KICKOFF_OFFENDER_1_Y = (NogginConstants.CENTER_FIELD_Y -
                              READY_KICKOFF_OFFENDER_OFFSET)
"""CHASER"""
示例#27
0
    def flipLocFilter(self):
        """
        Check where the goalie sees the ball and where we do.
        Record if we're generally correct, or if our flipped location
        is generally correct, or if neither one agrees with the goalie.
        NOTE: ignore whenever the ball is in the middle 2x2 meter box.
        """
        # Get goalie data
        for mate in self.teamMembers:
            if mate.isDefaultGoalie() and mate.active:
                if mate.ballOn and self.ball.vis.on:
                    # calculate global ball coordinates
                    # note: assume goalie is in center of goal.
                    goalie_x = Constants.FIELD_WHITE_LEFT_SIDELINE_X
                    goalie_y = Constants.MIDFIELD_Y

                    ball_x = goalie_x + (mate.ballDist *
                                         math.cos(mate.ballBearing))
                    ball_y = goalie_y + (mate.ballDist *
                                         math.sin(mate.ballBearing))
                    goalie_ball_location = Location(ball_x, ball_y)

                    # check against my data
                    my_ball_location = Location(self.ball.x, self.ball.y)
                    flipped_ball_location = Location(
                        Constants.FIELD_GREEN_WIDTH - self.ball.x,
                        Constants.FIELD_GREEN_HEIGHT - self.ball.y)

                    if (mate.ballDist < 250
                            and self.loc.x > Constants.MIDFIELD_X
                            and self.ball.x > Constants.MIDFIELD_X):
                        # I'm probably flipped!
                        self.updateFlipFilters(-1)

                        print "Goalie saw the ball close, and I think I and it are far."
                        print "Goalie sees ball at: " + str(
                            goalie_ball_location)

                        break

                    if (goalie_ball_location.inCenterCenter()
                            or my_ball_location.inCenterCenter()):
                        # Ball is too close to the middle of the field. Risky.
                        self.updateFlipFilters(0)
                        break

                    if my_ball_location.distTo(goalie_ball_location) < 70:
                        # I'm probably in the right place!
                        self.updateFlipFilters(1)
                    elif flipped_ball_location.distTo(
                            goalie_ball_location) < 70:
                        # I'm probably flipped!
                        self.updateFlipFilters(-1)
                    else:
                        # I don't agree with the goalie. Ignore.
                        self.updateFlipFilters(0)

        # If I've decided I should flip enough times, actually do it.
        if (len(self.flipFilter) == 10 and sum(self.flipFilter) > 6):
            self.flipLoc()
            # Reset filters! Don't want to flip again next frame.
            self.noFlipFilter = []
            self.flipFilter = []
示例#28
0
DEFAULT_KICK_X_OFFSET = 13

#HACK HACK HACK for HackKickInformation
KICK_STRAIGHT_POST_BEARING = 17
KICK_STRAIGHT_BEARING_THRESH = 70
KICK_SIDE_DIST_THRESH = .75 * NogginConstants.GOAL_WIDTH

# TODO make these accurate. TODO make ranges specific to kicks
SHORT_RANGE_KICK_DIST = 120
LONG_RANGE_KICK_DIST = 230

SHOOT_FRACTION = 0.145  # how far in along goal width should we shoot?
SHOOT_Y_OFFSET = NogginConstants.GOAL_WIDTH * SHOOT_FRACTION
SIDELINE_KICKOFF_OFFSET = 80.

LEFT_CLEAR_POINT = Location(NogginConstants.OPP_GOALBOX_LEFT_X,
                            NogginConstants.OPP_GOALBOX_TOP_Y)

RIGHT_CLEAR_POINT = Location(NogginConstants.OPP_GOALBOX_LEFT_X,
                             NogginConstants.OPP_GOALBOX_BOTTOM_Y)

SHOOT_LEFT_AIM_POINT = Location(
    NogginConstants.LANDMARK_OPP_GOAL_LEFT_POST_X,
    NogginConstants.LANDMARK_OPP_GOAL_LEFT_POST_Y - SHOOT_Y_OFFSET)

SHOOT_RIGHT_AIM_POINT = Location(
    NogginConstants.LANDMARK_OPP_GOAL_LEFT_POST_X,
    NogginConstants.LANDMARK_OPP_GOAL_RIGHT_POST_Y + SHOOT_Y_OFFSET)

SHOOT_CENTER_AIM_POINT = Location(
    NogginConstants.LANDMARK_OPP_GOAL_LEFT_POST_X,
    NogginConstants.CENTER_FIELD_Y)