def goalieSave(player): brain = player.brain ball = brain.ball if player.firstFrame(): player.stopWalking() brain.tracker.trackBallFixedPitch() player.isSaving = True if helper.shouldSave(player): brain.tracker.stopHeadMoves() brain.fallController.enableFallProtection(False) if TESTING: print "Saving because" print "Ball.relVelX is" + str(ball.loc.relVelX) print "And Ball.heat is" + str(ball.vis.heat) if helper.shouldSaveRight(player): return player.goNow('testSaveRight') elif helper.shouldSaveLeft(player): return player.goNow('testSaveLeft') else: return player.goNow('testSaveCenter') else: if helper.shouldSaveRight(player): return player.goNow('saveRight') if helper.shouldSaveLeft(player): return player.goNow('saveLeft') else: return player.goNow('saveCenter') return player.stay()
def goalieSave(player): brain = player.brain ball = brain.ball if player.firstFrame(): player.stopWalking() brain.tracker.trackBall() player.isSaving = True if helper.shouldSave(player): brain.tracker.stopHeadMoves() brain.fallController.enableFallProtection(False) if TESTING: print "Saving because" print "Ball.relVelX is" + str(ball.loc.relVelX) print "And Ball.heat is" + str(ball.vis.heat) if helper.shouldSaveRight(player): return player.goNow("testSaveRight") elif helper.shouldSaveLeft(player): return player.goNow("testSaveLeft") else: return player.goNow("testSaveCenter") else: if helper.shouldSaveRight(player): return player.goNow("saveRight") if helper.shouldSaveLeft(player): return player.goNow("saveLeft") else: return player.goNow("saveCenter") return player.stay()
def goaliePosition(player): """ Have the robot navigate to the position reported to it from playbook """ nav = player.brain.nav my = player.brain.my ball = player.brain.ball heading = None if player.firstFrame(): player.isPositioning = True player.isChasing = False player.isSaving = False nav.positionPlaybook() if ball.dist >= goalCon.ACTIVE_LOC_THRESH: player.brain.tracker.activeLoc() else: player.brain.tracker.trackBall() if player.brain.nav.isStopped(): if goalTran.shouldPositionLeft(player): player.goNow('goaliePositionLeft') elif goalTran.shouldPositionRight(player): player.goNow('goaliePositionRight') return player.stay()
def testShouldPositionRight(player): if player.counter % 100 == 0: if goalTran.shouldPositionRight(player): print "position right" elif goalTran.shouldPositionLeft(player): print "position left" elif goalTran.shouldPositionCenter(player): print "postion center" return player.stay()
def goaliePickSave(player): player.brain.fallController.enableFallProtection(False) if helper.shouldSaveRight(player): return player.goNow('saveRight') elif helper.shouldSaveLeft(player): return player.goNow('saveLeft') elif helper.shouldSaveCenter(player): return player.goNow('saveCenter') return player.stay()
def goaliePositionForSave(player): if player.firstFrame(): player.stopWalking() player.brain.tracker.trackBall() strafeDir = helper.strafeDirForSave(player) if strafeDir == -1: helper.strafeRightSpeed(player) elif strafeDir == 1: helper.strafeLeftSpeed(player) else: player.stopWalking() return player.stay()
def holdLeftSave(player): if helper.shouldHoldSave(player): return player.stay() else: return player.goLater('rollOutLeft') return player.stay()
def testSaveDecision(player): ball = player.brain.ball if goalTran.shouldSave(player): return player.goNow('goalieSave') return player.stay()
def squatPosition(player): brain = player.brain position = brain.play.getPosition() nav = brain.nav my = brain.my if player.firstFrame(): player.changeOmniGoToCounter = 0 player.isChasing = False player.squatting = False if brain.ball.x >= constants.ACTIVE_LOC_THRESH: brain.tracker.activeLoc() else: brain.tracker.trackBall() useOmni = helper.useOmni(player) changedOmni = False ball = brain.ball bearing = None if (not nav.atDestinationGoalie() or not nav.atHeading()): if not useOmni: nav.goTo((PBConstants.GOALIE_HOME_X, PBConstants.GOALIE_HOME_Y,\ NogginConstants.OPP_GOAL_HEADING)) else: nav.omniGoTo((PBConstants.GOALIE_HOME_X, PBConstants.GOALIE_HOME_Y,\ NogginConstants.OPP_GOAL_HEADING)) else: player.stopWalking() return player.goLater("squat") return player.stay()
def holdCenterSave(player): if helper.shouldHoldSave(player): return player.stay() else: return player.goLater('postCenterSave') return player.stay()
def positionForGoalieKick(player): if player.firstFrame(): player.brain.tracker.lookStraightThenTrack() if clearBall.ballSide == RIGHT: player.kick = kicks.RIGHT_SHORT_STRAIGHT_KICK else: player.kick = kicks.LEFT_SHORT_STRAIGHT_KICK ball = player.brain.ball positionForGoalieKick.kickPose = RelRobotLocation(ball.rel_x - player.kick.setupX, ball.rel_y - player.kick.setupY, 0) positionForGoalieKick.speed = nav.GRADUAL_SPEED player.brain.nav.goTo(positionForGoalieKick.kickPose, speed = positionForGoalieKick.speed, precision = nav.CLOSE_ENOUGH) ball = player.brain.ball positionForGoalieKick.kickPose = RelRobotLocation(ball.rel_x - player.kick.setupX, ball.rel_y - player.kick.setupY, 0) player.brain.nav.updateDest(positionForGoalieKick.kickPose) if GoalieTransitions.ballReadyToKick(player, positionForGoalieKick.kickPose): player.brain.nav.stand() return player.goNow('kickBall') return Transition.getNextState(player, positionForGoalieKick)
def approachBall(player): """ Once we are aligned with the ball, approach it """ # Switch to other states if we should if player.penaltyKicking and \ player.brain.ball.inOppGoalBox(): return player.goNow('penaltyBallInOppGoalbox') elif player.brain.tracker.activeLocOn: if transitions.shouldScanFindBallActiveLoc(player): return player.goLater('scanFindBall') elif transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') elif player.brain.play.isRole(GOALIE) and goalTran.dangerousBall(player): return player.goNow('approachDangerousBall') elif transitions.shouldDribble(player): return player.goNow('dribble') elif transitions.shouldSpinToBallClose(player): return player.goNow('spinToBallClose') elif transitions.shouldStopBeforeKick(player): return player.goNow('stopBeforeKick') elif transitions.shouldPositionForKick(player): return player.goNow('decideKick') if player.firstFrame(): player.brain.nav.chaseBall() player.hasAlignedOnce = False player.brain.tracker.trackBall() return player.stay()
def holdRightSave(player): if helper.shouldHoldSave(player): return player.stay() else: return player.goLater('rollOutRight') return player.stay()
def holdLeftSave(player): if helper.shouldHoldSave(player): return player.stay() else: return player.goLater("rollOutLeft") return player.stay()
def testSaveCenter(player): if player.firstFrame(): player.executeMove(SweetMoves.GOALIE_TEST_CENTER_SAVE) if player.counter > goalCon.TEST_SAVE_WAIT and not helper.shouldHoldSave(player): player.executeMove(SweetMoves.INITIAL_POS) return player.goNow("doneSaving") return player.stay()
def holdCenterSave(player): if helper.shouldHoldSave(player): return player.stay() else: return player.goLater("postCenterSave") return player.stay()
def positionForGoalieKick(player): if player.firstFrame(): player.brain.tracker.lookStraightThenTrack() if clearBall.ballSide == RIGHT: player.kick = kicks.RIGHT_SHORT_STRAIGHT_KICK else: player.kick = kicks.LEFT_SHORT_STRAIGHT_KICK ball = player.brain.ball positionForGoalieKick.kickPose = RelRobotLocation(ball.rel_x - player.kick.setupX, ball.rel_y - player.kick.setupY, 0) print("Kickpose:", positionForGoalieKick.kickPose.relX, positionForGoalieKick.kickPose.relY) positionForGoalieKick.speed = nav.GRADUAL_SPEED player.brain.nav.goTo(positionForGoalieKick.kickPose, speed = positionForGoalieKick.speed, precision = nav.CLOSE_ENOUGH) ball = player.brain.ball positionForGoalieKick.kickPose = RelRobotLocation(ball.rel_x - player.kick.setupX, ball.rel_y - player.kick.setupY, 0) player.brain.nav.updateDest(positionForGoalieKick.kickPose) if GoalieTransitions.ballReadyToKick(player, positionForGoalieKick.kickPose): player.brain.nav.stand() print("Kickpose:", positionForGoalieKick.kickPose.relX, positionForGoalieKick.kickPose.relY) return player.goNow('kickBall') return Transition.getNextState(player, positionForGoalieKick)
def testSaveLeft(player): if player.firstFrame(): player.executeMove(SweetMoves.GOALIE_TEST_DIVE_LEFT) if(player.counter > goalCon.TEST_SAVE_WAIT and not helper.shouldHoldSave(player)): player.executeMove(SweetMoves.INITIAL_POS) return player.goNow('doneSaving') return player.stay()
def testInBox(player): if player.counter % 100 == 0: if goalTran.goalieInBox(player): print "in" else: print "out" return player.stay()
def testDangerousBall(player): if player.counter % 100 == 0: if goalTran.dangerousBall(player): print "dangerous" else: print "not dangerous" return player.stay()
def testSaveCenter(player): if player.firstFrame(): player.executeMove(SweetMoves.GOALIE_TEST_CENTER_SAVE) if (player.counter > goalCon.TEST_SAVE_WAIT and not helper.shouldHoldSave(player)): player.executeMove(SweetMoves.INITIAL_POS) return player.goNow('doneSaving') return player.stay()
def testStopChase(player): player.isChasing = True if goalTran.shouldStopChase(player): print "stop" else: print "not stopping" return player.stay()
def testChase(player): player.isSaving = False player.penaltyKicking = False if goalTran.shouldChase(player): print "chase" else: print "staying" return player.stay()
def goalieStateChoice(player): ball = player.brain.ball # for simplicity to start off with we just want the goalie to chase # the ball as long as it is close enough and it isnt dangerous if player.isChasing: if goalTran.shouldStopChase(player): return "goaliePosition" else: return player.currentState if player.isPositioning: if goalTran.outOfPosition(player): return player.currentState elif goalTran.shouldChase(player): return "goalieChase" return player.currentState
def goalieOutOfPosition(player): nav = player.brain.nav if helper.useFarPosition(player): player.brain.tracker.activeLoc() else: player.brain.tracker.trackBall() position = player.brain.play.getPosition() if player.firstFrame() or\ nav.destX != position[0] or nav.destY != position[1]: nav.omniGoTo(position) if helper.useClosePosition(player): return player.goLater('goaliePositionBallClose') if nav.isStopped() and player.counter > 0: player.framesFromCenter = 0 player.stepOffCenter = 0 return player.goLater('goaliePosition') return player.stay()
def chase(player): """ Super State to determine what to do from various situations """ if transitions.shouldFindBall(player): return player.goNow('findBall') if player.brain.play.isRole(GOALIE) and goalTran.dangerousBall(player): return player.goNow('approachDangerousBall') else: return player.goNow('positionForKick')
def goaliePositionForSave(player): if player.firstFrame(): player.stopWalking() player.brain.tracker.trackBall() strafeDir = helper.strafeDirForSave(player) if fabs(strafeDir) > 0: player.setWalk(0, constants.STRAFE_SPEED * MyMath.sign(strafeDir), 0) else: player.stopWalking() return player.stay()
def chase(player): """ Super State to determine what to do from various situations """ if transitions.shouldFindBall(player): return player.goNow('findBall') if player.brain.play.isRole(GOALIE) and goalTran.dangerousBall(player): return player.goNow('approachDangerousBall') else: return player.goNow('spinToBall')
def approachBallWalk(player): """ Method that is used by both approach ball and dribble We use things as to when we should leave and how we should walk """ if player.brain.playbook.role != pbc.GOALIE: if transitions.shouldNotGoInBox(player): return player.goLater('ballInMyBox') elif transitions.shouldChaseAroundBox(player): return player.goLater('chaseAroundBox') elif transitions.shouldApproachBallWithLoc(player): return player.goNow('approachBallWithLoc') elif transitions.shouldTurnToBall_ApproachBall(player): return player.goLater('turnToBall') elif not player.brain.tracker.activeLocOn and \ transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') elif player.brain.tracker.activeLocOn and \ transitions.shouldScanFindBallActiveLoc(player): return player.goLater('scanFindBall') elif transitions.shouldAvoidObstacleDuringApproachBall(player): return player.goLater('avoidObstacle') # Determine our speed for approaching the ball ball = player.brain.ball if player.brain.playbook.role == pbc.GOALIE and goalTran.dangerousBall(player): return player.goNow('approachDangerousBall') if ball.dist < constants.APPROACH_WITH_GAIN_DIST: sX = MyMath.clip(ball.dist*constants.APPROACH_X_GAIN, constants.MIN_APPROACH_X_SPEED, constants.MAX_APPROACH_X_SPEED) else : sX = constants.MAX_APPROACH_X_SPEED # Determine the speed to turn to the ball sTheta = MyMath.clip(ball.bearing*constants.APPROACH_SPIN_GAIN, -constants.APPROACH_SPIN_SPEED, constants.APPROACH_SPIN_SPEED) # Avoid spinning so slowly that we step in place if fabs(sTheta) < constants.MIN_APPROACH_SPIN_MAGNITUDE: sTheta = 0.0 # Set our walk towards the ball if ball.on: player.setSpeed(sX,0,sTheta) return player.stay()
def approachBallWalk(player): """ Method that is used by both approach ball and dribble We use things as to when we should leave and how we should walk """ if not player.brain.play.isRole(GOALIE): if transitions.shouldNotGoInBox(player): return player.goLater('ballInMyBox') elif transitions.shouldChaseAroundBox(player): return player.goLater('chaseAroundBox') elif transitions.shouldApproachBallWithLoc(player): return player.goNow('approachBallWithLoc') elif transitions.shouldTurnToBall_ApproachBall(player): return player.goLater('turnToBall') elif not player.brain.tracker.activeLocOn and \ transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') elif player.brain.tracker.activeLocOn and \ transitions.shouldScanFindBallActiveLoc(player): return player.goLater('scanFindBall') elif transitions.shouldAvoidObstacleDuringApproachBall(player): return player.goLater('avoidObstacle') # Determine our speed for approaching the ball ball = player.brain.ball if player.brain.play.isRole(GOALIE) and goalTran.dangerousBall(player): return player.goNow('approachDangerousBall') if ball.dist < constants.APPROACH_WITH_GAIN_DIST: sX = MyMath.clip(ball.dist * constants.APPROACH_X_GAIN, constants.MIN_APPROACH_X_SPEED, constants.MAX_APPROACH_X_SPEED) else: sX = constants.MAX_APPROACH_X_SPEED # Determine the speed to turn to the ball sTheta = MyMath.clip(ball.bearing * constants.APPROACH_SPIN_GAIN, -constants.APPROACH_SPIN_SPEED, constants.APPROACH_SPIN_SPEED) # Avoid spinning so slowly that we step in place if fabs(sTheta) < constants.MIN_APPROACH_SPIN_MAGNITUDE: sTheta = 0.0 # Set our walk towards the ball if ball.on: player.setWalk(sX, 0, sTheta) return player.stay()
def goalieSave(player): #going to want it to get in a squat to prepare at somepoint in here brain = player.brain if player.firstFrame(): player.isSaving = True player.isChasing = False brain.motion.stopHeadMoves() player.stopWalking() brain.tracker.trackBall() if helper.shouldSave(player): return player.goNow('goaliePickSave') return player.stay()
def approachDangerousBall(player): if player.firstFrame(): player.stopWalking() #print "approach dangerous ball" #single steps towards ball and goal with spin player.setSteps(0, 0, 0, 0) if not goalTran.dangerousBall(player): return player.goLater('approachBall') if transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') elif transitions.shouldTurnToBall_ApproachBall(player): return player.goLater('turnToBall') elif transitions.shouldSpinFindBall(player): return player.goLater('spinFindBall') return player.stay()
def goaliePosition(player): """ Have the robot navigate to the position reported to it from playbook """ nav = player.brain.nav my = player.brain.my ball = player.brain.ball heading = None if player.firstFrame(): nav.positionPlaybook() player.brain.tracker.trackBallFixedPitch() if goalTran.goalieIsLost(player): return player.goLater('spinToField') return player.stay()
def goalieSpinToPosition(player): nav = player.brain.nav if helper.useFarPosition(player): player.brain.tracker.activeLoc() else: player.brain.tracker.trackBall() if not nav.atHeading(NogginConstants.OPP_GOAL_HEADING): spinDir = MyMath.getSpinDir(player.brain.my.h, NogginConstants.OPP_GOAL_HEADING) player.setSpeed(0, 0, spinDir*10) return player.stay() else: player.stopWalking() return player.goLater('goaliePosition') return player.stay()
def goaliePosition(player): """ Have the robot navigate to the position reported to it from playbook """ nav = player.brain.nav my = player.brain.my ball = player.brain.ball heading = None if player.firstFrame(): nav.positionPlaybook() player.brain.tracker.trackBall() if goalTran.goalieIsLost(player): return player.goLater('spinToField') return player.stay()
def approachDangerousBall(player): """adjusts position to be farther away from the ball if the goalie is too close to the ball while in the goal box""" if player.firstFrame(): player.stopWalking() #move away from the ball so it is no longer dangerous if player.brain.nav.isStopped(): if player.brain.ball.loc.relY > 0: player.brain.nav.walk(0, -15, 0) else: player.brain.nav.walk(0, 15, 0) if not goalTran.dangerousBall(player) or transitions.shouldFindBall(player): return player.goLater('chase') return player.stay()
def goaliePositionBallFar(player): nav = player.brain.nav player.brain.tracker.activeLoc() if helper.outOfPosition(player): player.goLater('goalieOutOfPosition') #elif not nav.atHeading(NogginConstants.OPP_GOAL_HEADING): # return player.goLater('goalieSpinToPosition') elif helper.useLeftStrafeFarSpeed(player): helper.strafeLeftSpeed(player) elif helper.useRightStrafeFarSpeed(player): helper.strafeRightSpeed(player) else: player.stopWalking() #Don't switch out if we don't see the ball if helper.useClosePosition(player): return player.goLater('goaliePositionBallClose') return player.stay()
def approachDangerousBall(player): ball = player.brain.ball my = player.brain.my if player.firstFrame(): player.stopWalking() #move away from the ball so it is no longer dangerous if player.brain.nav.isStopped(): if ball.relY > 0: player.brain.nav.walk(0, -15, 0) else: player.brain.nav.walk(0, 15, 0) if not goalTran.dangerousBall(player): return player.goLater('chase') if transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') return player.stay()
def holdLeftSave(player): if helper.shouldHoldSave(player): player.executeMove(SweetMoves.SAVE_LEFT_HOLD_DEBUG) else: return player.goLater('postSave') return player.stay()
def saveStrafe(player): strafeDir = helper.strafeDirForSave(player) if fabs(strafeDir) > 0: player.setWalk(0, constants.STRAFE_SPEED * MyMath.sign(strafeDir), 0) else: player.stopWalking()
def holdCenterSave(player): if helper.shouldHoldSave(player): pass # player.executeMove(SweetMoves.SAVE_CENTER_HOLD_DEBUG) else: return player.goLater('postSave') return player.stay()