Exemple #1
0
def DecideNextAction():
    global frameSinceLastGrabKick
    if sGrab.isGrabbed:
        if perform() != Constant.STATE_EXECUTING:
            sGrab.resetPerform()
            frameSinceLastGrabKick = Global.frame
            resetPerform()
    elif Global.frame - frameSinceLastGrabKick > 60:
        sGrab.perform()
    else:
        sFindBall.perform()
Exemple #2
0
def DecideNextAction():
    global gCounter

    import Indicator
    Indicator.setDefault()
    if sGrab.isGrabbed:
        if perform(90, True) == Constant.STATE_SUCCESS:
            gCounter = 0

    elif gCounter < 50:
        gCounter += 1
        sFindBall.perform()
    else:
        sGrab.perform()
Exemple #3
0
def DecideNextAction():
    global grabCounter
    grabCounter -= 1

    #testKick()
    #return

    Action.openMouth()
    sGrab.moveHeadForward()
    Action.walk(0, 0, 0)

    obsFront = VisionLink.getNoObstacleInBox(-25, 100, 25, 20,
                                             Constant.MIN_VIS_OBSTACLE_BOX,
                                             Constant.OBS_USE_LOCAL)
    obsLeft = VisionLink.getNoObstacleInBox(-80, 80, -40, -80,
                                            Constant.MIN_VIS_OBSTACLE_BOX,
                                            Constant.OBS_USE_LOCAL)
    obsRight = VisionLink.getNoObstacleInBox(40, 80, 80, -80,
                                             Constant.MIN_VIS_OBSTACLE_BOX,
                                             Constant.OBS_USE_LOCAL)

    print "Obstacle Front : ", obsFront, " Left : ", obsLeft, " Right: ", obsRight
    return

    #print "Camera Frame : ", Global.cameraFrame
    Indicator.setDefault()
    if not sGrab.isGrabbed or performToTargetGoal(
    ) != Constant.STATE_EXECUTING:
        if grabCounter == 60:
            hTrack.panLow = True
            resetPerform()
            sGrab.resetPerform()

        if grabCounter > 0:
            sFindBall.perform()
        else:
            sGrab.perform()

        grabCounter -= 1

    else:
        grabCounter = 60
Exemple #4
0
def kickOffShootGoal():
    global playCounter, whenGrabbed

    if pReady.isCentre(Global.kickOffPos):
        if playCounter > 150:
            sGrab.resetPerform()
            return False

        if whenGrabbed == 0:
            #print "grabbing"
            sGrab.perform()
            if sGrab.isGrabbed:
                #print "grabbed"
                whenGrabbed = playCounter
            return True

        if playCounter < whenGrabbed + 40:
            #print "walking"
            sGrabDribble(0, Action.MAX_LEFT, 0)
            return True

        # not aiming to visual goal
        if sGrabTurnKick.perform(False) == Constant.STATE_SUCCESS:
            #print "aiming"
            sGrab.resetPerform()
            return False

    elif pReady.isForward(Global.kickOffPos):
        if playCounter > 40:
            return False
        hTrack.saGoToTarget(Constant.TARGET_GOAL_X, Constant.TARGET_GOAL_Y)
    else:
        return False

    hFWHead.DecideNextAction()
    return True
Exemple #5
0
def kickOffUPenn():
    global playCounter, whenGrabbed

    if pReady.chosenFormation == 0:
        kickLeft = False
    else:
        kickLeft = True

    if pReady.isCentre(Global.kickOffPos):
        if playCounter > 150:
            return False

        if whenGrabbed == 0:
            print "grabbing"
            if sGrab.perform() == Constant.STATE_FAILED:
                return False
            if sGrab.isGrabbed:
                whenGrabbed = playCounter
            return True

        print "Grabbed!"
        if sUpennKick.perform(kickLeft) == Constant.STATE_SUCCESS:
            sGrab.resetPerform()
            return False

        sFindBall.perform(True)
        return True

    elif pReady.isForward(Global.kickOffPos):
        if playCounter > 40:
            return False
        hTrack.saGoToTarget(Constant.TARGET_GOAL_X, Constant.TARGET_GOAL_Y)
        hFWHead.DecideNextAction()
    else:
        return False

    return True
