Exemplo n.º 1
0
def dribble(player):
    if transitions.shouldNotDribble(player):
        if player.lastDiffState == 'orbitBall':
            return player.goNow('approachBall')
        return player.goNow('orbitBall')
    ball = player.brain.ball
    relH = player.decider.normalizeAngle(player.brain.loc.h)
    if ball.distance < constants.LINE_UP_X and not (relH > -constants.ORBIT_GOOD_BEARING and
        relH < constants.ORBIT_GOOD_BEARING):
        player.setWalk(0, 0, 0)
        return player.goLater('orbitBall')

    if player.brain.ball.vis == True:
        if transitions.inGoalBox(player):
            player.brain.nav.walk(0.8, 0, 0)
        else:
            player.brain.nav.goTo(Location(ball.x, ball.y), Navigator.GENERAL_AREA, speeds.SPEED_SIX)
    else:
        player.brain.nav.walk(0.6, 0, 0)
    return player.stay()
Exemplo n.º 2
0
def dribble(player):
    if transitions.shouldNotDribble(player):
        if player.lastDiffState == 'orbitBall':
            return player.goNow('approachBall')
        return player.goNow('orbitBall')
    ball = player.brain.ball
    relH = player.decider.normalizeAngle(player.brain.loc.h)
    if ball.distance < constants.LINE_UP_X and not (
            relH > -constants.ORBIT_GOOD_BEARING
            and relH < constants.ORBIT_GOOD_BEARING):
        player.setWalk(0, 0, 0)
        return player.goLater('orbitBall')

    if player.brain.ball.vis == True:
        if transitions.inGoalBox(player):
            player.brain.nav.walk(0.8, 0, 0)
        else:
            player.brain.nav.goTo(Location(ball.x, ball.y),
                                  Navigator.GENERAL_AREA, speeds.SPEED_SIX)
    else:
        player.brain.nav.walk(0.6, 0, 0)
    return player.stay()
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
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()