Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
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()
Exemplo n.º 6
0
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.stat_rel_x - kick_pos[0],
                                                ball.stat_rel_y - kick_pos[1],
                                                0)

    if player.firstFrame():
        # Safer when coming from orbit in 1 frame. Still works otherwise, too.
        player.brain.tracker.lookStraightThenTrack()
        #only enque the new goTo destination once and update it afterwards
        player.brain.nav.goTo(positionForKick.kickPose,
                              Navigator.PRECISELY,
                              Navigator.SLOW_SPEED,
                              False,
                              Navigator.ADAPTIVE)
    else:
        player.brain.nav.updateDest(positionForKick.kickPose)

    if transitions.shouldFindBallKick(player):
        player.inKickingState = False
        return player.goLater('chase')

    if (transitions.ballInPosition(player, positionForKick.kickPose) or
        player.brain.nav.isAtPosition()):
        player.ballBeforeKick = player.brain.ball
        player.brain.nav.stand()
        return player.goNow('kickBallExecute')

    return player.stay()
Exemplo n.º 7
0
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')

    ballLoc = player.brain.ball.loc
    kick_pos = player.kick.getPosition()
    positionForKick.kickPose = RelRobotLocation(ballLoc.relX - kick_pos[0] - 3,
                                                ballLoc.relY - kick_pos[1],
                                                0)

    if player.firstFrame():
        player.brain.tracker.trackBall()
        player.inKickingState = False

    #only enque the new goTo destination once
    if player.firstFrame():    
        player.brain.nav.goTo(positionForKick.kickPose, 
                              Navigator.CLOSE_ENOUGH,
                              Navigator.CAREFUL_SPEED,
                              Navigator.ADAPTIVE)
    else:
        player.brain.nav.updateDest(positionForKick.kickPose)
        

    # most of the time going to chase will kick back to here, lets us reset
    if transitions.shouldFindBallKick(player) and player.counter > 15:
        player.inKickingState = False
        return player.goNow('findBall')

    #if transitions.shouldKick(player):
    if transitions.ballInPosition(player, positionForKick.kickPose) or player.brain.nav.isAtPosition():
#        if transitions.shouldOrbit(player):
#            return player.goNow('lookAround')
#        else:
        player.brain.nav.stand()
        return player.goLater('kickBallExecute')

    return player.stay()
Exemplo n.º 8
0
def positionForKick(player):
    """
    Get the ball in the sweet spot
    """
    if (transitions.shouldApproachBallAgain(player) or
        transitions.shouldRedecideKick(player)):
        print "DEBUG_SUITE: In 'positionForKick', either shouldApproachBallAgain or shouldRedecideKick. Switching to 'chase'."
        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()
        #TODO: try getting rid of ADAPTIVE here, if ball estimates are good,
        #we don't need to lower the speed/shuffle to the ball
        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:
        print "DEBUG_SUITE: In 'positionForKick', both shouldFindBallKick and counter >15. Switching to 'chase'."
        player.inKickingState = False
        return player.goLater('chase')

    if (transitions.ballInPosition(player, positionForKick.kickPose) or
        player.brain.nav.isAtPosition()):
        print "DEBUG_SUITE: In 'positionForKick', either ballInPosition or nav.isAtPosition. Switching to 'kickBallExecute'."
        player.brain.nav.stand()
        return player.goNow('kickBallExecute')

    return player.stay()
