def approachBall(player): if player.firstFrame(): player.brain.tracker.trackBall() if player.shouldKickOff: player.brain.nav.chaseBall(Navigator.QUICK_SPEED) else: player.brain.nav.chaseBall() if (transitions.shouldFindBall(player) or transitions.shouldSpinToBall(player)): return player.goLater('chase') if (transitions.shouldPrepareForKick(player) or player.brain.nav.isAtPosition()): player.inKickingState = True if player.shouldKickOff: if player.brain.ball.rel_y > 0: player.kick = kicks.LEFT_SHORT_STRAIGHT_KICK else: player.kick = kicks.RIGHT_SHORT_STRAIGHT_KICK player.shouldKickOff = False return player.goNow('positionForKick') else: return player.goNow('prepareForKick') else: return player.stay()
def positionPlaying(player): """ Game Playing positioning """ if player.firstFrame(): player.brain.nav.positionPlaybook() player.brain.tracker.repeatBasicPan() # TODO Landmarks if player.brain.ball.vis.on and player.brain.ball.distance < 100: player.brain.tracker.trackBall() else: player.brain.tracker.repeatBasicPan() # TODO Landmarks if player.brain.nav.isAtPosition(): player.brain.tracker.trackBall() if player.brain.play.isChaser() and transitions.shouldChaseBall(player): return player.goLater('chase') if transitions.shouldFindBallPosition(player): return player.goLater('findBall') if player.brain.locUncert > 75: # Find some goalposts (preferably close ones) and walk toward them. pass return player.stay()
def positionForKick(player): """ Get to the ball. Uses chaseBall to walk to the ball when its far away, and positionForKick once we get close. This allows Player to monitor Navigator's progress as it positions. """ if player.penaltyKicking and player.brain.ball.loc.inOppGoalBox(): return player.goNow('penaltyBallInOppGoalbox') if player.firstFrame(): player.brain.tracker.trackBall() player.inKickingState = False if player.counter % 10 is 0: player.brain.kickDecider.decideKick() player.brain.nav.kickPosition(player.brain.kickDecider.getKick()) # most of the time going to chase will kick back to here, lets us reset if transitions.shouldFindBallKick(player): player.inKickingState = False return player.goLater('chase') #if transitions.shouldKick(player): if transitions.ballInPosition(player) and (player.brain.nav.isStopped() or player.brain.nav.isAtPosition()): if transitions.shouldOrbit(player): return player.goNow('lookAround') else: return player.goNow('kickBallExecute') return player.stay()
def orbitBall(player): """ State to orbit the ball """ if player.firstFrame(): if hackKick.DEBUG_KICK_DECISION: print "Orbiting at angle: ",player.kick.h if player.kick.h == 0: return player.goNow('positionForKick') # Reset from pre-kick pan to straight, then track the ball. player.brain.tracker.lookStraightThenTrack() player.brain.nav.orbitAngle(player.orbitDistance, player.kick.h) elif player.brain.nav.isStopped(): player.shouldOrbit = False player.kick.h = 0 if player.kick == kicks.ORBIT_KICK_POSITION: return player.goNow('prepareForKick') else: player.kick = kicks.chooseAlignedKickFromKick(player, player.kick) return player.goNow('positionForKick') if (transitions.shouldFindBallKick(player) or transitions.shouldCancelOrbit(player)): player.inKickingState = False return player.goLater('chase') return player.stay()
def spinFindBall(player): """ State to spin to find the ball. If we find the ball, we move to align on it. If we don't find it, we walk to look for it """ if transitions.shouldChaseBall(player): player.stopWalking() player.brain.tracker.trackBall() return player.goNow('findBall') if player.firstFrame(): player.brain.tracker.stopHeadMoves() if player.brain.nav.isStopped() and player.brain.tracker.isStopped(): my = player.brain.my ball = player.brain.ball spinDir = my.spinDirToPoint(ball.loc) player.setWalk(0, 0, spinDir*constants.FIND_BALL_SPIN_SPEED) player.brain.tracker.trackBallSpin() if not player.brain.play.isRole(GOALIE): if transitions.shouldWalkFindBall(player): return player.goLater('walkFindBall') return player.stay()
def positionForKick(player): """ Get the ball in the sweet spot """ if transitions.shouldRedecideKick(player): return player.goLater('approachBall') ball = player.brain.ball positionForKick.kickPose = RelRobotLocation(ball.rel_x - player.kick.setupX, ball.rel_y - player.kick.setupY, 0) if player.firstFrame(): player.brain.tracker.lookStraightThenTrack() if player.kick == kicks.M_LEFT_SIDE or player.kick == kicks.M_RIGHT_SIDE: positionForKick.speed = Navigator.GRADUAL_SPEED else: positionForKick.speed = MIN_SPEED player.brain.nav.destinationWalkTo(positionForKick.kickPose, positionForKick.speed) elif player.brain.ball.vis.on: # don't update if we don't see the ball player.brain.nav.updateDestinationWalkDest(positionForKick.kickPose) player.ballBeforeKick = player.brain.ball if transitions.ballInPosition(player, positionForKick.kickPose): if player.motionKick: return player.goNow('executeMotionKick') else: player.brain.nav.stand() return player.goNow('executeKick') return player.stay()
def turnToBall(player): """ Rotate to align with the ball. When we get close, we will approach it """ ball = player.brain.ball if player.firstFrame(): player.hasAlignedOnce = False player.brain.tracker.trackBall() player.brain.CoA.setRobotGait(player.brain.motion) # Determine the speed to turn to the ball turnRate = MyMath.clip(ball.bearing*constants.BALL_SPIN_GAIN, -constants.BALL_SPIN_SPEED, constants.BALL_SPIN_SPEED) # Avoid spinning so slowly that we step in place if fabs(turnRate) < constants.MIN_BALL_SPIN_MAGNITUDE: turnRate = MyMath.sign(turnRate)*constants.MIN_BALL_SPIN_MAGNITUDE if ball.on: player.setSpeed(x=0,y=0,theta=turnRate) if transitions.shouldKick(player): return player.goNow('waitBeforeKick') elif transitions.shouldPositionForKick(player): return player.goNow('positionForKick') elif transitions.shouldApproachBall(player): return player.goLater('approachBall') elif transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') return player.stay()
def approachBall(player): if player.brain.nav.dodging: return player.stay() if player.firstFrame(): player.buffBoxFiltered = CountTransition(playOffTransitions.ballNotInBufferedBox, 0.8, 10) player.brain.tracker.trackBall() if player.shouldKickOff: if player.inKickOffPlay: return player.goNow('giveAndGo') else: return player.goNow('positionAndKickBall') elif player.penaltyKicking: return player.goNow('prepareForPenaltyKick') else: player.brain.nav.chaseBall(MAX_SPEED, fast = True) if (transitions.shouldPrepareForKick(player) or player.brain.nav.isAtPosition()): return player.goNow('positionAndKickBall') elif transitions.shouldDecelerate(player): player.brain.nav.chaseBall(MIN_SPEED, fast = True) else: player.brain.nav.chaseBall(MAX_SPEED, fast = True)
def spinFindBall(player): """ State to spin to find the ball. If we find the ball, we move to align on it. If we don't find it, we go to a garbage state """ if transitions.shouldApproachBall(player): return player.goNow('approachBall') if player.firstFrame(): #if ball.on #player.brain.tracker.trackBallSpin() #else: #tracker.findBall() my = player.brain.my ball = player.brain.ball spinDir = my.spinDirToPoint(ball) player.setWalk(0, 0, spinDir*constants.FIND_BALL_SPIN_SPEED) player.brain.tracker.trackBallSpin() if not player.brain.play.isRole(GOALIE): if transitions.shouldWalkToBallLocPos(player): return player.goLater('approachBall') return player.stay()
def approachBall(player): if player.firstFrame(): player.brain.tracker.trackBall() if player.shouldKickOff: player.brain.nav.chaseBall(Navigator.QUICK_SPEED, fast = True) else: player.brain.nav.chaseBall(fast = True) if (transitions.shouldFindBall(player)): print "DEBUG_SUIT: In 'approachBall', shouldFindBall is True. Switching to 'chase'." return player.goLater('chase') if (transitions.shouldPrepareForKick(player) or player.brain.nav.isAtPosition()): player.inKickingState = True if player.shouldKickOff: if player.brain.ball.rel_y > 0: player.kick = kicks.LEFT_STRAIGHT_KICK else: player.kick = kicks.RIGHT_STRAIGHT_KICK player.shouldKickOff = False return player.goNow('positionForKick') else: print "DEBUG_SUITE: In 'approachBall', either shouldPrepareForKick or nav.isAtPosition is True. Not a kickoff: switching to 'prepareForKick'." return player.goNow('prepareForKick') else: return player.stay()
def scanFindBall(player): """ State to move the head to find the ball. If we find the ball, we move to align on it. If we don't find it, we spin to keep looking """ if player.firstFrame(): player.stopWalking() player.brain.tracker.trackBall() if transitions.shouldApproachBall(player): return player.goNow('approachBall') # a time based check. may be a problem for goalie. if it's not good for him to # spin, he should prbly not be chaser anymore, so this wouldn't get reached if transitions.shouldSpinFindBall(player): return player.goNow('spinFindBall') ball = player.brain.ball if fabs(ball.bearing) < constants.SCAN_FIND_BEARING_THRESH: return player.stay() else: return player.goLater('spinFindBall') return player.stay()
def positionForKick(player): """ Get to the ball. Uses chaseBall to walk to the ball when its far away, and positionForKick once we get close. This allows Player to monitor Navigator's progress as it positions. """ if player.firstFrame(): player.brain.tracker.trackBall() player.inKickingState = True if player.counter % 10 is 0: player.brain.kickDecider.decideKick() player.brain.nav.kickPosition(player.brain.kickDecider.getKick()) # most of the time going to chase will kick back to here, lets us reset if transitions.shouldFindBallKick(player): player.inKickingState = False return player.goLater('chase') #if transitions.shouldKick(player): if transitions.ballInPosition(player): if transitions.shouldOrbit(player): print "Don't have a kick, orbitting" return player.goNow('orbitBall') else: return player.goNow('kickBallExecute') return player.stay()
def walkToWayPoint(player): if player.brain.nav.dodging: return player.stay() if player.firstFrame(): player.decider = KickDecider.KickDecider(player.brain) player.brain.tracker.trackBall() player.kick = player.decider.decidingStrategy() relH = player.decider.normalizeAngle(player.kick.setupH - player.brain.loc.h) ball = player.brain.ball if transitions.shouldDecelerate(player): speed = MIN_SPEED else: speed = MAX_SPEED if fabs(relH) <= constants.MAX_BEARING_DIFF: wayPoint = RobotLocation(ball.x - constants.WAYPOINT_DIST*cos(radians(player.kick.setupH)), ball.y - constants.WAYPOINT_DIST*sin(radians(player.kick.setupH)), player.brain.loc.h) player.brain.nav.goTo(wayPoint, Navigator.CLOSE_ENOUGH, speed, True, fast = True) if transitions.shouldSpinToKickHeading(player): return player.goNow('spinToKickHeading') else: player.brain.nav.chaseBall(speed, fast = True) if transitions.shouldPrepareForKick(player): return player.goLater('positionAndKickBall') return player.stay()
def positionForKick(player): """ Get the ball in the sweet spot """ if transitions.shouldRedecideKick(player): return player.goLater('approachBall') ball = player.brain.ball positionForKick.kickPose = RelRobotLocation( ball.rel_x - player.kick.setupX, ball.rel_y - player.kick.setupY, 0) if player.firstFrame(): player.brain.tracker.lookStraightThenTrack() if player.kick == kicks.M_LEFT_SIDE or player.kick == kicks.M_RIGHT_SIDE: positionForKick.speed = Navigator.GRADUAL_SPEED else: positionForKick.speed = MIN_SPEED player.brain.nav.destinationWalkTo(positionForKick.kickPose, positionForKick.speed) elif player.brain.ball.vis.on: # don't update if we don't see the ball player.brain.nav.updateDestinationWalkDest(positionForKick.kickPose) player.ballBeforeKick = player.brain.ball if transitions.ballInPosition(player, positionForKick.kickPose): if player.motionKick: return player.goNow('executeMotionKick') else: player.brain.nav.stand() return player.goNow('executeKick') return player.stay()
def spinToBallClose(player): """ If the ball is really close to us, but we aren't facing it yet, stop and spin toward it, then decide your kick. """ player.brain.tracker.trackBall() ball = player.brain.ball if (ball.relY > constants.SHOULD_STOP_Y or ball.relY < -1*constants.SHOULD_STOP_Y): spinDir = player.brain.my.spinDirToPoint(ball) player.setWalk(0, 0, spinDir*constants.BALL_SPIN_SPEED) else: if ball.dist > constants.SHOULD_START_DIST: player.brain.nav.chaseBall() else: player.stopWalking() return player.goNow('decideKick') if player.brain.tracker.activeLocOn: if transitions.shouldScanFindBallActiveLoc(player): return player.goLater('scanFindBall') elif transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') return player.stay()
def waitBeforeKick(player): """ Stop before we kick to make sure we want to kick """ player.inKickingState = True if player.firstFrame(): player.brain.CoA.setRobotGait(player.brain.motion) player.stopWalking() if not player.brain.nav.isStopped(): return player.stay() if transitions.shouldKick(player): return player.goLater('getKickInfo') elif transitions.shouldApproachForKick(player): player.brain.tracker.trackBall() player.inKickingState = False return player.goLater('approachBall') elif transitions.shouldScanFindBall(player): player.inKickingState = False player.brain.tracker.trackBall() return player.goLater('scanFindBall') elif transitions.shouldRepositionForKick(player): player.brain.tracker.trackBall() return player.goLater('positionForKick') # Just don't get stuck here! if player.counter > 50: return player.goNow('scanFindBall') return player.stay()
def positionForKick(player): """ Get the ball in the sweet spot """ if (transitions.shouldApproachBallAgain(player) or transitions.shouldRedecideKick(player)): player.inKickingState = False return player.goLater('chase') ball = player.brain.ball kick_pos = player.kick.getPosition() positionForKick.kickPose = RelRobotLocation(ball.rel_x - kick_pos[0], ball.rel_y - kick_pos[1], 0) #only enque the new goTo destination once if player.firstFrame(): # Safer when coming from orbit in 1 frame. Still works otherwise, too. player.brain.tracker.lookStraightThenTrack() player.brain.nav.goTo(positionForKick.kickPose, Navigator.PRECISELY, Navigator.GRADUAL_SPEED, False, Navigator.ADAPTIVE) else: player.brain.nav.updateDest(positionForKick.kickPose) if transitions.shouldFindBallKick(player) and player.counter > 15: player.inKickingState = False return player.goLater('chase') if (transitions.ballInPosition(player, positionForKick.kickPose) or player.brain.nav.isAtPosition()): player.brain.nav.stand() return player.goNow('kickBallExecute') return player.stay()
def orbitBall(player): """ State to orbit the ball """ if player.firstFrame(): if hackKick.DEBUG_KICK_DECISION: print "Orbiting at angle: ", player.kick.h if player.kick.h == 0: return player.goNow('positionForKick') # Reset from pre-kick pan to straight, then track the ball. player.brain.tracker.lookStraightThenTrack() player.brain.nav.orbitAngle(player.orbitDistance, player.kick.h) elif player.brain.nav.isStopped(): player.shouldOrbit = False player.kick.h = 0 if player.kick == kicks.ORBIT_KICK_POSITION: return player.goNow('prepareForKick') else: player.kick = kicks.chooseAlignedKickFromKick(player, player.kick) return player.goNow('positionForKick') if (transitions.shouldFindBallKick(player) or transitions.shouldCancelOrbit(player)): player.inKickingState = False return player.goLater('chase') return player.stay()
def spinFindBall(player): """ State to spin to find the ball. If we find the ball, we move to align on it. If we don't find it, we walk to look for it """ if transitions.shouldChaseBall(player): player.stopWalking() player.brain.tracker.trackBall() return player.goNow('findBall') if player.firstFrame(): player.brain.tracker.stopHeadMoves() if player.brain.nav.isStopped() and player.brain.tracker.isStopped(): my = player.brain.loc ball = Location(player.brain.ball.x, player.brain.ball.y) spinDir = my.spinDirToPoint(ball) player.setWalk(0, 0, spinDir * constants.FIND_BALL_SPIN_SPEED) player.brain.tracker.spinPan() if transitions.shouldWalkFindBall(player): return player.goLater('walkFindBall') return player.stay()
def approachBall(player): if player.brain.nav.dodging: return player.stay() if player.firstFrame(): player.buffBoxFiltered = CountTransition( playOffTransitions.ballNotInBufferedBox, 0.8, 10) player.brain.tracker.trackBall() if player.shouldKickOff: if player.inKickOffPlay: return player.goNow('giveAndGo') else: return player.goNow('positionAndKickBall') elif player.penaltyKicking: return player.goNow('prepareForPenaltyKick') else: player.brain.nav.chaseBall(MAX_SPEED, fast=True) if (transitions.shouldPrepareForKick(player) or player.brain.nav.isAtPosition()): return player.goNow('positionAndKickBall') elif transitions.shouldDecelerate(player): player.brain.nav.chaseBall(MIN_SPEED, fast=True) else: player.brain.nav.chaseBall(MAX_SPEED, fast=True)
def spinFindBall(player): """ State to spin to find the ball. If we find the ball, we move to align on it. If we don't find it, we walk to look for it """ if transitions.shouldChaseBall(player): player.stopWalking() player.brain.tracker.trackBall() return player.goLater('findBall') if player.firstFrame(): player.brain.tracker.stopHeadMoves() player.stopWalking() if player.brain.nav.isStopped() and player.brain.tracker.isStopped(): my = player.brain.loc ball = Location(player.brain.ball.x, player.brain.ball.y) spinDir = my.spinDirToPoint(ball) player.setWalk(0, 0, spinDir*constants.FIND_BALL_SPIN_SPEED) player.brain.tracker.spinPan() if ((player.brain.play.isChaser() and transitions.shouldWalkFindBall(player)) or (not player.brain.play.isChaser() and transitions.spunOnce(player))): return player.goLater('playbookPosition') return player.stay()
def turnToBall(player): """ Rotate to align with the ball. When we get close, we will approach it """ ball = player.brain.ball if player.firstFrame(): player.hasAlignedOnce = False player.brain.tracker.trackBall() player.brain.CoA.setRobotGait(player.brain.motion) # Determine the speed to turn to the ball turnRate = MyMath.clip(ball.bearing * constants.BALL_SPIN_GAIN, -constants.BALL_SPIN_SPEED, constants.BALL_SPIN_SPEED) # Avoid spinning so slowly that we step in place if fabs(turnRate) < constants.MIN_BALL_SPIN_MAGNITUDE: turnRate = MyMath.sign(turnRate) * constants.MIN_BALL_SPIN_MAGNITUDE if ball.on: player.setWalk(x=0, y=0, theta=turnRate) if transitions.shouldKick(player): return player.goNow('waitBeforeKick') elif transitions.shouldPositionForKick(player): return player.goNow('positionForKick') elif transitions.shouldApproachBall(player): return player.goLater('approachBall') elif transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') return player.stay()
def approachBall(player): if player.firstFrame(): player.brain.tracker.trackBall() if player.shouldKickOff: player.brain.nav.chaseBall(Navigator.QUICK_SPEED, fast = True) elif player.penaltyKicking: return player.goNow('prepareForPenaltyKick') else: player.brain.nav.chaseBall(fast = True) if transitions.shouldFindBall(player): return player.goLater('chase') if (transitions.shouldPrepareForKick(player) or player.brain.nav.isAtPosition()): if player.brain.nav.isAtPosition(): print "isAtPosition() is causing the bug!" else: print "shouldPrepareForKick() is causing the bug!" print player.brain.ball.distance print player.brain.ball.vis.distance player.inKickingState = True if player.shouldKickOff: if player.brain.ball.rel_y > 0: player.kick = kicks.LEFT_STRAIGHT_KICK else: player.kick = kicks.RIGHT_STRAIGHT_KICK return player.goNow('positionForKick') else: return player.goNow('prepareForKick') else: return player.stay()
def chaseAroundBox(player): if player.firstFrame(): player.shouldNotChaseAroundBox = 0 player.brain.CoA.setRobotGait(player.brain.motion) if transitions.shouldKick(player): return player.goNow('waitBeforeKick') elif transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') elif transitions.shouldAvoidObstacle( player): # Has potential to go into box! return player.goLater('avoidObstacle') if not transitions.shouldChaseAroundBox(player): player.shouldChaseAroundBox += 1 else: player.shouldChaseAroundBox = 0 if player.shouldChaseAroundBox > constants.STOP_CHASING_AROUND_BOX: return player.goLater('chase') ball = player.brain.ball my = player.brain.my if my.x > NogginConstants.MY_GOALBOX_RIGHT_X: # go to corner nearest ball if ball.y > NogginConstants.MY_GOALBOX_TOP_Y: player.brain.nav.goTo( RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_TOP_Y + constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING)) if ball.y < NogginConstants.MY_GOALBOX_BOTTOM_Y: player.brain.nav.goTo( RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_BOTTOM_Y - constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING)) if my.x < NogginConstants.MY_GOALBOX_RIGHT_X: # go to corner nearest ball if my.y > NogginConstants.MY_GOALBOX_TOP_Y: player.brain.nav.goTo( RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_TOP_Y + constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING)) if my.y < NogginConstants.MY_GOALBOX_BOTTOM_Y: player.brain.nav.goTo( RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_BOTTOM_Y - constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING)) return player.stay()
def chaseAroundBox(player): if player.firstFrame(): player.shouldNotChaseAroundBox = 0 player.brain.CoA.setRobotGait(player.brain.motion) if transitions.shouldKick(player): return player.goNow('waitBeforeKick') elif transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') elif transitions.shouldAvoidObstacle(player): # Has potential to go into box! return player.goLater('avoidObstacle') if not transitions.shouldChaseAroundBox(player): player.shouldChaseAroundBox += 1 else : player.shouldChaseAroundBox = 0 if player.shouldChaseAroundBox > constants.STOP_CHASING_AROUND_BOX: return player.goLater('chase') ball = player.brain.ball my = player.brain.my if my.x > NogginConstants.MY_GOALBOX_RIGHT_X: # go to corner nearest ball if ball.y > NogginConstants.MY_GOALBOX_TOP_Y: player.brain.nav.goTo( RobotLocation(NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_TOP_Y + constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING )) if ball.y < NogginConstants.MY_GOALBOX_BOTTOM_Y: player.brain.nav.goTo( RobotLocation(NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_BOTTOM_Y - constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING )) if my.x < NogginConstants.MY_GOALBOX_RIGHT_X: # go to corner nearest ball if my.y > NogginConstants.MY_GOALBOX_TOP_Y: player.brain.nav.goTo( RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_TOP_Y + constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING )) if my.y < NogginConstants.MY_GOALBOX_BOTTOM_Y: player.brain.nav.goTo( RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X + constants.GOALBOX_OFFSET, NogginConstants.MY_GOALBOX_BOTTOM_Y - constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING )) return player.stay()
def chase(player): """ Method to determine which chase state should be used. We dump the robot into this state when we our switching from something else. """ player.isChasing = True player.hasAlignedOnce = False if player.brain.play.isRole(GOALIE): if transitions.shouldScanFindBall(player): return player.goNow('scanFindBall') elif transitions.shouldApproachBall(player): return player.goNow('approachBall') elif transitions.shouldKick(player): return player.goNow('waitBeforeKick') elif transitions.shouldTurnToBall_ApproachBall(player): return player.goNow('turnToBall') else: return player.goNow('scanFindBall') if transitions.shouldScanFindBall(player): return player.goNow('scanFindBall') elif transitions.shouldApproachBallWithLoc(player): return player.goNow('approachBallWithLoc') elif transitions.shouldApproachBall(player): return player.goNow('approachBall') elif transitions.shouldKick(player): return player.goNow('waitBeforeKick') elif transitions.shouldTurnToBall_ApproachBall(player): return player.goNow('turnToBall') else: return player.goNow('scanFindBall')
def chase(player): """ Method to determine which chase state should be used. We dump the robot into this state when we our switching from something else. """ player.isChasing = True player.hasAlignedOnce = False if player.brain.playbook.role == pbc.GOALIE: if transitions.shouldScanFindBall(player): return player.goNow('scanFindBall') elif transitions.shouldApproachBall(player): return player.goNow('approachBall') elif transitions.shouldKick(player): return player.goNow('waitBeforeKick') elif transitions.shouldTurnToBall_ApproachBall(player): return player.goNow('turnToBall') else: return player.goNow('scanFindBall') if transitions.shouldScanFindBall(player): return player.goNow('scanFindBall') elif transitions.shouldApproachBallWithLoc(player): return player.goNow('approachBallWithLoc') elif transitions.shouldApproachBall(player): return player.goNow('approachBall') elif transitions.shouldKick(player): return player.goNow('waitBeforeKick') elif transitions.shouldTurnToBall_ApproachBall(player): return player.goNow('turnToBall') else: return player.goNow('scanFindBall')
def positionForPenaltyKick(player): """ We're getting ready for a penalty kick """ if player.firstFrame(): positionForPenaltyKick.position = True player.inKickingState = True positionForPenaltyKick.yes = False if player.brain.ball.rel_y > 0: player.kick = kicks.LEFT_STRAIGHT_KICK print "Kicking with left" else: player.kick = kicks.RIGHT_STRAIGHT_KICK print "Kicking with right" if (transitions.shouldApproachBallAgain(player) or transitions.shouldRedecideKick(player)): player.inKickingState = False print "Going Back to Chase" return player.goLater('chase') ball = player.brain.ball kick_pos = player.kick.getPosition() positionForPenaltyKick.kickPose = RelRobotLocation(ball.rel_x - kick_pos[0], ball.rel_y - kick_pos[1], 0) #So we stand and wait for two seconds before actually positioning if player.stateTime < 2: return player.stay() elif positionForPenaltyKick.position: player.ballBeforeApproach = player.brain.ball player.brain.tracker.lookStraightThenTrack() positionForPenaltyKick.position = True player.brain.nav.goTo(positionForPenaltyKick.kickPose, Navigator.PRECISELY, Navigator.CAREFUL_SPEED, False, Navigator.ADAPTIVE) positionForPenaltyKick.position = False else: player.brain.nav.updateDest(positionForPenaltyKick.kickPose) if (transitions.ballInPosition(player, positionForPenaltyKick.kickPose) or player.brain.nav.isAtPosition()): positionForPenaltyKick.yes = True #return player.stay() player.brain.nav.stand() return player.goNow('kickBallExecute') if positionForPenaltyKick.yes: print "ball relX: ", ball.rel_x print "ball relY: ", ball.rel_y return player.stay()
def goalieChase(player): """ TODO: make goalie more aggressive (different transitions?) """ if transitions.shouldScanFindBall(player): return player.goNow('scanFindBall') elif transitions.shouldApproachBall(player): return player.goNow('approachBall') elif transitions.shouldKick(player): return player.goNow('waitBeforeKick') else: return player.goNow('scanFindBall')
def positionForKick(player): """ State to align on the ball once we are near it """ if player.firstFrame(): kick = player.brain.kickDecider.kickInfo.getKick() player.brain.kickDecider.currentKick = kick if kick is None: player.angleToOrbit = player.brain.kickDecider.kickInfo.orbitAngle return player.goLater('orbitBall') player.brain.kickDecider.kickInfo = \ KickInformation.KickInformation(player) player.brain.nav.kickPosition(kick) player.inKickingState = True player.ballTooFar = 0 player.brain.tracker.trackBall() # something has gone wrong, maybe the ball was moved? if (player.brain.ball.dist > PFK_BALL_CLOSE_ENOUGH or player.brain.ball.framesOff > PFK_BALL_VISION_FRAMES): player.ballTooFar += 1 if player.ballTooFar > BUFFER_FRAMES_THRESHOLD: return player.goNow('chase') else: player.ballTooFar = 0 # Leave this state if necessary if transitions.shouldKick(player): return player.goNow('kickBallExecute') if player.brain.tracker.activeLocOn: if transitions.shouldScanFindBallActiveLoc(player): player.inKickingState = False return player.goLater('scanFindBall') else: if transitions.shouldScanFindBall(player): player.inKickingState = False return player.goLater('scanFindBall') if transitions.shouldApproachFromPositionForKick(player): player.inKickingState = False return player.goLater('approachBall') if not player.brain.play.isRole(GOALIE): if transitions.shouldDribble(player): return player.goNow('dribble') return player.stay()
def penaltyKickShortDribble(player): if player.firstFrame(): player.penaltyMadeFirstKick = True if transitions.shouldStopPenaltyKickDribbling(player): if transitions.shouldKick(player): return player.goNow('waitBeforeKick') elif transitions.shouldPositionForKick(player): return player.goNow('positionForKick') elif transitions.shouldApproachBall(player): return player.goNow('approachBall') return ChaseBallStates.approachBallWalk(player)
def positionForPenaltyKick(player): """ We're getting ready for a penalty kick """ if player.firstFrame(): positionForPenaltyKick.position = True player.inKickingState = True positionForPenaltyKick.yes = False if player.brain.ball.rel_y > 0: player.kick = kicks.LEFT_STRAIGHT_KICK print "Kicking with left" else: player.kick = kicks.RIGHT_STRAIGHT_KICK print "Kicking with right" if (transitions.shouldApproachBallAgain(player) or transitions.shouldRedecideKick(player)): player.inKickingState = False print "Going Back to Chase" return player.goLater('chase') ball = player.brain.ball kick_pos = player.kick.getPosition() positionForPenaltyKick.kickPose = RelRobotLocation( ball.rel_x - kick_pos[0], ball.rel_y - kick_pos[1], 0) #So we stand and wait for two seconds before actually positioning if player.stateTime < 2: return player.stay() elif positionForPenaltyKick.position: player.ballBeforeApproach = player.brain.ball player.brain.tracker.lookStraightThenTrack() positionForPenaltyKick.position = True player.brain.nav.goTo(positionForPenaltyKick.kickPose, Navigator.PRECISELY, Navigator.CAREFUL_SPEED, False, Navigator.ADAPTIVE) positionForPenaltyKick.position = False else: player.brain.nav.updateDest(positionForPenaltyKick.kickPose) if (transitions.ballInPosition(player, positionForPenaltyKick.kickPose) or player.brain.nav.isAtPosition()): positionForPenaltyKick.yes = True #return player.stay() player.brain.nav.stand() return player.goNow('kickBallExecute') if positionForPenaltyKick.yes: print "ball relX: ", ball.rel_x print "ball relY: ", ball.rel_y return player.stay()
def positionForKick(player): """ State to align on the ball once we are near it """ if player.firstFrame(): player.brain.CoA.setRobotSlowGait(player.brain.motion) ball = player.brain.ball player.inKickingState = True # Leave this state if necessary if transitions.shouldKick(player): player.brain.CoA.setRobotGait(player.brain.motion) return player.goNow('waitBeforeKick') elif transitions.shouldScanFindBall(player): player.inKickingState = False player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('scanFindBall') elif transitions.shouldTurnToBallFromPositionForKick(player): player.inKickingState = False player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('turnToBall') elif transitions.shouldApproachFromPositionForKick(player): player.inKickingState = False player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('approachBall') # Determine approach speed targetY = ball.relY sY = MyMath.clip(targetY * constants.PFK_Y_GAIN, constants.PFK_MIN_Y_SPEED, constants.PFK_MAX_Y_SPEED) sY = max(constants.PFK_MIN_Y_MAGNITUDE,sY) * MyMath.sign(sY) if transitions.shouldApproachForKick(player): targetX = (ball.relX - (constants.BALL_KICK_LEFT_X_CLOSE + constants.BALL_KICK_LEFT_X_FAR) / 2.0) sX = MyMath.clip(ball.relX * constants.PFK_X_GAIN, constants.PFK_MIN_X_SPEED, constants.PFK_MAX_X_SPEED) else: sX = 0.0 if ball.on: player.setSpeed(sX,sY,0) return player.stay()
def scanFindBall(player): """ State to move the head to find the ball. If we find the ball, we mppove to align on it. If we don't find it, we spin to keep looking """ player.brain.tracker.trackBall() if transitions.shouldChaseBall(player): return player.goNow('findBall') # a time based check. if transitions.shouldSpinFindBall(player): return player.goLater('spinFindBall') return player.stay()
def orbitBall(player): """ State to orbit the ball """ if player.firstFrame(): player.brain.nav.orbitAngle(player.angleToOrbit) player.brain.tracker.trackBall() if transitions.shouldScanFindBall(player): return player.goLater('scanFindBall') if transitions.shouldChaseFromPositionForKick(player): return player.goLater('chase') elif player.brain.nav.isStopped(): return player.goLater('chase') return player.stay()
def walkToBallLocPos(player): player.brain.tracker.trackBall() if transitions.shouldApproachBallWithLoc(player): player.brain.tracker.trackBall() return player.goLater("approachBallWithLoc") elif transitions.shouldTurnToBall_FoundBall(player): return player.goLater("turnToBall") ball = player.brain.ball destH = MyMath.getTargetHeading(player.brain.my, ball.x, ball.y) dest = (ball.x, ball.y, destH) nav = player.brain.nav if player.firstFrame() or nav.destX != dest[0] or nav.destY != dest[1] or nav.destH != dest[2]: nav.goTo(dest) return player.stay()
def omniPositionForKick(player): if player.firstFrame(): player.brain.tracker.trackBall() player.inKickingState = False # decide kick in util method # only enque once (for obstacle avoidance) player.brain.nav.goTo(getKickPosition(player), Navigator.CLOSE_ENOUGH, Navigator.FULL_SPEED, Navigator.ADAPTIVE) else: # update kicking position player.brain.nav.updateDest(getKickPosition(player)) # Did we lose the ball? if transitions.shouldFindBall(player): return player.goLater('gaurd') # At position? position = getKickPosition(player) if (0 < position.relX < constants.BALL_X_OFFSET and position.relY < constants.BALL_Y_OFFSET and position.relH < constants.GOOD_ENOUGH_H): print "kicking!" # KICK IT!!!$@%&!! player.brain.nav.stop() player.executeMove(SweetMoves.LEFT_BIG_KICK) #check this @! else: print "orbiting!" # ORBIT return player.stay()
def orbitBeforeKick(player): """ State for circling the ball when we're facing our goal. """ brain = player.brain my = brain.my if player.firstFrame(): player.orbitStartH = my.h brain.CoA.setRobotGait(brain.motion) brain.tracker.trackBall() shotPoint = KickingHelpers.getShotCloseAimPoint(player) bearingToGoal = my.getRelativeBearing(shotPoint) spinDir = -MyMath.sign(bearingToGoal) player.brain.nav.orbitAngle(spinDir * 90) if not player.brain.tracker.activeLocOn and \ transitions.shouldScanFindBall(player): player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('scanFindBall') elif brain.ball.dist > constants.STOP_ORBIT_BALL_DIST: return player.goLater('chase') if player.brain.nav.isStopped() and not player.firstFrame(): return player.goLater('positionForKick') return player.stay()
def kickBallStraightShort(player): if player.brain.ball.on: player.kickDecider.ballForeWhichFoot() elif ChaseBallTransitions.shouldScanFindBall(player): player.inKickingState = False return player.goLater('scanFindBall') else : return player.stay() player.brain.tracker.trackBall() ballForeFoot = player.kickDecider.ballForeFoot if ballForeFoot == constants.LEFT_FOOT: player.chosenKick = SweetMoves.SHORT_QUICK_LEFT_KICK return player.goNow('kickBallExecute') elif ballForeFoot == constants.RIGHT_FOOT: player.chosenKick = SweetMoves.SHORT_QUICK_RIGHT_KICK return player.goNow('kickBallExecute') elif ballForeFoot == constants.MID_RIGHT: player.chosenKick = SweetMoves.SHORT_QUICK_RIGHT_KICK return player.goNow('stepForRightFootKick') elif ballForeFoot == constants.MID_LEFT: player.chosenKick = SweetMoves.SHORT_QUICK_LEFT_KICK return player.goNow('stepForLeftFootKick') else : # INCORRECT_POS return player.goLater('positionForKick')
def alignForSideKick(player): if player.firstFrame(): player.brain.CoA.setRobotSlowGait(player.brain.motion) player.brain.tracker.trackBall() ball = player.brain.ball if ball.on and player.brain.nav.isStopped(): player.kickDecider.ballForeWhichFoot() ballForeFoot = player.kickDecider.ballForeFoot if ballForeFoot == constants.MID_LEFT or \ ballForeFoot == constants.MID_RIGHT: player.stopWalking() player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('kickBallExecute') elif ballForeFoot == constants.INCORRECT_POS: player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('positionForKick') targetY = ball.relY sY = MyMath.sign(targetY) * constants.SIDE_STEP_MAX_SPEED player.setSteps(0, sY, 0, constants.NUM_ALIGN_KICK_STEPS) if ChaseBallTransitions.shouldScanFindBall(player): player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('scanFindBall') return player.stay()
def afterKick(player): """ State to follow up after a kick. Currently exits after one frame. """ # trick the robot into standing up instead of leaning to the side if player.firstFrame(): player.hasAlignedOnce = False player.standup() if player.penaltyKicking: return player.goLater('penaltyKickRelocalize') return player.stay() player.brain.tracker.trackBall() if player.brain.ball.on: player.inKickingState = False player.brain.nav.justKicked = False return player.goLater('chase') if transitions.shouldScanFindBall(player): player.inKickingState = False player.brain.nav.justKicked = False return player.goLater('scanFindBall') return player.stay()
def orbitBeforeKick(player): """ State for circling the ball when we're facing our goal. """ brain = player.brain my = brain.my if player.firstFrame(): player.orbitStartH = my.h brain.CoA.setRobotGait(brain.motion) brain.tracker.trackBall() shotPoint = KickingHelpers.getShotCloseAimPoint(player) bearingToGoal = MyMath.getRelativeBearing(my.x, my.y, my.h, shotPoint[0], shotPoint[1] ) spinDir = -MyMath.sign(bearingToGoal) player.brain.nav.orbitAngle(spinDir * 90) if not player.brain.tracker.activeLocOn and \ transitions.shouldScanFindBall(player): player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('scanFindBall') elif brain.ball.dist > constants.STOP_ORBIT_BALL_DIST: return player.goLater('chase') if player.brain.nav.isStopped() and not player.firstFrame(): return player.goLater('positionForKick') return player.stay()
def goalieRunChecks(player): setRelX(player) setRelY(player) if not player.isChasing: if shouldChaseLoc(player): player.shouldChaseCounter+=1 if DEBUG: print "should chase: ", player.shouldChaseCounter if player.shouldChaseCounter >= goalCon.START_CHASE_BUFFER: player.shouldChaseCounter = 0 if player.currentState == 'squatted' or\ player.currentState == 'squat': return 'chasePrepare' player.isChasing = True return 'chase' else: player.shouldChaseCounter = 0 elif player.isChasing and\ not chaseTran.shouldntStopChasing(player): if shouldStopChaseLoc(player) : player.shouldChaseCounter+=1 if DEBUG: print "should stop chase: ", player.shouldChaseCounter if player.shouldChaseCounter >= goalCon.STOP_CHASE_BUFFER: player.shouldChaseCounter = 0 player.isChasing = False return 'goaliePosition' else: player.shouldChaseCounter = 0 return player.currentState
def stepForLeftFootKick(player): if player.firstFrame(): player.brain.CoA.setRobotSlowGait(player.brain.motion) player.brain.tracker.trackBall() ball = player.brain.ball if ball.on and player.brain.nav.isStopped(): player.kickDecider.ballForeWhichFoot() ballForeFoot = player.kickDecider.ballForeFoot if ballForeFoot == constants.LEFT_FOOT: player.stopWalking() player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('kickBallExecute') # switch foot! elif ballForeFoot == constants.RIGHT_FOOT: player.stopWalking() player.chosenKick = SweetMoves.RIGHT_FAR_KICK player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('kickBallExecute') elif ballForeFoot == constants.INCORRECT_POS: player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('positionForKick') targetY = ball.relY - constants.LEFT_FOOT_CENTER_Y sY = MyMath.sign(targetY) * constants.SIDE_STEP_MAX_SPEED player.setSteps(0, sY, 0, constants.NUM_ALIGN_KICK_STEPS) if ChaseBallTransitions.shouldScanFindBall(player): player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('scanFindBall') return player.stay()
def walkToWayPoint(player): if player.brain.nav.dodging: return player.stay() if player.firstFrame(): player.decider = KickDecider.KickDecider(player.brain) player.brain.tracker.trackBall() player.kick = player.decider.new2016KickStrategy() relH = player.decider.normalizeAngle(player.kick.setupH - player.brain.loc.h) ball = player.brain.ball # print "In walkToWayPoint" if transitions.shouldDecelerate(player): # print "I should decelerate" speed = speeds.SPEED_SIX else: speed = speeds.SPEED_EIGHT if fabs(relH) <= 50: #constants.MAX_BEARING_DIFF: wayPoint = RobotLocation( ball.x - constants.WAYPOINT_DIST * cos(radians(player.kick.setupH)), ball.y - constants.WAYPOINT_DIST * sin(radians(player.kick.setupH)), player.brain.loc.h) # print("Going to waypoint") player.brain.nav.goTo(wayPoint, Navigator.GENERAL_AREA, speed, True, fast=True) if transitions.shouldSpinToKickHeading(player): return player.goNow('spinToKickHeading') else: player.brain.nav.chaseBall(speed, fast=True) if transitions.shouldPrepareForKick(player): return player.goLater('dribble') return player.stay()
def positionForKick(player): """ State to align on the ball once we are near it """ if player.firstFrame(): player.brain.CoA.setRobotSlowGait(player.brain.motion) ball = player.brain.ball player.inKickingState = True # Leave this state if necessary if transitions.shouldKick(player): player.brain.CoA.setRobotGait(player.brain.motion) return player.goNow('waitBeforeKick') elif transitions.shouldScanFindBall(player): player.inKickingState = False player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('scanFindBall') elif transitions.shouldTurnToBallFromPositionForKick(player): player.inKickingState = False player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('turnToBall') elif transitions.shouldApproachFromPositionForKick(player): player.inKickingState = False player.brain.CoA.setRobotGait(player.brain.motion) return player.goLater('approachBall') # Determine approach speed targetY = ball.relY sY = MyMath.clip(targetY * constants.PFK_Y_GAIN, constants.PFK_MIN_Y_SPEED, constants.PFK_MAX_Y_SPEED) sY = max(constants.PFK_MIN_Y_MAGNITUDE, sY) * MyMath.sign(sY) if transitions.shouldApproachForKick(player): # targetX = (ball.relX - # (constants.BALL_KICK_LEFT_X_CLOSE + # constants.BALL_KICK_LEFT_X_FAR) / 2.0) sX = MyMath.clip(ball.relX * constants.PFK_X_GAIN, constants.PFK_MIN_X_SPEED, constants.PFK_MAX_X_SPEED) else: sX = 0.0 if ball.on: player.setWalk(sX, sY, 0) return player.stay()
def walkToBallLocPos(player): player.brain.tracker.trackBall() if transitions.shouldApproachBallWithLoc(player): player.brain.tracker.trackBall() return player.goLater('approachBallWithLoc') elif transitions.shouldTurnToBall_FoundBall(player): return player.goLater('turnToBall') ball = player.brain.ball destH = player.brain.my.getTargetHeading(ball) dest = RobotLocation(ball.x, ball.y, destH) nav = player.brain.nav if player.firstFrame() or \ nav.dest != dest: nav.goTo(dest) return player.stay()
def scanFindBall(player): """ State to move the head to find the ball. If we find the ball, we mppove to align on it. If we don't find it, we spin to keep looking """ player.brain.tracker.trackBallFixedPitch() if transitions.shouldChaseBall(player): return player.goNow('findBall') # a time based check. may be a problem for goalie. if it's not # good for him to spin, he should prbly not be chaser anymore, so # this wouldn't get reached if transitions.shouldSpinFindBall(player): return player.goLater('spinFindBall') 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 positionForKick(player): """ Get the ball in the sweet spot """ if transitions.shouldRedecideKick(player): return player.goLater('approachBall') ball = player.brain.ball positionForKick.kickPose = RelRobotLocation( ball.rel_x - player.kick.setupX, ball.rel_y - player.kick.setupY, 0) if player.firstFrame(): player.brain.tracker.lookStraightThenTrack() player.brain.nav.destinationWalkTo(positionForKick.kickPose, Navigator.MEDIUM_SPEED) positionForKick.slowDown = False elif player.brain.ball.vis.on: # don't update if we don't see the ball # slows down the walk when very close to the ball to stabalize motion kicking and to not walk over the ball if player.kick == kicks.M_LEFT_STRAIGHT or player.kick == kicks.M_RIGHT_STRAIGHT: if (not positionForKick.slowDown and player.brain.ball.distance < constants.SLOW_DOWN_TO_BALL_DIST): positionForKick.slowDown = True player.brain.nav.destinationWalkTo(positionForKick.kickPose, Navigator.GRADUAL_SPEED) elif (positionForKick.slowDown and player.brain.ball.distance >= constants.SLOW_DOWN_TO_BALL_DIST): positionForKick.slowDown = False player.brain.nav.destinationWalkTo(positionForKick.kickPose, Navigator.MEDIUM_SPEED) else: player.brain.nav.updateDestinationWalkDest( positionForKick.kickPose) else: player.brain.nav.updateDestinationWalkDest( positionForKick.kickPose) player.ballBeforeKick = player.brain.ball if transitions.ballInPosition(player, positionForKick.kickPose): if player.motionKick: return player.goNow('executeMotionKick') else: player.brain.nav.stand() return player.goNow('executeKick') return player.stay()
def spinToBall(player): if player.firstFrame(): player.brain.tracker.trackBallFixedPitch() player.brain.nav.stand() if transitions.shouldFindBall(player): return player.goLater('chase') if transitions.shouldStopSpinningToBall(player): return player.goNow('approachBall') else: spinDir = player.brain.my.spinDirToPoint(player.brain.ball.loc) if fabs(player.brain.ball.loc.bearing) > constants.CHANGE_SPEED_THRESH: speed = Navigator.GRADUAL_SPEED else: speed = Navigator.SLOW_SPEED player.setWalk(0,0,spinDir*speed) return player.stay()
def followPotentialField(player): """ This state is based on electric field potential vector paths. The ball is treated as an attractive force where on the side that will be kicked. The opposite side is treated as a repulsive force of smaller magnitude. """ if player.firstFrame(): player.brain.tracker.trackBall() ball = player.brain.ball heading = player.brain.loc.h relH = player.decider.normalizeAngle(player.kick.setupH - heading) if (transitions.shouldPositionForKick(player, ball, relH)): destinationX = player.kick.destinationX destinationY = player.kick.destinationY player.kick = kicks.chooseAlignedKickFromKick(player, player.kick) player.kick.destinationX = destinationX player.kick.destinationY = destinationY return player.goNow('positionForKick') else: attractorX = ball.rel_x - constants.ATTRACTOR_BALL_DIST * cos( radians(heading - player.kick.setupH)) attractorY = ball.rel_y - constants.ATTRACTOR_BALL_DIST * sin( -radians(heading - player.kick.setupH)) attractorDist = (attractorX**2 + attractorY**2)**.5 if attractorDist == 0: attractorDist = .00000000001 repulsorX = ball.rel_x - constants.REPULSOR_BALL_DIST * cos( radians(heading - player.kick.setupH)) repulsorY = ball.rel_y - constants.REPULSOR_BALL_DIST * sin( -radians(heading - player.kick.setupH)) repulsorDist = (repulsorX**2 + repulsorY**2)**.5 if repulsorDist == 0: repulsorDist = .00000000001 # super position of an attractive potential field and arepulsive one xComp = constants.ATTRACTOR_REPULSOR_RATIO * attractorX / attractorDist**3 - repulsorX / repulsorDist**3 yComp = constants.ATTRACTOR_REPULSOR_RATIO * attractorY / attractorDist**3 - repulsorY / repulsorDist**3 if xComp == 0 and yComp == 0: player.setWalk(0, 0, 0) else: normalizer = Navigator.FAST_SPEED / (xComp**2 + yComp**2)**.5 if ball.bearing_deg > constants.SHOULD_SPIN_TO_BALL_BEARING / 2: hComp = copysign(Navigator.GRADUAL_SPEED, ball.bearing_deg) else: hComp = copysign(Navigator.GRADUAL_SPEED, ball.bearing_deg) player.setWalk(normalizer * xComp, normalizer * yComp, hComp) return player.stay()
def dribble(player): """ Keep running at the ball, but dribble """ if player.firstFrame(): player.brain.CoA.setRobotDribbleGait(player.brain.motion) # if we should stop dribbling, see what else we should do if transitions.shouldStopDribbling(player): if transitions.shouldKick(player): return player.goNow('waitBeforeKick') elif transitions.shouldPositionForKick(player): return player.goNow('positionForKick') elif transitions.shouldApproachBall(player): return player.goNow('approachBall') return approachBallWalk(player)
def chase(player): """ Super State to determine what to do from various situations """ if transitions.shouldFindBall(player): return player.goNow('findBall') else: return player.goNow('spinToBall')
def walkToWayPoint(player): if player.brain.nav.dodging: return player.stay() if player.firstFrame(): player.decider = KickDecider.KickDecider(player.brain) player.brain.tracker.trackBall() player.kick = player.decider.decidingStrategy() relH = player.decider.normalizeAngle(player.kick.setupH - player.brain.loc.h) ball = player.brain.ball if transitions.shouldDecelerate(player): speed = MIN_SPEED else: speed = MAX_SPEED if fabs(relH) <= constants.MAX_BEARING_DIFF: wayPoint = RobotLocation( ball.x - constants.WAYPOINT_DIST * cos(radians(player.kick.setupH)), ball.y - constants.WAYPOINT_DIST * sin(radians(player.kick.setupH)), player.brain.loc.h) player.brain.nav.goTo(wayPoint, Navigator.CLOSE_ENOUGH, speed, True, fast=True) if transitions.shouldSpinToKickHeading(player): return player.goNow('spinToKickHeading') else: player.brain.nav.chaseBall(speed, fast=True) if transitions.shouldPrepareForKick(player): return player.goLater('positionAndKickBall') return player.stay()
def positionForKick(player): """ Get the ball in the sweet spot """ if (transitions.shouldApproachBallAgain(player) or transitions.shouldRedecideKick(player)): player.inKickingState = False return player.goLater('chase') if not player.shouldKickOff or DRIBBLE_ON_KICKOFF: if dr_trans.shouldDribble(player): return player.goNow('decideDribble') if player.corner_dribble: return player.goNow('executeDribble') ball = player.brain.ball kick_pos = player.kick.getPosition() positionForKick.kickPose = RelRobotLocation(ball.rel_x - kick_pos[0], ball.rel_y - kick_pos[1], 0) if player.firstFrame(): player.brain.tracker.lookStraightThenTrack() player.brain.nav.destinationWalkTo(positionForKick.kickPose, Navigator.SLOW_SPEED, True) elif player.brain.ball.vis.on: # don't update if we don't see the ball player.brain.nav.updateDestinationWalkDest(positionForKick.kickPose) if transitions.shouldFindBall(player): player.inKickingState = False return player.goLater('chase') player.ballBeforeKick = player.brain.ball if transitions.ballInPosition(player, positionForKick.kickPose): if player.motionKick: return player.goNow('motionKickExecute') else: player.brain.nav.stand() return player.goNow('kickBallExecute') return player.stay()