コード例 #1
0
ファイル: ChaseBallStates.py プロジェクト: iris-xx/nao-man
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()
コード例 #2
0
ファイル: PositionStates.py プロジェクト: iris-xx/nao-man
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()