Exemple #6
0
def DecideNextAction():
    import hFWHead
    if sGrab.perform() == Constant.STATE_SUCCESS:
        hFWHead.DecideNextAction()
        perform(90)
Exemple #7
0
def doKickWithGrab():
    global gSelectedKick
    global gIsKickTriggering

    if not sGrab.isGrabbed:

        r = sGrab.perform()
        if r == Constant.STATE_FAILED:
            hTrack.panLow = True
            return r
        elif r == Constant.STATE_EXECUTING:
            return r
        # Grab success
        else:
            # override kick selection
            selectedKick = sSelKick.perform()

            # If the selected kick is different, then do kick reset.
            if gSelectedKick != None and selectedKick[0] != gSelectedKick[0]:
                doKickReset()
            gSelectedKick = selectedKick

            # If kick selection returns paw kick, change it to
            # grab dribble.
            # Because we can't paw kick or dribble from grab.
            kickType = gSelectedKick[0]
            if kickType == sSelKick.KT_DRIBBLE\
                or kickType == sSelKick.KT_PAW_KICK:
                gSelectedKick = (sSelKick.KT_GRAB_DRIBBLE, gSelectedKick[1],
                                 gSelectedKick[2])

            gIsKickTriggering = True

    r = Constant.STATE_EXECUTING

    if gIsKickTriggering:

        kickType, dkd, direction = gSelectedKick

        # Setting isClockwise
        isClockwise = None
        if direction == Constant.dCLOCKWISE:
            isClockwise = True
        elif direction == Constant.dANTICLOCKWISE:
            isClockwise = False

        if kickType == sSelKick.KT_GRAB_TURN_KICK:
            r = sGrabTurnKick.perform(False,\
                                      Action.DiveKickWT,\
                                      Constant.TARGET_GOAL_X,\
                                      Constant.FIELD_LENGTH)

        elif kickType == sSelKick.KT_GRAB_TURN_SHOOT:
            r = sGrabTurnKick.perform()

        elif kickType == sSelKick.KT_GRAB_DRIBBLE_GOAL:
            r = sGrabDribble.performToTargetGoal()

        elif kickType == sSelKick.KT_GRAB_DRIBBLE:
            r = sGrabDribble.performToDKD(dkd)

        elif kickType == sSelKick.KT_TURN_KICK:
            r = sTurnKick.perform(dkd, isClockwise=isClockwise)

        elif kickType == sSelKick.KT_UPENN_LEFT:
            #print "grab upeen left"
            r = sUpennKick.perform(dkd, True)

        elif kickType == sSelKick.KT_UPENN_RIGHT:
            #print "grab upeen right"
            r = sUpennKick.perform(dkd, False)

        else:
            print "rAttacker.py : No appropriate kick for grab chosen???"
            r = Constant.STATE_FAILED

    return r
