Exemplo 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')
Exemplo 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')
Exemplo n.º 3
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()
Exemplo n.º 4
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()
Exemplo n.º 5
0
def walkToBallLocPos(player):
    player.brain.tracker.trackBall()
    if transitions.shouldApproachBallWithLoc(player):
        player.brain.tracker.trackBall()
        return player.goLater("approachBallWithLoc")
    elif transitions.shouldTurnToBall_FoundBall(player):
        return player.goLater("turnToBall")

    ball = player.brain.ball
    destH = MyMath.getTargetHeading(player.brain.my, ball.x, ball.y)
    dest = (ball.x, ball.y, destH)

    nav = player.brain.nav
    if player.firstFrame() or nav.destX != dest[0] or nav.destY != dest[1] or nav.destH != dest[2]:
        nav.goTo(dest)
    return player.stay()
Exemplo n.º 6
0
def walkToBallLocPos(player):
    player.brain.tracker.trackBall()
    if transitions.shouldApproachBallWithLoc(player):
        player.brain.tracker.trackBall()
        return player.goLater('approachBallWithLoc')
    elif transitions.shouldTurnToBall_FoundBall(player):
        return player.goLater('turnToBall')

    ball = player.brain.ball
    destH = player.brain.my.getTargetHeading(ball)
    dest = RobotLocation(ball.x, ball.y, destH)

    nav = player.brain.nav
    if player.firstFrame() or \
            nav.dest != dest:
        nav.goTo(dest)
    return player.stay()
Exemplo n.º 7
0
def walkToBallLocPos(player):
    player.brain.tracker.trackBall()
    if transitions.shouldApproachBallWithLoc(player):
        player.brain.tracker.trackBall()
        return player.goLater('approachBallWithLoc')
    elif transitions.shouldTurnToBall_FoundBall(player):
        return player.goLater('turnToBall')

    ball = player.brain.ball
    destH = player.brain.my.getTargetHeading(ball)
    dest = RobotLocation(ball.x, ball.y, destH)

    nav = player.brain.nav
    if player.firstFrame() or \
            nav.dest != dest:
        nav.goTo(dest)
    return player.stay()
Exemplo n.º 8
0
def spinFindBall(player):
    """
    State to spin to find the ball. If we find the ball, we
    move to align on it. If we don't find it, we go to a garbage state
    """

    if player.brain.playbook.role == pbc.GOALIE:
        if transitions.shouldApproachBall(player):
            player.brain.tracker.trackBall()
            return player.goLater('approachBall')
        elif transitions.shouldTurnToBall_FoundBall(player):
            return player.goLater('turnToBall')
    else:
        if transitions.shouldApproachBallWithLoc(player):
            player.brain.tracker.trackBall()
            return player.goLater('approachBallWithLoc')
        elif transitions.shouldApproachBall(player):
            player.brain.tracker.trackBall()
            return player.goLater('approachBall')
        elif transitions.shouldTurnToBall_FoundBall(player):
            return player.goLater('turnToBall')
        elif transitions.shouldWalkToBallLocPos(player):
            return player.goLater('walkToBallLocPos')
    if player.firstFrame():
        player.brain.tracker.trackBall()

        if player.justKicked:
            spinDir = player.getSpinDirAfterKick()
        else:
            my = player.brain.my
            ball = player.brain.ball
            spinDir = MyMath.getSpinDir(my.h,
                                        my.h + ball.locBearing)

        player.setSpeed(0, 0, spinDir*constants.FIND_BALL_SPIN_SPEED)

    return player.stay()
Exemplo n.º 9
0
def scanFindBall(player):
    """
    State to move the head to find the ball. If we find the ball, we
    move to align on it. If we don't find it, we spin to keep looking
    """
    if player.firstFrame():
        player.stopWalking()
        player.brain.tracker.trackBall()

    if player.brain.play.isRole(GOALIE):
        if transitions.shouldTurnToBall_FoundBall(player):
            return player.goLater("turnToBall")
        elif transitions.shouldSpinFindBall(player):
            return player.goLater("spinFindBall")
    else:
        if transitions.shouldApproachBallWithLoc(player):
            player.brain.tracker.trackBall()
            return player.goLater("approachBallWithLoc")
        elif transitions.shouldSpinFindBall(player):
            return player.goLater("spinFindBall")
        elif transitions.shouldTurnToBall_FoundBall(player):
            return player.goLater("turnToBall")
        elif transitions.shouldSpinFindBall(player):
            return player.goLater("spinFindBall")

    if (
        abs(player.brain.ball.locBearing) < constants.SCAN_FIND_BEARING_THRESH
        or player.brain.ball.locDist < constants.SCAN_FIND_DIST_THRESH
        and not player.brain.play.isRole(GOALIE)
    ):
        return player.stay()
    elif player.brain.play.isRole(GOALIE) and abs(player.brain.ball.locBearing) < constants.SCAN_FIND_BEARING_THRESH:
        return player.stay()
    elif player.firstFrame():
        return player.goLater("spinFindBall")
    return player.stay()
