def perform(aimToGoal = True, kickType=Action.HeadTapWT, \ tX = Constant.TARGET_GOAL_X, tY = Constant.TARGET_GOAL_Y): global gLastFrameCalled global gtkGenerator global isAimToGoal, targetX, targetY, gKickType if not sGrab.isGrabbed: resetPerform() return Constant.STATE_FAILED elif not sGrab.isBallUnderChin(): sGrab.resetPerform() resetPerform() return Constant.STATE_FAILED if gLastFrameCalled != Global.frame - 1: resetPerform() gLastFrameCalled = Global.frame if gtkGenerator == None: isAimToGoal = aimToGoal if not isAimToGoal: targetX = tX targetY = tY gKickType = kickType gtkGenerator = gtkGeneratorFunc() try: Global.lostBall = 0 gtkGenerator.next() except StopIteration: resetPerform() return Constant.STATE_SUCCESS return Constant.STATE_EXECUTING
def perform(forward, left, turnCCW, walkType=None, minorWalkType=None, checkForBallUnderChin=True): if not sGrab.isGrabbed: resetPerform() return Constant.STATE_FAILED elif checkForBallUnderChin and not sGrab.isBallUnderChin(): sGrab.resetPerform() resetPerform() return Constant.STATE_FAILED Action.openMouth() moveHeadForward() wt = Action.SkellipticalWalkWT if forward != 0 and left != 0 and turnCCW != 0: mwt = Action.GrabDribbleMWT elif forward != 0 and left != 0: mwt = Action.GrabDribbleMWT elif forward != 0 and turnCCW != 0: if abs(turnCCW) < 10: mwt = Action.SkeFastForwardMWT else: mwt = Action.SkeGrabDribbleMWT elif left != 0 and turnCCW != 0: mwt = Action.SkeGrabDribbleMWT elif forward != 0: mwt = Action.SkeFastForwardMWT elif left != 0: mwt = Action.SkeGrabDribbleMWT elif turnCCW != 0: mwt = Action.SkeGrabDribbleMWT else: mwt = Action.SkeGrabDribbleMWT if walkType != None: wt = walkType if minorWalkType != None: mwt = minorWalkType Action.walk(forward, left, turnCCW, "sdd", wt, mwt) return Constant.STATE_EXECUTING
def isBallUnderChin(): return gIsHeadLifting\ or sGrab.isBallUnderChin()
def perform(forward, left, turnCCW, walkType=None, minorWalkType=None, checkForBallUnderChin=True): global gLastActionFrame global gTurnCCWSpd if not sGrab.isGrabbed: print "Grab failed" resetPerform() return Constant.STATE_FAILED elif checkForBallUnderChin and not sGrab.isBallUnderChin(): sGrab.resetPerform() resetPerform() return Constant.STATE_FAILED Action.openMouth() moveHeadForward() gLastActionFrame = Global.frame wt = Action.SkellipticalWalkWT if forward != 0 and left != 0 and turnCCW != 0: mwt = Action.GrabDribbleMWT elif forward != 0 and left != 0: mwt = Action.GrabDribbleMWT elif forward != 0 and turnCCW != 0: if abs(turnCCW) < 10: mwt = Action.SkeFastForwardMWT else: mwt = Action.SkeGrabDribbleMWT elif left != 0 and turnCCW != 0: mwt = Action.SkeGrabDribbleMWT elif forward != 0: mwt = Action.SkeFastForwardMWT elif left != 0: mwt = Action.SkeGrabDribbleMWT elif turnCCW != 0: mwt = Action.SkeGrabDribbleMWT else: mwt = Action.SkeGrabDribbleMWT if walkType != None: wt = walkType if minorWalkType != None: mwt = minorWalkType Action.walk(forward, left, turnCCW, "sdd", wt, mwt) if gTurnCCWSpd != None: Action.finalValues[Action.TurnCCW] = gTurnCCWSpd gTurnCCWSpd = None return Constant.STATE_EXECUTING
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