Exemple #8
0
def doKickWithGrab():
    global gSelectedKick

    if not sGrab.isGrabbed:
        # If the ball is in the edge, do more get behind.
        if hWhere.ballOnEdge():
            r = sGrab.perform(sFindBall.GET_BEHIND_PRIORITY)
        else:
            r = sGrab.perform()

        if r == Constant.STATE_FAILED:
            hTrack.panLow = True
            return r
        elif r == Constant.STATE_EXECUTING:
            return r
        # Grab success
        else:
            # override kick selection
            selectedKick = sSelKick.perform()
            #print "kick reselected"
            # If the selected kick is different, then do kick reset.
            if gSelectedKick != None and selectedKick[0] != gSelectedKick[0]:
                doKickReset()
            gSelectedKick = selectedKick

            # If kick selection returns paw kick, change it to
            # grab dribble.
            # Because we can't paw kick or dribble from grab.
            kickType = gSelectedKick[0]
            if kickType == sSelKick.KT_DRIBBLE\
                or kickType == sSelKick.KT_PAW_KICK\
                or kickType == sSelKick.KT_AVOID_OWN_GOAL:
                gSelectedKick = (sSelKick.KT_GRAB_DRIBBLE, gSelectedKick[1],
                                 gSelectedKick[2])

    r = Constant.STATE_EXECUTING

    if sGrab.isGrabbed:

        if not sGrab.isBallUnderChin():
            return Constant.STATE_FAILED

        kickType, dkd, direction = gSelectedKick

        # Find a global co-ordinate on the dkd
        tx, ty = hMath.getPointRelative(Global.ballX, Global.ballY, dkd, 200)

        # Setting isClockwise
        isClockwise = None
        if direction == Constant.dCLOCKWISE:
            isClockwise = True
        elif direction == Constant.dANTICLOCKWISE:
            isClockwise = False

        if kickType == sSelKick.KT_GRAB_TURN_KICK:
            r = sGrabTurnKick.perform(False, Action.HeadTapWT, tx, ty)
            #r = sGrabDribble.performToDKD(dkd, 0)

        elif kickType == sSelKick.KT_GRAB_TURN_SHOOT:
            r = sGrabTurnKick.perform()

        elif kickType == sSelKick.KT_GRAB_DRIBBLE_GOAL:
            r = sGrabDribble.performToTargetGoal()

        elif kickType == sSelKick.KT_GRAB_DRIBBLE_STOP:
            r = sGrabDribble.performToDKD(dkd,
                                          minTimeToDribble=2500,
                                          dontKick=True)

        elif kickType == sSelKick.KT_GRAB_DRIBBLE:
            r = sGrabDribble.performToDKD(dkd)

        elif kickType == sSelKick.KT_TURN_KICK:
            r = sTurnKick.perform(dkd, isClockwise=isClockwise)

        elif kickType == sSelKick.KT_UPENN_LEFT:
            #print "grab upeen left"
            r = sUpennKick.perform(dkd, True)

        elif kickType == sSelKick.KT_UPENN_RIGHT:
            #print "grab upeen right"
            r = sUpennKick.perform(dkd, False)

        else:
            print "rAttacker.py : No appropriate kick for grab chosen??? ", kickType
            r = Constant.STATE_FAILED

    return r
Exemple #9
0
def GrabGenerator():
    global counter, grabbing_time_when_stop, moveTo, isCorrectstandingPosition
    grab_counter = 0
    sensor_counter = 0
    kickType = None
    # grabbing
    local_isGrabed = False
    if not local_isGrabed:
        sGrab.resetPerform()
        while sGrab.perform() == Constant.STATE_EXECUTING:
            if not isCorrectstandingPosition and Global.ballD <= 30:  #sGrab.REALLY_SLOW_DIST :
                isCorrectstandingPosition = True
                print "distance ok to stop"
                return
            yield True

    while local_isGrabed:
        if grabbing_time_when_stop > MAX_GRABBING_TIME_WHEN_STOP:
            grabbing_time_when_stop = 0
            local_isGrabed = True
        sGrab.moveHeadForward()
        Action.openMouth()
        grabbing_time_when_stop = grabbing_time_when_stop + 1
        yield True

    while not kickType:

        sGrab.moveHeadForward()
        Action.openMouth()

        #posx,posy = Global.selfLoc.getPos()
        #print "float:",posx, posy
        #posx = int(posx)
        #posy = int(posy)
        #print "int:",posx, posy
        if moveTo == None:
            print "WARNING moveTo == None"
        print "This is broken"
        #sGrabDribble.GrabSideWalk(moveTo)
        #kickType == Action.DiveKickWT

        grab_counter += 1

        if grab_counter % 15 != 0:
            if VisionLink.getAnySensor(Constant.ssCHEST_INFRARED) > 138000:
                sensor_counter += 1
        else:
            if sensor_counter < 3:
                print "Oops, fail grabbing the ball.."
                reset()
                return
            else:
                sensor_counter = 0

        # Check if we've grabbed for too long
        if grab_counter > GRAB_FRAME_MAX:
            kickType = Action.DiveKickWT
            #headColor((True, False, False))
            #Action.standStill()
            #reset()
            #return # Raise a StopIteration exception

        yield True

    # Start kick
#    if Debug.TurnAndSideMoveDebug :
    print "kicking"
    if kickType == Action.DiveKickWT:
        kickCount = 15  #30
    else:
        kickCount = 22

    # Do kick
    for _ in range(kickCount):
        Action.kick(kickType)
        Action.openMouth()
        yield True

    isCorrectstandingPosition = False
    Global.lostBall = 0
    reset()
