Beispiel #1
0
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()
Beispiel #2
0
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()
Beispiel #3
0
def atSpinBallPosition(player):
    """
    Spun to the ball heading, spin again
    """
    if player.firstFrame():
        player.stopWalking()
        player.brain.tracker.activeLoc()

    if transitions.shouldTurnToBall_fromAtBallPosition(player):
        return player.goLater('spinToBall')
    elif transitions.shouldSpinFindBallPosition(player):
        return player.goLater('spinFindBallPosition')

    return player.stay()
Beispiel #4
0
def atSpinBallPosition(player):
    """
    Spun to the ball heading, spin again
    """
    if player.firstFrame():
        player.stopWalking()
        player.brain.tracker.activeLoc()

    if transitions.shouldTurnToBall_fromAtBallPosition(player):
        return player.goLater('spinToBall')
    elif transitions.shouldSpinFindBallPosition(player):
        return player.goLater('spinFindBallPosition')

    return player.stay()
Beispiel #5
0
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()
Beispiel #6
0
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()
Beispiel #7
0
def playbookPosition(player):
    """
    Have the robot navigate to the position reported to it from playbook
    """
    brain = player.brain
    nav = brain.nav
    my = brain.my
    ball = brain.ball
    gcState = brain.gameController.currentState

    if player.firstFrame():
        if gcState == 'gameReady':
            brain.tracker.locPans()
        else:
            brain.tracker.activeLoc()

    # determine final goal heading
    if ball.on:
        destHeading = my.h + ball.bearing
    elif ball.framesOff < 30:
        destHeading = my.h + ball.locBearing
    else:
        destHeading = NogginConstants.OPP_GOAL_HEADING

    # turn playbook value into location for navigator
    position = player.brain.play.getPosition()
    position = RobotLocation(position[0], position[1], destHeading)

    if gcState == 'gameReady':
        position.h = NogginConstants.OPP_GOAL_HEADING

    nav.positionPlaybook(position)

    if brain.my.locScore == NogginConstants.BAD_LOC:
        player.shouldRelocalizeCounter += 1

        # only need to check after we increment counter
        if player.shouldRelocalizeCounter >=\
               constants.SHOULD_RELOC_FRAME_THRESH:
            return player.goLater('relocalize')

    else:
        player.shouldRelocalizeCounter = 0

    if transitions.shouldAvoidObstacle(player):
        return player.goNow('avoidObstacle')

    # we're at the point, let's switch to another state
    if nav.isStopped() and player.counter > 0:
        return player.goLater('atPosition')

    return player.stay()
Beispiel #8
0
def playbookPosition(player):
    """
    Have the robot navigate to the position reported to it from playbook
    """
    brain = player.brain
    nav = brain.nav
    my = brain.my
    ball = brain.ball
    gcState = brain.gameController.currentState

    if player.firstFrame():
        if gcState == 'gameReady':
            brain.tracker.locPans()
        else:
            brain.tracker.activeLoc()

    # determine final goal heading
    if ball.on:
        destHeading = my.h + ball.bearing
    elif ball.framesOff < 30:
        destHeading = my.h + ball.locBearing
    else:
        destHeading = NogginConstants.OPP_GOAL_HEADING

    # turn playbook value into location for navigator
    position = player.brain.play.getPosition()
    position = RobotLocation(position[0], position[1], destHeading)

    if gcState == 'gameReady':
        position.h = NogginConstants.OPP_GOAL_HEADING

    nav.positionPlaybook(position)

    if brain.my.locScore == NogginConstants.BAD_LOC:
        player.shouldRelocalizeCounter += 1

        # only need to check after we increment counter
        if player.shouldRelocalizeCounter >=\
               constants.SHOULD_RELOC_FRAME_THRESH:
            return player.goLater('relocalize')

    else:
        player.shouldRelocalizeCounter = 0

    if transitions.shouldAvoidObstacle(player):
        return player.goNow('avoidObstacle')

    # we're at the point, let's switch to another state
    if nav.isStopped() and player.counter > 0:
        return player.goLater('atPosition')

    return player.stay()
