def orbitBall(player): """ State to orbit the ball """ if player.brain.nav.dodging: return player.stay() # Calculate relative heading every frame relH = player.decider.normalizeAngle(player.kick.setupH - player.brain.loc.h) # Are we within the acceptable heading range? if (relH > -constants.ORBIT_GOOD_BEARING and relH < constants.ORBIT_GOOD_BEARING): print "STOPPED! Because relH is: ", relH #player.stopWalking() 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') if (transitions.orbitTooLong(player) or transitions.orbitBallTooFar(player)): #player.stopWalking() return player.goLater('approachBall') # Set our walk. Nav will make sure that we don't set duplicate speeds. if relH < 0: if relH < -20: player.setWalk(0, 0.7, -0.25) else: player.setWalk(0, 0.5, -0.15) elif relH > 0: if relH > 20: player.setWalk(0, -0.7, 0.25) else: player.setWalk(0, -0.5, 0.15) # DEBUGGING PRINT OUTS if constants.DEBUG_ORBIT and player.counter % 20 == 0: print "desiredHeading is: | ", player.kick.setupH print "player heading: | ", player.brain.loc.h print "orbit heading: | ", relH print "walk is: | (", player.brain.nav.getXSpeed( ), ",", player.brain.nav.getYSpeed(), ",", player.brain.nav.getHSpeed( ), ")" print "===============================" # X correction if (constants.ORBIT_BALL_DISTANCE + constants.ORBIT_DISTANCE_FAR < player.brain.ball.distance): # Too far away player.brain.nav.setXSpeed(.15) elif (constants.ORBIT_BALL_DISTANCE - constants.ORBIT_DISTANCE_CLOSE > player.brain.ball.distance): # Too close player.brain.nav.setXSpeed(-.15) elif (constants.ORBIT_BALL_DISTANCE + constants.ORBIT_DISTANCE_GOOD > player.brain.ball.distance and constants.ORBIT_BALL_DISTANCE - constants.ORBIT_DISTANCE_GOOD < player.brain.ball.distance): player.brain.nav.setXSpeed(0) # H correction if relH < 0: # Orbiting clockwise if player.brain.ball.rel_y > 2: player.brain.nav.setHSpeed(0) elif player.brain.ball.rel_y < -2: if relH < -20: player.brain.nav.setHSpeed(-0.35) else: player.brain.nav.setHSpeed(-0.2) else: if relH < -20: player.brain.nav.setHSpeed(-0.25) else: player.brain.nav.setHSpeed(-0.15) else: # Orbiting counter-clockwise if player.brain.ball.rel_y > 2: if relH > 20: player.brain.nav.setHSpeed(0.35) else: player.brain.nav.setHSpeed(0.2) elif player.brain.ball.rel_y < -2: player.brain.nav.setHSpeed(0) else: if relH > 20: player.brain.nav.setHSpeed(0.25) else: player.brain.nav.setHSpeed(0.15) return player.stay()
def orbitBall(player): """ State to orbit the ball """ # Calculate relative heading every frame relH = player.kick.h - player.brain.loc.h # Are we within the acceptable heading range? if (relH > -constants.ORBIT_GOOD_BEARING and relH < constants.ORBIT_GOOD_BEARING): print "STOPPED! Because relH is: ", relH player.stopWalking() player.kick = kicks.chooseAlignedKickFromKick(player, player.kick) return player.goNow('positionForKick') if (transitions.orbitTooLong(player) or transitions.orbitBallTooFar(player)): player.stopWalking() player.inKickingState = False return player.goLater('chase') # Set our walk. Nav will make sure that we don't set duplicate speeds. if relH < 0: if relH < -20: player.setWalk(0, 0.7, -0.25) else: player.setWalk(0, 0.5, -0.15) elif relH > 0: if relH > 20: player.setWalk(0, -0.7, 0.25) else: player.setWalk(0, -0.5, 0.15) # DEBUGGING PRINT OUTS if constants.DEBUG_ORBIT and player.counter%20 == 0: print "desiredHeading is: | ", player.kick.h print "player heading: | ", player.brain.loc.h print "orbit heading: | ", relH print "walk is: | (",player.brain.nav.getXSpeed(),",",player.brain.nav.getYSpeed(),",",player.brain.nav.getHSpeed(),")" print "===============================" # X correction if (constants.ORBIT_BALL_DISTANCE + constants.ORBIT_DISTANCE_FAR < player.brain.ball.distance): # Too far away player.brain.nav.setXSpeed(.15) elif (constants.ORBIT_BALL_DISTANCE - constants.ORBIT_DISTANCE_CLOSE > player.brain.ball.distance): # Too close player.brain.nav.setXSpeed(-.15) elif (constants.ORBIT_BALL_DISTANCE + constants.ORBIT_DISTANCE_GOOD > player.brain.ball.distance and constants.ORBIT_BALL_DISTANCE - constants.ORBIT_DISTANCE_GOOD < player.brain.ball.distance): player.brain.nav.setXSpeed(0) # H correction if relH < 0: # Orbiting clockwise if player.brain.ball.rel_y > 2: player.brain.nav.setHSpeed(0) elif player.brain.ball.rel_y < -2: if relH < -20: player.brain.nav.setHSpeed(-0.35) else: player.brain.nav.setHSpeed(-0.2) else: if relH < -20: player.brain.nav.setHSpeed(-0.25) else: player.brain.nav.setHSpeed(-0.15) else: # Orbiting counter-clockwise if player.brain.ball.rel_y > 2: if relH > 20: player.brain.nav.setHSpeed(0.35) else: player.brain.nav.setHSpeed(0.2) elif player.brain.ball.rel_y < -2: player.brain.nav.setHSpeed(0) else: if relH > 20: player.brain.nav.setHSpeed(0.25) else: player.brain.nav.setHSpeed(0.15) return player.stay()
def orbitBall(player): """ State to orbit the ball. Uses two PID controllers! """ if player.firstFrame(): orbitBall.xController.reset() orbitBall.hController.reset() if player.brain.nav.dodging: return player.stay() # Calculate relative heading every frame relH = player.decider.normalizeAngle(player.kick.setupH - player.brain.loc.h) # Check if within the acceptable heading range if (relH > -constants.ORBIT_GOOD_BEARING and relH < constants.ORBIT_GOOD_BEARING): print "STOPPED! RelH: ", relH destinationX = player.kick.destinationX destinationY = player.kick.destinationY player.kick = kicks.chooseAlignedKickFromKick(player, player.kick) player.kick.destinationX = destinationX player.kick.destinationY = destinationY player.setWalk(0, 0, 0) # return player.goLater('positionForKick') if transitions.shouldNotDribble(player): return player.goNow('positionForKick') return player.goNow('dribble') if (transitions.orbitTooLong(player) or transitions.orbitBallTooFar(player)): return player.goLater('approachBall') # Orbit in correct direction at constant speed ySpeed = min(constants.ORBIT_Y_SPEED, fabs(orbitBall.yController.correct(relH))) if relH > 0: ySpeed = -ySpeed ySpeed = ySpeed * 1.5 # Calculate corrections in x and h using PID controller xError = player.brain.ball.distance - constants.ORBIT_X hError = player.brain.ball.bearing xSpeedCorrect = orbitBall.xController.correct(xError) hSpeedCorrect = orbitBall.hController.correct(hError) hSpeedCorrect = hSpeedCorrect * 1.3 # Set walk vector player.setWalk(xSpeedCorrect, ySpeed, hSpeedCorrect) if constants.DEBUG_ORBIT: print "ORBIT DEBUG:" print xError print hError print xSpeedCorrect print hSpeedCorrect return player.stay()