Exemple #10
0
def perform(params=None):
    global gLastFrameCalled
    global gLastDecisionFunction
    global pos, friendPos, isPlayerSet, friend, friendloc, centerPos
    hTeam.sendWirelessInfo()

    id(params)  # ignore
    if not isPlayerSet:
        if Global.myPlayerNum == 3:
            friend = Global.teamPlayers[1]
            friendloc = Global.teammatesLoc[1]
            centerPos = (Constant.FIELD_WIDTH / 2, Constant.GOALBOX_DEPTH)
        else:
            friend = Global.teamPlayers[2]
            friendloc = Global.teammatesLoc[2]
            centerPos = (Constant.FIELD_WIDTH / 2,
                         Constant.FIELD_LENGTH - Constant.GOALBOX_DEPTH)
        isPlayerSet = True
        print "Player no:", Global.myPlayerNum

    friendPos = friendloc.getPos()
    pos = Global.selfLoc.getPos()
    #if friend grab, go to center position, while looking at obstacle, get facing ball.
    #if see ball far away, get behind ball (don't pass half the field) while scanning for ball and obstacle.
    #if see ball < 1/2 field, chase and grab, turn no obstacle, until facing friend or gap upfield. and kick if obstacle near, if not stop realease, and scan look for obstacle and ball.
    #if got wirelessball get behind wireless ball on keep a distance with obstacle, scan.
    #if doesn't see and doesn't have wireless ball, find ball and goto base spot to spin again.

    calculateObstacleBox()

    shouldIBeDodgy = gUseDodgyDog

    if gLastFrameCalled != Global.frame - 1:
        resetPerform()
    gLastFrameCalled = Global.frame

    #     elif shouldIKick():
    #         #shouldIBeDodgy = False  #Really?
    #         doKick()
    if (sGrab.isGrabbed):
        print "friend is in :", friendPos[0], " ", friendPos[1]
        r = scGrabDribble.performToPosition((friendPos[0], friendPos[1]))


#         if r == Constant.STATE_EXECUTING:
#             return
#         else:
#             scGrabDribble.resetPerform()
#align to friend gps, while avoiding the obstacle.
#and the pass to him.

    elif (sGrab.grabbingCount > 0):
        #print "grabbing"
        r = sGrab.perform(doGetBehindv=sFindBall.GET_BEHIND_NONE)
        if r == Constant.STATE_EXECUTING:
            return
        elif r == Constant.STATE_FAILED:
            sGrab.resetPerform()

    elif shouldIFindSpace():
        #print "Find space"
        doFindSpace()

    elif not shouldIEndActivelyLocalise()\
        or shouldIActivelyLocalise():
        #print "active loc"
        doActivelyLocalise()

    elif (Global.vBall.isVisible() or Global.lostBall < Constant.LOST_BALL_GPS
          or friend.hasSeenBall()):
        #print "see a ball"
        #if (friend.getTimeToReachBall() < selfobj.getTimeToReachBall() + 1000):
        if (centerPos[1] < Constant.FIELD_LENGTH / 2):
            isOtherHalf = Global.ballY > Constant.FIELD_LENGTH / 2
        else:
            isOtherHalf = Global.ballY < Constant.FIELD_LENGTH / 2

        if (isOtherHalf):  #And no near obstacle and Global.ballD > 30):
            #print "ball the other end"
            #if hMath.getDistSquaredBetween(pos[0],pos[1],Global.ballX,Global.ballY) > YDISTANCE_TO_BALL_SQR:
            if (abs(Global.ballX - pos[0]) > YDISTANCE_TO_BALL):
                sFindBall.perform(True)
                #time to ball ? to get the ball if the other one is slow
                if (centerPos[1] < Constant.FIELD_LENGTH / 2):
                    hTrack.saGoToTarget(
                        Global.ballX,
                        max(pos[1], Global.ballY - YDISTANCE_TO_BALL)
                    )  #and ywhere the same or more if y diff less than 2 meter)
                else:
                    hTrack.saGoToTarget(
                        Global.ballX,
                        max(pos[1], Global.ballY + YDISTANCE_TO_BALL)
                    )  #and ywhere the same or more if y diff less than 2 meter)
            else:
                sFindBall.perform(True)
                if (centerPos[1] < Constant.FIELD_LENGTH / 2):
                    movePoint = (max(
                        LOOK_OFFSETX,
                        min(Global.ballX,
                            Constant.FIELD_WIDTH - LOOK_OFFSETX)),
                                 Global.ballY - YDISTANCE_TO_BALL)
                else:
                    movePoint = (max(
                        LOOK_OFFSETX,
                        min(Global.ballX,
                            Constant.FIELD_WIDTH - LOOK_OFFSETX)),
                                 Global.ballY + YDISTANCE_TO_BALL)

                hTrack.saGoToTargetFacingHeading(
                    movePoint[0], movePoint[1],
                    hMath.getHeadingBetween(pos[0], pos[1], Global.ballX,
                                            Global.ballY))
        else:
            #print "Grab"
            r = sGrab.perform(doGetBehindv=sFindBall.GET_BEHIND_NONE)
            if r == Constant.STATE_EXECUTING:
                return
            elif r == Constant.STATE_FAILED:
                sGrab.resetPerform()
    else:  #if shouldIGoToCenter():
        #print "goto center"
        doGotoCenter()

    # Use dodgy dog if required
    fwdCmd = Action.finalValues[Action.Forward]
    shouldIBeDodgy = shouldIBeDodgy and (not sGrab.isGrabbed) \
                    and sGrab.grabbingCount == 0 \
                    and Global.ballD > sGrab.CLOSE_DIST \
                    and fwdCmd > Action.MAX_SKE_FWD_SPD/2 \
                    and fwdCmd > Action.finalValues[Action.Left] \
                    and sDodgyDog.shouldIBeDodgyToBall()

    if shouldIBeDodgy:
        sDodgyDog.dodgyDogToBall()
