def spinToBall(player): """ State to spin to turn to the ball """ if player.firstFrame(): player.stopWalking() player.brain.tracker.trackBall() ball = player.brain.ball turnRate = MyMath.clip(ball.locBearing*ChaseConstants.BALL_SPIN_GAIN, -ChaseConstants.BALL_SPIN_SPEED, ChaseConstants.BALL_SPIN_SPEED) if transitions.atSpinBallDir(player): return player.goLater('atSpinBallPosition') elif transitions.shouldSpinFindBallPosition(player): return player.goLater('spinFindBallPosition') elif player.currentSpinDir != MyMath.sign(turnRate): player.stopWalking() player.currentSpinDir = MyMath.sign(turnRate) elif player.stoppedWalk and ball.on and player.brain.nav.isStopped(): player.setWalk(x=0,y=0,theta=turnRate) return player.stay()
def spinToBall(player): """ State to spin to turn to the ball """ if player.firstFrame(): player.stopWalking() player.brain.tracker.trackBall() ball = player.brain.ball turnRate = MyMath.clip(ball.locBearing * ChaseConstants.BALL_SPIN_GAIN, -ChaseConstants.BALL_SPIN_SPEED, ChaseConstants.BALL_SPIN_SPEED) if transitions.atSpinBallDir(player): return player.goLater('atSpinBallPosition') elif transitions.shouldSpinFindBallPosition(player): return player.goLater('spinFindBallPosition') elif player.currentSpinDir != MyMath.sign(turnRate): player.stopWalking() player.currentSpinDir = MyMath.sign(turnRate) elif player.stoppedWalk and ball.on and player.brain.nav.isStopped(): player.setWalk(x=0, y=0, theta=turnRate) return player.stay()
def spinFindBallPosition(player): """ Spin to find the ball if it is not being seen. """ if player.brain.nav.isStopped(): player.stoppedWalk = True if player.firstFrame() and player.stoppedWalk: player.setWalk(0, 0, ChaseConstants.FIND_BALL_SPIN_SPEED) player.brain.tracker.trackBall() if transitions.shouldTurnToBall_fromAtBallPosition(player): return player.goLater('spinToBall') if transitions.atSpinBallDir(player): return player.goLater('atSpinBallPosition') return player.stay()
def spinFindBallPosition(player): """ Spin to find the ball if it is not being seen. """ if player.brain.nav.isStopped(): player.stoppedWalk = True if player.firstFrame() and player.stoppedWalk: player.setSpeed(0, 0, ChaseConstants.FIND_BALL_SPIN_SPEED) player.brain.tracker.trackBall() if transitions.shouldTurnToBall_fromAtBallPosition(player): return player.goLater("spinToBall") if transitions.atSpinBallDir(player): return player.goLater("atSpinBallPosition") return player.stay()