Ejemplo n.º 1
0
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')
Ejemplo n.º 2
0
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')
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
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')
Ejemplo n.º 5
0
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()
Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
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()
Ejemplo n.º 8
0
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()
Ejemplo n.º 9
0
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()
Ejemplo n.º 10
0
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()
Ejemplo n.º 11
0
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()
Ejemplo n.º 12
0
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()
Ejemplo n.º 13
0
def decideKick(player):

    if ChaseBallTransitions.shouldScanFindBall(player):
        player.inKickingState = False
        return player.goLater('scanFindBall')

    # Get references to the collected data
    myLeftPostBearing =  player.kickDecider.myLeftPostBearing
    myRightPostBearing = player.kickDecider.myRightPostBearing
    oppLeftPostBearing = player.kickDecider.oppLeftPostBearing
    oppRightPostBearing = player.kickDecider.oppRightPostBearing

    player.printf(player.kickDecider)

    if player.penaltyKicking:
        return player.goNow('penaltyKickBall')

    player.kickObjective = helpers.getKickObjective(player)

    if player.kickObjective == constants.OBJECTIVE_CLEAR:
        return player.goNow('clearBall')
    elif player.kickObjective == constants.OBJECTIVE_SHOOT_FAR or \
            player.kickObjective == constants.OBJECTIVE_SHOOT_CLOSE:
        return player.goNow('shootBall')
    elif player.kickObjective == constants.OBJECTIVE_KICKOFF:
        player.hasKickedOffKick = True
        player.bigKick = False
        return player.goNow('kickBallStraight')
    else :
        return player.goNow('clearBall')
Ejemplo n.º 14
0
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()
Ejemplo n.º 15
0
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()
Ejemplo n.º 16
0
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()
Ejemplo n.º 17
0
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()
Ejemplo n.º 18
0
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')
Ejemplo n.º 19
0
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()
Ejemplo n.º 20
0
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()
Ejemplo n.º 21
0
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()
Ejemplo n.º 22
0
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()
Ejemplo n.º 23
0
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()
Ejemplo n.º 24
0
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()
Ejemplo n.º 25
0
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()
Ejemplo n.º 26
0
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()
Ejemplo n.º 27
0
def goalieChase(player):
    """
    TODO: make goalie more aggressive (different transitions?)
    """
    # Check in order of importance
    if transitions.shouldScanFindBall(player):
        return player.goNow('scanFindBall')
    elif transitions.shouldSpinToBallClose(player):
        return player.goNow('spinToBallClose')
    elif transitions.shouldStopBeforeKick(player):
        return player.goNow('stopBeforeKick')
    elif transitions.shouldPositionForKick(player):
        return player.goNow('decideKick')
    elif transitions.shouldApproachBall(player):
        return player.goNow('approachBall')
    else:
        return player.goNow('scanFindBall')
Ejemplo n.º 28
0
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()
Ejemplo n.º 29
0
def chase(player):
    """
    Method to determine which chase state should be used.
    We dump the robot into this state when we are switching from something else.
    """
    player.isChasing = True
    player.hasAlignedOnce = False

    if player.brain.play.isRole(GOALIE):
        return player.goNow('goalieChase')

    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')
Ejemplo n.º 30
0
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.inKickingState = True

        if transitions.shouldKickNow(player):
            return player.goLater('kickBallExecute')

        player.brain.nav.kickPosition(kick)

    player.brain.tracker.trackBall()

    # Leave this state if necessary
    if transitions.shouldStopAndKick(player):
        return player.goLater('preKickStop')
    if player.brain.tracker.activeLocOn:
        if transitions.shouldScanFindBallActiveLoc(player):
            player.inKickingState = False
            return player.goLater('scanFindBall')
    elif transitions.shouldScanFindBall(player):
        player.inKickingState = False
        return player.goLater('scanFindBall')
    if transitions.shouldChaseFromPositionForKick(player):
        player.inKickingState = False
        return player.goLater('chase')
    if not player.brain.play.isRole(GOALIE):
        if transitions.shouldDribble(player):
            return player.goLater('dribble')

    if player.brain.nav.isStopped():
        kick = player.brain.kickDecider.kickInfo.getKick()
        player.brain.nav.kickPosition(kick)

    return player.stay()
Ejemplo n.º 31
0
def dribble(player):
    """
    Keep running at the ball, but dribble
    """
    if player.firstFrame():
        player.brain.nav.dribble()

    if transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')
    # if we should stop dribbling, see what else we should do
    if transitions.shouldStopDribbling(player):
        # may not be appropriate due to turned out feet...
        if transitions.shouldStopBeforeKick(player):
            return player.goLater('stopBeforeKick')
        if transitions.shouldPositionForKick(player):
            return player.goLater('decideKick')
        elif transitions.shouldChaseBall(player):
            return player.goLater('chase')

    return player.stay()