Exemplo n.º 10
0
def scanFindBall(player):
    """
    State to move the head to find the ball. If we find the ball, we
    move to align on it. If we don't find it, we spin to keep looking
    """
    if player.firstFrame():
        player.stopWalking()
        player.brain.tracker.trackBall()

    if player.brain.playbook.role == pbc.GOALIE:
        if transitions.shouldTurnToBall_FoundBall(player):
            return player.goLater('turnToBall')
        elif transitions.shouldSpinFindBall(player):
            return player.goLater('spinFindBall')
    else:
        if transitions.shouldApproachBallWithLoc(player):
            player.brain.tracker.trackBall()
            return player.goLater('approachBallWithLoc')
        elif transitions.shouldSpinFindBall(player):
            return player.goLater('spinFindBall')
        elif transitions.shouldTurnToBall_FoundBall(player):
            return player.goLater('turnToBall')
        elif transitions.shouldSpinFindBall(player):
            return player.goLater('spinFindBall')

    if abs(player.brain.ball.locBearing) < constants.SCAN_FIND_BEARING_THRESH \
            or player.brain.ball.locDist < constants.SCAN_FIND_DIST_THRESH \
            and not player.brain.playbook.role == pbc.GOALIE:
        return player.stay()
    elif player.brain.playbook.role == pbc.GOALIE and \
            abs(player.brain.ball.locBearing) <\
            constants.SCAN_FIND_BEARING_THRESH:
        return player.stay()
    elif player.firstFrame():
        return player.goLater('spinFindBall')
    return player.stay()
Exemplo n.º 11
0
def scanFindBall(player):
    """
    State to move the head to find the ball. If we find the ball, we
    move to align on it. If we don't find it, we spin to keep looking
    """
    if player.firstFrame():
        player.stopWalking()
        player.brain.tracker.trackBall()

    if player.brain.play.isRole(GOALIE):
        if transitions.shouldTurnToBall_FoundBall(player):
            return player.goLater('turnToBall')
        elif transitions.shouldSpinFindBall(player):
            return player.goLater('spinFindBall')
    else:
        if transitions.shouldApproachBallWithLoc(player):
            player.brain.tracker.trackBall()
            return player.goLater('approachBallWithLoc')
        elif transitions.shouldSpinFindBall(player):
            return player.goLater('spinFindBall')
        elif transitions.shouldTurnToBall_FoundBall(player):
            return player.goLater('turnToBall')
        elif transitions.shouldSpinFindBall(player):
            return player.goLater('spinFindBall')

    if abs(player.brain.ball.locBearing) < constants.SCAN_FIND_BEARING_THRESH \
            or player.brain.ball.locDist < constants.SCAN_FIND_DIST_THRESH \
            and not player.brain.play.isRole(GOALIE):
        return player.stay()
    elif player.brain.play.isRole(GOALIE) and \
            abs(player.brain.ball.locBearing) <\
            constants.SCAN_FIND_BEARING_THRESH:
        return player.stay()
    elif player.firstFrame():
        return player.goLater('spinFindBall')
    return player.stay()
Exemplo n.º 12
0
def spinFindBall(player):
    """
    State to spin to find the ball. If we find the ball, we
    move to align on it. If we don't find it, we go to a garbage state
    """

    if player.brain.play.isRole(GOALIE):
        if transitions.shouldApproachBall(player):
            player.brain.tracker.trackBall()
            return player.goLater('approachBall')
        elif transitions.shouldTurnToBall_FoundBall(player):
            return player.goLater('turnToBall')
    else:
        if transitions.shouldApproachBallWithLoc(player):
            player.brain.tracker.trackBall()
            return player.goLater('approachBallWithLoc')
        elif transitions.shouldApproachBall(player):
            player.brain.tracker.trackBall()
            return player.goLater('approachBall')
        elif transitions.shouldTurnToBall_FoundBall(player):
            return player.goLater('turnToBall')
        elif transitions.shouldWalkToBallLocPos(player):
            return player.goLater('walkToBallLocPos')
    if player.firstFrame():
        player.brain.tracker.trackBall()

        if player.justKicked:
            spinDir = player.getSpinDirAfterKick()
        else:
            my = player.brain.my
            ball = player.brain.ball
            spinDir = my.spinDirToHeading(my.h + ball.locBearing)

        player.setWalk(0, 0, spinDir * constants.FIND_BALL_SPIN_SPEED)

    return player.stay()