Exemplo n.º 9
0
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()
Exemplo n.º 10
0
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")

        elif player.kick.h < 0:
            # set y vel at 50% speed
            print "Turn to left, move right"
            player.brain.nav.walk(0, -0.7, 0.25)

        elif player.kick.h > 0:
            # set y vel at 50% speed in opposite direction
            print "Turn to right, move left"
            player.brain.nav.walk(0, 0.7, -0.25)

    elif player.brain.nav.isStopped():
        player.shouldOrbit = False
        player.kick.h = 0
        player.kick = kicks.chooseAlignedKickFromKick(player, player.kick)
        return player.goNow("positionForKick")

    # all of this is basically the same as in shoot() in hackKickInformation
    goalCenter = Location(nogginConstants.FIELD_WHITE_RIGHT_SIDELINE_X, nogginConstants.CENTER_FIELD_Y)
    ballLocation = Location(player.brain.ball.x, player.brain.ball.y)
    headingBallToGoalCenter = ballLocation.headingTo(goalCenter)
    bearingForKick = headingBallToGoalCenter - player.brain.loc.h

    # the kick was chosen before we came into orbitBall()
    if player.kick.isStraightKick():
        orbitBall.desiredHeading = 0 - bearingForKick
    elif player.kick == kicks.RIGHT_SIDE_KICK:
        orbitBall.desiredHeading = 70 - bearingForKick
    elif player.kick == kicks.LEFT_SIDE_KICK:
        orbitBall.desiredHeading = -70 - bearingForKick
    elif player.kick.isBackKick():
        if bearingForKick < -125:
            orbitBall.desiredHeading = -180 - bearingForKick
        else:
            orbitBall.desiredHeading = 180 - bearingForKick

    # #debugging
    # if player.counter%20 == 0:
    #     print "desiredHeading is:  | ", orbitBall.desiredHeading
    #     print "ball to goal center:| ", headingBallToGoalCenter
    #     print "player heading:     | ", player.brain.loc.h
    #     print "bearing for kick:   | ", bearingForKick
    #     print "walk is:            |  (",player.brain.nav.getXSpeed(),",",player.brain.nav.getYSpeed(),",",player.brain.nav.getHSpeed(),")"
    #     print "=====================++++++++++"

    # our in-house heading checker is of the opinion that we're pointed in the right direction
    if orbitBall.desiredHeading > -10 and orbitBall.desiredHeading < 10:
        player.stopWalking()
        print "Done orbiting, going to positionForKick"
        player.shouldOrbit = False
        player.kick.h = 0
        player.kick = kicks.chooseAlignedKickFromKick(player, player.kick)
        return player.goNow("positionForKick")

    if player.stateTime > 8:
        print "In state orbitBall for too long, switching to chase"
        player.shouldOrbit = False
        player.stopWalking()
        player.inKickingState = False
        return player.goLater("chase")

    # These next three if statements might need some fine tuning
    # ATM that doesn't appear to be the case
    if constants.ORBIT_BALL_DISTANCE < player.brain.ball.distance - 7:
        # We're too far away
        player.brain.nav.setXSpeed(0.15)

    if constants.ORBIT_BALL_DISTANCE > player.brain.ball.distance + 1:
        # We're too close
        player.brain.nav.setXSpeed(-0.15)

    if (
        constants.ORBIT_BALL_DISTANCE > player.brain.ball.distance - 1
        and constants.ORBIT_BALL_DISTANCE < player.brain.ball.distance + 1
    ):
        # print "We're at a good distance"
        player.brain.nav.setXSpeed(0)

    if transitions.shouldFindBallKick(player) or transitions.shouldCancelOrbit(player):
        player.inKickingState = False
        return player.goLater("chase")

    if player.kick.h > 0:  # Orbiting clockwise
        if player.brain.ball.rel_y > 2:
            player.brain.nav.setHSpeed(0)
            # print "turn clockwise SLOWER"
        elif player.brain.ball.rel_y < 2:
            player.brain.nav.setHSpeed(-0.35)
            # print "turn clockwise FASTER"
        else:
            player.brain.nav.setHSpeed(-0.25)
            # print "turn clockwise NORMAL"
    else:  # Orbiting counter-clockwise
        if player.brain.ball.rel_y > 2:
            player.brain.nav.setHSpeed(0.35)
            # print "turn counterclockwise FASTER"
        elif player.brain.ball.rel_y < 2:
            player.brain.nav.setHSpeed(0)
            # print "turn counterclockwise SLOWER"
        else:
            player.brain.nav.setHSpeed(0.25)
            # print "turn clockwise NORMAL"

    return player.stay()
Exemplo n.º 11
0
def orbitBall(player):
    """
    State to orbit the ball
    """
    if player.firstFrame():
        orbitBall.counter = 0
        if hackKick.DEBUG_KICK_DECISION:
            print "Orbiting at angle: ", player.kick.h

        if player.kick.h == 0:
            print "DEBUG_SUITE: In 'orbitBall', orbit is zero. Switching to 'positionForKick'."
            return player.goNow("positionForKick")

        print "DEBUG_SUITE: In 'orbitBall', orbiting at non-zero angle."
        # Reset from pre-kick pan to straight, then track the ball.
        player.brain.tracker.lookStraightThenTrack()

        if player.kick.h > 0:
            # set y vel at 50% speed
            print "Turn to right"
            player.brain.nav.walk(0, 0.5, -0.15)

        if player.kick.h < 0:
            # set y vel at 50% speed in opposite direction
            print "Turn to left"
            player.brain.nav.walk(0, -0.5, 0.15)

    elif player.brain.nav.isStopped():
        player.shouldOrbit = False
        player.kick.h = 0
        if player.kick == kicks.ORBIT_KICK_POSITION:
            print "DEBUG_SUITE: In 'orbitBall', finished with orbit kick. Switching to 'prepareForKick'."
            return player.goNow("prepareForKick")
        else:
            print "DEBUG_SUITE: In 'orbitBall', finished with orbit. Switching to 'positionForKick'."
            player.kick = kicks.chooseAlignedKickFromKick(player, player.kick)
            return player.goNow("positionForKick")

    # Used to update kick.h so we can *ideally* determine how long we've been orbiting
    prepareForKick.hackKick.shoot()

    # debugging
    if orbitBall.counter % 25 == 0:
        print "h is: ", player.kick.h
        print "stateTime is: ", player.stateTime

    # hackKick.shoot() is of the opinion that we're pointed in the right direction
    if player.kick.h > -5 and player.kick.h < 5:
        print "I'm not orbiting anymore"
        player.shouldOrbit = False
        player.kick.h = 0
        player.kick = kicks.chooseAlignedKickFromKick(player, player.kick)
        return player.goNow("positionForKick")

    if player.stateTime > 5:
        print "In state orbitBall for too long, switching to chase"
        player.shouldOrbit = False
        return player.goLater("chase")

    # These next three if statements might need some fine tuning
    # ATM that doesn't appear to be the case
    if player.orbitDistance < player.brain.ball.distance - 1:
        # We're too far away
        player.brain.nav.setXSpeed(0.15)

    if player.orbitDistance > player.brain.ball.distance + 1:
        # We're too close
        player.brain.nav.setXSpeed(-0.15)

    if player.orbitDistance > player.brain.ball.distance - 1 and player.orbitDistance < player.brain.ball.distance + 1:
        # print "We're at a good distance"
        player.brain.nav.setXSpeed(0)

    if transitions.shouldFindBallKick(player) or transitions.shouldCancelOrbit(player):
        print "DEBUG_SUITE: In 'orbitBall', either shouldFindBall or shouldCancelOrbit. Switching to 'chase'."
        player.inKickingState = False
        return player.goLater("chase")

    # Keeps track of the number of frames in orbitBall
    orbitBall.counter = orbitBall.counter + 1
    return player.stay()