Ejemplo n.º 32
0
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)
    ball = player.brain.ball
    my = player.brain.my
    if player.brain.nav.isStopped():
        if ball.dist >= 10:
            if ball.y > my.y + 7:
                player.brain.nav.walk(0, 10, 0)
            elif ball.y < my.y - 7:
                player.brain.nav.walk(0, -10, 0)

    if not goalTran.dangerousBall(player):
        return player.goLater('chase')
    if transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')

    return player.stay()
Ejemplo n.º 33
0
def chase(player):
    """
    Super State to determine what to do from various situations
    """
    player.isChasing = True
    player.hasAlignedOnce = False

    if player.brain.play.isRole(GOALIE):
        return player.goNow('goalieChase')

    # Check in order of importance
    if transitions.shouldScanFindBall(player):
        return player.goNow('scanFindBall')
    elif transitions.shouldStopBeforeKick(player):
        return player.goNow('stopBeforeKick')
    elif transitions.shouldPositionForKick(player):
        return player.goNow('decideKick')
    elif transitions.shouldApproachBall(player):
        return player.goNow('approachBall')
    else:
        return player.goNow('scanFindBall')
Ejemplo n.º 34
0
def approachBall(player):
    """
    Once we are alligned with the ball, approach it
    """
    if player.firstFrame():
        player.hasAlignedOnce = False
        player.brain.tracker.trackBall()
        player.brain.CoA.setRobotGait(player.brain.motion)

    #if player.brain.ball.locDist > constants.APPROACH_ACTIVE_LOC_DIST:
    if transitions.shouldActiveLoc(player):
        player.brain.tracker.activeLoc()
    else:
        player.brain.tracker.trackBall()


    if player.penaltyKicking and \
            player.ballInOppGoalBox():
        return player.goNow('penaltyBallInOppGoalbox')

    # Switch to other states if we should
    if player.brain.play.isRole(GOALIE):
        if transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldTurnToBall_ApproachBall(player):
            return player.goLater('turnToBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            return player.goLater('scanFindBall')
    else:
        if transitions.shouldDribble(player):
            return player.goNow('dribble')
        elif transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')

    return approachBallWalk(player)
Ejemplo n.º 35
0
def approachBall(player):
    """
    Once we are alligned with the ball, approach it
    """
    if player.firstFrame():
        player.hasAlignedOnce = False
        player.brain.tracker.trackBall()
        player.brain.CoA.setRobotGait(player.brain.motion)

    #if player.brain.ball.locDist > constants.APPROACH_ACTIVE_LOC_DIST:
    if transitions.shouldActiveLoc(player):
        player.brain.tracker.activeLoc()
    else :
        player.brain.tracker.trackBall()


    if player.penaltyKicking and \
            player.ballInOppGoalBox():
        return player.goNow('penaltyBallInOppGoalbox')

    # Switch to other states if we should
    if player.brain.playbook.role == pbc.GOALIE:
        if transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldTurnToBall_ApproachBall(player):
            return player.goLater('turnToBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            return player.goLater('scanFindBall')
    else:
        if transitions.shouldDribble(player):
            return player.goNow('dribble')
        elif transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')

    return approachBallWalk(player)
Ejemplo n.º 36
0
def spinToKick(player):
    """
    If the ball is behind the tip of our foot, but outside it, spin
    """
    player.brain.tracker.trackBall()
    ball = player.brain.ball

    if (ball.relY > constants.SHOULD_SPIN_TO_KICK_Y or
        ball.relY < -1*constants.SHOULD_SPIN_TO_KICK_Y):
        spinDir = player.brain.my.spinDirToPoint(ball)
        player.setWalk(0,0,spinDir*constants.BALL_SPIN_SPEED)
    else:
        if ball.dist > constants.SHOULD_SPIN_TO_KICK_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()
Ejemplo n.º 37
0
def goalieChase(player):
    """
    TODO: make goalie more aggressive (different transitions?)
    """
    # Check in order of importance

    #tells the goalie what state its in
    if player.firstFrame():
        player.isChasing = True
        player.isPositioning = False
        player.isSaving = False

    if transitions.shouldScanFindBall(player):
        return player.goNow('scanFindBall')
    elif transitions.shouldSpinToBallClose(player):
        return player.goNow('spinToBallClose')
    elif transitions.shouldStopBeforeKick(player):
        return player.goNow('stopBeforeKick')
    elif transitions.shouldPositionForKick(player):
        return player.goNow('decideKick')
    elif transitions.shouldApproachBall(player):
        return player.goNow('approachBall')
    else:
        return player.goNow('scanFindBall')
Ejemplo n.º 38
0
def decideKick(player):

    if ChaseBallTransitions.shouldScanFindBall(player):
        player.inKickingState = False
        return player.goLater('scanFindBall')

    player.printf(player.kickDecider)

    if player.penaltyKicking:
        return player.goNow('penaltyKickBall')

    player.kickObjective = helpers.getKickObjective(player)

    if player.kickObjective == constants.OBJECTIVE_CLEAR:
        return player.goNow('clearBall')
    elif player.kickObjective == constants.OBJECTIVE_SHOOT_FAR or \
            player.kickObjective == constants.OBJECTIVE_SHOOT_CLOSE:
        return player.goNow('shootBall')
    elif player.kickObjective == constants.OBJECTIVE_KICKOFF:
        player.hasKickedOffKick = True
        player.bigKick = False
        return player.goNow('kickBallStraight')
    else :
        return player.goNow('clearBall')
Ejemplo n.º 39
0
def approachBallWithLoc(player):
    if player.firstFrame():
        player.brain.CoA.setRobotGait(player.brain.motion)
        player.hasAlignedOnce = False

    nav = player.brain.nav
    my = player.brain.my
    if player.brain.play.isRole(GOALIE):
        if transitions.shouldKick(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKickFromApproachLoc(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('positionForKick')
        elif my.locScoreFramesBad > constants.APPROACH_NO_LOC_THRESH:
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('approachBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('scanFindBall')
    else:
        if transitions.shouldKick(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKickFromApproachLoc(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('positionForKick')
        elif transitions.shouldNotGoInBox(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('ballInMyBox')
        elif transitions.shouldChaseAroundBox(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('chaseAroundBox')
        elif transitions.shouldAvoidObstacleDuringApproachBall(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('avoidObstacle')
        elif my.locScoreFramesBad > constants.APPROACH_NO_LOC_THRESH:
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('approachBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('scanFindBall')
        elif player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBallActiveLoc(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('scanFindBall')

    #if player.brain.ball.locDist > constants.APPROACH_ACTIVE_LOC_DIST:
    if transitions.shouldActiveLoc(player):
        player.brain.tracker.activeLoc()
    else:
        player.brain.tracker.trackBall()

    dest = player.getApproachPosition()
    useOmni = my.dist(dest) <= \
        constants.APPROACH_OMNI_DIST
    changedOmni = False

    if useOmni != nav.movingOmni():
        player.changeOmniGoToCounter += 1
    else:
        player.changeOmniGoToCounter = 0
    if player.changeOmniGoToCounter > PositionConstants.CHANGE_OMNI_THRESH:
        changedOmni = True

    if player.firstFrame() or \
           nav.dest != dest or \
           changedOmni:
        if not useOmni:
            player.brain.CoA.setRobotGait(player.brain.motion)
            nav.goTo(dest)
        else:
            player.brain.CoA.setRobotSlowGait(player.brain.motion)
            nav.omniGoTo(dest)

    return player.stay()
Ejemplo n.º 40
0
def approachBallWithLoc(player):
    if player.firstFrame():
        player.brain.CoA.setRobotGait(player.brain.motion)
        player.hasAlignedOnce = False

    nav = player.brain.nav
    my = player.brain.my
    if player.brain.playbook.role == pbc.GOALIE:
        if transitions.shouldKick(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKickFromApproachLoc(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('positionForKick')
        elif my.locScoreFramesBad > constants.APPROACH_NO_LOC_THRESH:
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('approachBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('scanFindBall')
    else:
        if transitions.shouldKick(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKickFromApproachLoc(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('positionForKick')
        elif transitions.shouldNotGoInBox(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('ballInMyBox')
        elif transitions.shouldChaseAroundBox(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('chaseAroundBox')
        elif transitions.shouldAvoidObstacleDuringApproachBall(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('avoidObstacle')
        elif my.locScoreFramesBad > constants.APPROACH_NO_LOC_THRESH:
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('approachBall')
        elif not player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBall(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('scanFindBall')
        elif player.brain.tracker.activeLocOn and \
                transitions.shouldScanFindBallActiveLoc(player):
            player.brain.CoA.setRobotGait(player.brain.motion)
            return player.goLater('scanFindBall')

    #if player.brain.ball.locDist > constants.APPROACH_ACTIVE_LOC_DIST:
    if transitions.shouldActiveLoc(player):
        player.brain.tracker.activeLoc()
    else :
        player.brain.tracker.trackBall()

    dest = player.getApproachPosition()
    useOmni = MyMath.dist(my.x, my.y, dest[0], dest[1]) <= \
        constants.APPROACH_OMNI_DIST
    changedOmni = False

    if useOmni != nav.movingOmni:
        player.changeOmniGoToCounter += 1
    else :
        player.changeOmniGoToCounter = 0
    if player.changeOmniGoToCounter > PositionConstants.CHANGE_OMNI_THRESH:
        changedOmni = True

    if player.firstFrame() or \
            nav.destX != dest[0] or \
            nav.destY != dest[1] or \
            nav.destH != dest[2] or \
            changedOmni:
        if not useOmni:
            player.brain.CoA.setRobotGait(player.brain.motion)
            nav.goTo(dest)
        else:
            player.brain.CoA.setRobotSlowGait(player.brain.motion)
            nav.omniGoTo(dest)

    return player.stay()