Пример #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.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')
Пример #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.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')
Пример #3
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()
Пример #4
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 transitions.shouldApproachBall(player):
        return player.goNow('approachBall')

    # a time based check. may be a problem for goalie. if it's not good for him to
    # spin, he should prbly not be chaser anymore, so this wouldn't get reached
    if transitions.shouldSpinFindBall(player):
        return player.goNow('spinFindBall')

    ball = player.brain.ball
    if fabs(ball.bearing) < constants.SCAN_FIND_BEARING_THRESH:
        return player.stay()

    else:
        return player.goLater('spinFindBall')

    return player.stay()
Пример #5
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 transitions.shouldApproachBall(player):
        return player.goNow('approachBall')

    if player.firstFrame():
        #if ball.on
        #player.brain.tracker.trackBallSpin()
        #else:
        #tracker.findBall()

        my = player.brain.my
        ball = player.brain.ball
        spinDir = my.spinDirToPoint(ball)

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

        player.brain.tracker.trackBallSpin()

    if not player.brain.play.isRole(GOALIE):
        if transitions.shouldWalkToBallLocPos(player):
            return player.goLater('approachBall')

    return player.stay()
Пример #6
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()
Пример #7
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')
Пример #8
0
def penaltyKickShortDribble(player):
    if player.firstFrame():
        player.penaltyMadeFirstKick = True
    if transitions.shouldStopPenaltyKickDribbling(player):

        if transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldApproachBall(player):
            return player.goNow('approachBall')

    return ChaseBallStates.approachBallWalk(player)
Пример #9
0
def penaltyKickShortDribble(player):
    if player.firstFrame():
        player.penaltyMadeFirstKick = True
    if transitions.shouldStopPenaltyKickDribbling(player):

        if transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldApproachBall(player):
            return player.goNow('approachBall')

    return ChaseBallStates.approachBallWalk(player)
Пример #10
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()
Пример #11
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()
Пример #12
0
def dribble(player):
    """
    Keep running at the ball, but dribble
    """
    if player.firstFrame():
        player.brain.nav.dribble()

    # 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.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldApproachBall(player):
            return player.goNow('approachBall')

    return player.stay()
Пример #13
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')
Пример #14
0
def dribble(player):
    """
    Keep running at the ball, but dribble
    """
    if player.firstFrame():
        player.brain.CoA.setRobotDribbleGait(player.brain.motion)

    # if we should stop dribbling, see what else we should do
    if transitions.shouldStopDribbling(player):

        if transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldApproachBall(player):
            return player.goNow('approachBall')

    return approachBallWalk(player)
Пример #15
0
def dribble(player):
    """
    Keep running at the ball, but dribble
    """
    if player.firstFrame():
        player.brain.CoA.setRobotDribbleGait(player.brain.motion)

    # if we should stop dribbling, see what else we should do
    if transitions.shouldStopDribbling(player):

        if transitions.shouldKick(player):
            return player.goNow('waitBeforeKick')
        elif transitions.shouldPositionForKick(player):
            return player.goNow('positionForKick')
        elif transitions.shouldApproachBall(player):
            return player.goNow('approachBall')

    return approachBallWalk(player)
Пример #16
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')
Пример #17
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')
Пример #18
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')