Beispiel #9
0
def playbookPosition(player):
    """
    Have the robot navigate to the position reported to it from playbook
    """
    brain = player.brain
    nav = brain.nav
    gcState = brain.gameController.currentState

    if player.firstFrame():
        nav.positionPlaybook()

        if gcState == 'gameReady':
            brain.tracker.locPans()
        else:
            brain.tracker.activeLoc()

    if PosTran.leavingTheField(player):
        return player.goLater('spinToField')

    return player.stay()
Beispiel #10
0
def atPosition(player):
    """
    State for when we're at the position
    """
    nav = player.brain.nav
    position = player.brain.play.getPosition()
    position = Location(position[0], position[1])
    if player.firstFrame():
        player.stopWalking()
        player.notAtPositionCounter = 0

    # buffer switching back to playbook position
    if transitions.shouldReposition(nav.dest, position):
        player.notAtPositionCounter += 1

        if player.notAtPositionCounter >=\
               constants.NOT_AT_POSITION_FRAMES_THRESH:
            return player.goLater('playbookPosition')
    else:
        player.notAtPositionCounter = 0

    return player.stay()
Beispiel #11
0
def atPosition(player):
    """
    State for when we're at the position
    """
    nav = player.brain.nav
    position = player.brain.play.getPosition()
    position = Location(position[0], position[1])
    if player.firstFrame():
        player.stopWalking()
        player.notAtPositionCounter = 0

    # buffer switching back to playbook position
    if transitions.shouldReposition(nav.dest, position):
        player.notAtPositionCounter += 1

        if player.notAtPositionCounter >=\
               constants.NOT_AT_POSITION_FRAMES_THRESH:
            return player.goLater('playbookPosition')
    else:
        player.notAtPositionCounter = 0

    return player.stay()
Beispiel #12
0
def goalieIsLost(player):
    """
    Goalie is facing off field
    """
    return PosTran.leavingTheField(player)
def goalieIsLost(player):

    return PosTran.leavingTheField(player)
Beispiel #14
0
def playbookPosition(player):
    """
    Have the robot navigate to the position reported to it from playbook
    """
    brain = player.brain
    position = brain.playbook.position
    nav = brain.nav
    my = brain.my
    ball = brain.ball

    if player.firstFrame():
        player.changeOmniGoToCounter = 0
        if brain.gameController.currentState == 'gameReady':
            brain.tracker.locPans()
        else :
            brain.tracker.activeLoc()

    # Get a bearing to the ball
    if brain.gameController.currentState == 'gameReady':
        destHeading = NogginConstants.OPP_GOAL_HEADING
    elif ball.on:
        destHeading = my.h + ball.bearing
    elif ball.framesOff < 3:
        destHeading = my.h + ball.locBearing
    else:
        destHeading = NogginConstants.OPP_GOAL_HEADING

    distToPoint = MyMath.dist(my.x, my.y, position[0], position[1])
    position = (position[0], position[1], destHeading)

    if brain.gameController.currentState == 'gameReady':
        useOmniDist = constants.OMNI_POSITION_READY_DIST
    else:
        useOmniDist = constants.OMNI_POSITION_DIST

    useOmni = distToPoint <= useOmniDist

    changedOmni = False

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

    # Send a goto if we have changed destinations or are just starting
    if (player.firstFrame() or
        abs(nav.destX - position[0]) > constants.GOTO_DEST_EPSILON or
        abs(nav.destY - position[1]) > constants.GOTO_DEST_EPSILON or
        changedOmni):

        if brain.my.locScore == NogginConstants.BAD_LOC:
            player.shouldRelocalizeCounter += 1
        else:
            player.shouldRelocalizeCounter = 0
        if player.shouldRelocalizeCounter > constants.SHOULD_RELOC_FRAME_THRESH:
            return player.goLater('relocalize')

        # Attempt to go to the point while looking at the ball
        if (not useOmni or
            (player.brain.playbook.role == PBConstants.DEFENDER and
             player.brain.ball.x < player.brain.my.x)):
            nav.goTo(position)
        else:
            nav.omniGoTo(position)

    if transitions.shouldAvoidObstacle(player):
        return player.goNow('avoidObstacle')

    # we're at the point, let's switch to another state
    if nav.isStopped() and player.counter > 0:
        return player.goLater('atPosition')

    return player.stay()