Exemple #11
0
def kickOffKickToGap():
    global playCounter, whenGrabbed
    global bestHeading, gBestHeading

    (myX, myY) = Global.selfLoc.getPos()
    myH = Global.selfLoc.getHeading()

    if pReady.chosenFormation == 0:
        print "chosenFormation =", pReady.chosenFormation, "- going right"
        (kickX, kickY) = (Constant.MAX_GOALBOX_EDGE_X,
                          Constant.TOP_GOALBOX_EDGE_Y)
        (suppX, suppY) = (kickX + 40, kickY - 40)
        (lKickX, lKickY) = hMath.getLocalCoordinate(myX, myY, myH, kickX,
                                                    kickY)
    else:
        print "chosenFormation =", pReady.chosenFormation, "- going left"
        (kickX, kickY) = (Constant.MIN_GOALBOX_EDGE_X,
                          Constant.TOP_GOALBOX_EDGE_Y)
        (suppX, suppY) = (kickX - 40, kickY - 40)
        (lKickX, lKickY) = hMath.getLocalCoordinate(myX, myY, myH, kickX,
                                                    kickY)

    if pReady.isCentre(Global.kickOffPos):
        if playCounter > 120:  # 6 sec, just in case
            return False

        if whenGrabbed == 0:
            #print "grabbing"
            if sGrab.grabbingCount == 0:
                # Find the obstacle gap just before we drop the head to grab
                (gapLeft, gapRight, bestHeading, angle) = \
                    VisionLink.getBestGap(lKickX, lKickY,
                                            GAP_MAX_DIST,GAP_MIN_DIST,
                                            GAP_MIN,GAP_MIN_INTENSITY,
                                            Constant.OBS_USE_SHARED)
                gBestHeading = hMath.local2GlobalHeading(
                    Global.selfLoc, bestHeading)
                #gBestHeading = hMath.getHeadingBetween(Constant.FIELD_WIDTH/2, Constant.FIELD_LENGTH/2, kickX, kickY)
                print "local target", lKickX, lKickY
                print "gap", bestHeading, gBestHeading
            if sGrab.perform() == Constant.STATE_FAILED:
                return False
            if sGrab.isGrabbed:
                print "grabbed, best gap at local", bestHeading, \
                        "global", gBestHeading
                whenGrabbed = playCounter
            return True

        # Don't prevent other forward from being attacker
        Global.myRole = Global.myLastRole = Constant.SUPPORTER

        relH = gBestHeading - Global.selfLoc.getHeading()
        if abs(relH) >= 3:
            if sGrabDribble.perform(0, 0, relH) == Constant.STATE_FAILED:
                return False
            return True

        Action.kick(Action.SoftTapWT)
        if Action.shouldIContinueKick():
            Action.continueKick()
            return True

        sGrab.resetPerform()
        return False

    elif pReady.isForward(Global.kickOffPos):
        if playCounter < 80:
            sDodgyDog.dodgyDogTo(suppX, suppY)
            hTrack.stationaryLocalise(6, 30, -30)
            return True
        elif playCounter < 120:
            if hTrack.canSeeBall and Global.ballD < 30:
                Global.myRole = Global.myLastRole = Constant.ATTACKER
                return False
            h = hMath.normalizeAngle_0_360(myH + Global.ballH)
            hTrack.saGoToTargetFacingHeading(suppX, suppY, h)
            hFWHead.DecideNextAction()
            return True
        else:
            Global.myRole = Global.myLastRole = Constant.ATTACKER
            return False
    else:
        return False

    return False
Exemple #12
0
def kickOffKickToCorner():
    global playCounter, whenGrabbed
    global bestHeading, gBestHeading

    # Warning: this set play freezes the attacker when it fails.
    # Don't use it yet

    (myX, myY) = Global.selfLoc.getPos()
    myH = Global.selfLoc.getHeading()

    if pReady.chosenFormation == 0:
        (kickX, kickY) = (Constant.FIELD_WIDTH, Constant.FIELD_LENGTH - 80)
        (suppX, suppY) = (kickX + 40, kickY - 40)
    else:
        (kickX, kickY) = (0, Constant.FIELD_LENGTH - 80)
        (suppX, suppY) = (kickX - 40, kickY - 40)

    if pReady.isCentre(Global.kickOffPos):
        print "kickToCorner: whenGrabbed", whenGrabbed,
        if playCounter > 120:  # 6 sec, just in case
            return False

        if whenGrabbed == 0:
            if sGrab.grabbingCount == 0:
                # Find the obstacle gap just before we drop the head to grab
                #(gapLeft, gapRight, bestHeading, angle) = \
                #    VisionLink.getBestGap(lKickX, lKickY,
                #                            GAP_MAX_DIST,GAP_MIN_DIST,
                #                            GAP_MIN,GAP_MIN_INTENSITY,
                #                            Constant.OBS_USE_SHARED)
                gap = getGapTo(kickX, kickY)
                if gap != None:
                    (gapLeft, gapRight, bestHeading, angle) = gap
                    bestHeading += hMath.getSign(5, bestHeading)
                else:
                    bestHeading = hMath.getHeadingToAbsolute(
                        Global.selfLoc, kickX, kickY)

                gBestHeading = hMath.local2GlobalHeading(
                    Global.selfLoc, bestHeading)
                print "gap", bestHeading, gBestHeading,
            print "grabbing"
            if sGrab.perform() == Constant.STATE_FAILED:
                print "Grab failed in set play. Done."
                sGrab.resetPerform()
                Global.myRole = Global.myLastRole = Constant.ATTACKER
                return False
            if sGrab.isGrabbed:
                print "grabbed, best gap at local", bestHeading, \
                        "global", gBestHeading
                whenGrabbed = playCounter
            return True

        # Don't prevent other forward from being attacker
        Global.myRole = Global.myLastRole = Constant.SUPPORTER

        # Keep updating gap, but not with shared obs
        gap = getGapTo(kickX, kickY)
        if gap != None:
            (gapLeft, gapRight, bestHeading, angle) = gap
            bestHeading += hMath.getSign(5, bestHeading)
            gBestHeading = hMath.local2GlobalHeading(Global.selfLoc,
                                                     bestHeading)
            print "New gap global", gBestHeading,
        else:
            print "No gap left - using last global", gBestHeading,
            #bestHeading = 0 # Kick now
        relH = gBestHeading - Global.selfLoc.getHeading()
        print "relH", relH,
        if abs(relH) >= 4 and (playCounter - whenGrabbed) < 55:
            print "dribbling"
            if sGrabDribble.perform(0, 0, relH) == Constant.STATE_FAILED:
                print "dribble failed. Done."
                Global.myRole = Global.myLastRole = Constant.ATTACKER
                return False
            return True

        print "Kicking",
        Action.kick(Action.SoftTapWT)
        if Action.shouldIContinueKick():
            Action.continueKick()
            return True

        sGrab.resetPerform()
        print "success. Done."
        return False

    elif pReady.isForward(Global.kickOffPos):
        Global.myRole = Global.myLastRole = Constant.ATTACKER
        if playCounter < 60:
            hTrack.saGoToTarget(suppX, suppY, 25)
            hFWHead.DecideNextAction()
            return True
        elif playCounter < 100:
            if hTrack.canSeeBall and Global.ballD < 30:
                return False
            h = hMath.normalizeAngle_0_360(myH + Global.ballH)
            hTrack.saGoToTargetFacingHeading(suppX, suppY, h)
            hFWHead.DecideNextAction()
            return True
        else:
            rAttacker.perform()
            return False
    else:
        return False

    return False
Exemple #13
0
def kickOffPushToSupporter():
    global playCounter, whenGrabbed
    global bestHeading, gBestHeading

    (myX, myY) = Global.selfLoc.getPos()
    myH = Global.selfLoc.getHeading()

    if pReady.chosenFormation == 0:
        (suppX, suppY) = (PUSH_TO_X + 40, PUSH_TO_Y - 40)
    else:
        (suppX, suppY) = (PUSH_TO_X - 40, PUSH_TO_Y - 40)

    if pReady.isCentre(Global.kickOffPos):
        if playCounter > 180:  # 6 sec, just in case
            return False

        if whenGrabbed == 0:
            #print "grabbing"
            if sGrab.grabbingCount == 0:
                # Find the obstacle gap just before we drop the head to grab
                #(gapLeft, gapRight, bestHeading, angle) = \
                #    VisionLink.getBestGap(lKickX, lKickY,
                #                            GAP_MAX_DIST,GAP_MIN_DIST,
                #                            GAP_MIN,GAP_MIN_INTENSITY,
                #                            Constant.OBS_USE_SHARED)
                gap = getGapTo(PUSH_TO_X, PUSH_TO_Y)
                if gap != None:
                    (gapLeft, gapRight, bestHeading, angle) = gap
                else:
                    bestHeading = hMath.getHeadingToAbsolute(
                        Global.selfLoc, PUSH_TO_X, PUSH_TO_Y)
                gBestHeading = hMath.local2GlobalHeading(
                    Global.selfLoc, bestHeading)
                print "gap ", bestHeading, gBestHeading
            if sGrab.perform() == Constant.STATE_FAILED:
                return False
            if sGrab.isGrabbed:
                #print "grabbed, best gap at local", bestHeading, \
                #        "global", gBestHeading
                whenGrabbed = playCounter
            return True

        # Don't prevent other forward from being attacker
        Global.myRole = Global.myLastRole = Constant.SUPPORTER

        relH = gBestHeading - Global.selfLoc.getHeading()
        if playCounter - whenGrabbed < 40:
            if sGrabDribble.perform(Action.MAX_FORWARD, 0, relH) \
                    == Constant.STATE_FAILED:
                return False
            return True

        Action.kick(Action.GTChestPushWT)
        if Action.shouldIContinueKick():
            Action.continueKick()
            return True

        sGrab.resetPerform()
        return False

    elif pReady.isForward(Global.kickOffPos):
        if playCounter < 80:
            sDodgyDog.dodgyDogTo(suppX, suppY)
            hTrack.stationaryLocalise(6, 30, -30)
            return True
        elif playCounter < 120:
            if hTrack.canSeeBall and Global.ballD < 30:
                Global.myRole = Global.myLastRole = Constant.ATTACKER
                return False
            h = hMath.normalizeAngle_0_360(myH + Global.ballH)
            hTrack.saGoToTargetFacingHeading(suppX, suppY, h)
            hFWHead.DecideNextAction()
            return True
        else:
            Global.myRole = Global.myLastRole = Constant.ATTACKER
            return False
    else:
        return False

    return False