コード例 #1
0
def performAimToGoal():
    global aimCounter
    if Global.vTGoal.isVisible():  # if we can see the goal

        # Choose the gap, locking it in if we're lining up
        minH, maxH = selectGap(aimCounter > 0)

        gapWidth = abs(maxH - minH)
        padding = gapWidth / 5.0

        #print "vGoal, bestgap", minH, maxH,

        if minH < -padding and maxH > padding:
            aimCounter += 1  # count frames of good aim
            # DON'T reset this to zero if we're outside the gap. reset->deadlock
            #print "++aimcounter to", aimCounter,

            # A forceStepComplete here makes the kick more reliably aim to
            # hit the goal but hinders further lining up to the centre of the
            # gap and any forward walking. Trade-off.
            Action.forceStepComplete()

        if aimCounter >= WAIT_FOR_AIM:
            # if inside the best gap, shoot
            #print "lined up good,",
            aimCounter = 0
            headColor(Indicator.RGB_GREEN)
            return Constant.STATE_SUCCESS
        else:
            # turn to the middle of the gap
            turnAmount = (minH + maxH) / 2.0
            #print "turning", turnAmount,
            # TODO: use another kind fast short step walk?
            #if Global.selfLoc.getY() > Constant.FIELD_LENGTH * 3 / 4:
            #    grabSideWalk(turnAmount)
            #else:
            sGrabDribble.perform(0, 0, turnAmount)

    else:  # if we can NOT see the goal
        global turnSpeed
        heading = hMath.getHeadingToFaceAt(Global.selfLoc,\
                                           Constant.TARGET_GOAL_X,\
                                           Constant.TARGET_GOAL_Y)
        if not turnSpeed:  # Choose direction to spin
            if heading > 0:
                turnSpeed = 80
            else:
                turnSpeed = -80
        #else:               # Check we haven't gone to far
        #if turnSpeed > 0 and heading < -TURN_PAST_GOAL:
        #    return Constant.STATE_FAILED
        #elif turnSpeed < 0 and heading > TURN_PAST_GOAL:
        #    return Constant.STATE_FAILED

        #print "no vGoal, turning", turnSpeed,
        sGrabDribble.perform(0, 0, turnSpeed)

    return Constant.STATE_EXECUTING
コード例 #2
0
def performNotAimToGoal():
    # if we are not aiming to the goal, use GPS
    heading = hMath.getHeadingToFaceAt(Global.selfLoc, \
                                       targetX, targetY)
    if canIKick(heading, gKickType):
        return Constant.STATE_SUCCESS
    else:
        sGrabDribble.perform(0, 0, heading * HEADING_ANGLE_MULTIPLE)
        return Constant.STATE_EXECUTING
コード例 #3
0
ファイル: rSetPlay.py プロジェクト: anorth/runswift-2005
def kickOffKickToGap():
    global playCounter, whenGrabbed
    global bestHeading, gBestHeading

    (myX, myY) = Global.selfLoc.getPos()
    myH = Global.selfLoc.getHeading()

    if pReady.chosenFormation == 0:
        print "chosenFormation =", pReady.chosenFormation, "- going right"
        (kickX, kickY) = (Constant.MAX_GOALBOX_EDGE_X,
                          Constant.TOP_GOALBOX_EDGE_Y)
        (suppX, suppY) = (kickX + 40, kickY - 40)
        (lKickX, lKickY) = hMath.getLocalCoordinate(myX, myY, myH, kickX,
                                                    kickY)
    else:
        print "chosenFormation =", pReady.chosenFormation, "- going left"
        (kickX, kickY) = (Constant.MIN_GOALBOX_EDGE_X,
                          Constant.TOP_GOALBOX_EDGE_Y)
        (suppX, suppY) = (kickX - 40, kickY - 40)
        (lKickX, lKickY) = hMath.getLocalCoordinate(myX, myY, myH, kickX,
                                                    kickY)

    if pReady.isCentre(Global.kickOffPos):
        if playCounter > 120:  # 6 sec, just in case
            return False

        if whenGrabbed == 0:
            #print "grabbing"
            if sGrab.grabbingCount == 0:
                # Find the obstacle gap just before we drop the head to grab
                (gapLeft, gapRight, bestHeading, angle) = \
                    VisionLink.getBestGap(lKickX, lKickY,
                                            GAP_MAX_DIST,GAP_MIN_DIST,
                                            GAP_MIN,GAP_MIN_INTENSITY,
                                            Constant.OBS_USE_SHARED)
                gBestHeading = hMath.local2GlobalHeading(
                    Global.selfLoc, bestHeading)
                #gBestHeading = hMath.getHeadingBetween(Constant.FIELD_WIDTH/2, Constant.FIELD_LENGTH/2, kickX, kickY)
                print "local target", lKickX, lKickY
                print "gap", bestHeading, gBestHeading
            if sGrab.perform() == Constant.STATE_FAILED:
                return False
            if sGrab.isGrabbed:
                print "grabbed, best gap at local", bestHeading, \
                        "global", gBestHeading
                whenGrabbed = playCounter
            return True

        # Don't prevent other forward from being attacker
        Global.myRole = Global.myLastRole = Constant.SUPPORTER

        relH = gBestHeading - Global.selfLoc.getHeading()
        if abs(relH) >= 3:
            if sGrabDribble.perform(0, 0, relH) == Constant.STATE_FAILED:
                return False
            return True

        Action.kick(Action.SoftTapWT)
        if Action.shouldIContinueKick():
            Action.continueKick()
            return True

        sGrab.resetPerform()
        return False

    elif pReady.isForward(Global.kickOffPos):
        if playCounter < 80:
            sDodgyDog.dodgyDogTo(suppX, suppY)
            hTrack.stationaryLocalise(6, 30, -30)
            return True
        elif playCounter < 120:
            if hTrack.canSeeBall and Global.ballD < 30:
                Global.myRole = Global.myLastRole = Constant.ATTACKER
                return False
            h = hMath.normalizeAngle_0_360(myH + Global.ballH)
            hTrack.saGoToTargetFacingHeading(suppX, suppY, h)
            hFWHead.DecideNextAction()
            return True
        else:
            Global.myRole = Global.myLastRole = Constant.ATTACKER
            return False
    else:
        return False

    return False
コード例 #4
0
ファイル: rSetPlay.py プロジェクト: anorth/runswift-2005
def kickOffKickToCorner():
    global playCounter, whenGrabbed
    global bestHeading, gBestHeading

    # Warning: this set play freezes the attacker when it fails.
    # Don't use it yet

    (myX, myY) = Global.selfLoc.getPos()
    myH = Global.selfLoc.getHeading()

    if pReady.chosenFormation == 0:
        (kickX, kickY) = (Constant.FIELD_WIDTH, Constant.FIELD_LENGTH - 80)
        (suppX, suppY) = (kickX + 40, kickY - 40)
    else:
        (kickX, kickY) = (0, Constant.FIELD_LENGTH - 80)
        (suppX, suppY) = (kickX - 40, kickY - 40)

    if pReady.isCentre(Global.kickOffPos):
        print "kickToCorner: whenGrabbed", whenGrabbed,
        if playCounter > 120:  # 6 sec, just in case
            return False

        if whenGrabbed == 0:
            if sGrab.grabbingCount == 0:
                # Find the obstacle gap just before we drop the head to grab
                #(gapLeft, gapRight, bestHeading, angle) = \
                #    VisionLink.getBestGap(lKickX, lKickY,
                #                            GAP_MAX_DIST,GAP_MIN_DIST,
                #                            GAP_MIN,GAP_MIN_INTENSITY,
                #                            Constant.OBS_USE_SHARED)
                gap = getGapTo(kickX, kickY)
                if gap != None:
                    (gapLeft, gapRight, bestHeading, angle) = gap
                    bestHeading += hMath.getSign(5, bestHeading)
                else:
                    bestHeading = hMath.getHeadingToAbsolute(
                        Global.selfLoc, kickX, kickY)

                gBestHeading = hMath.local2GlobalHeading(
                    Global.selfLoc, bestHeading)
                print "gap", bestHeading, gBestHeading,
            print "grabbing"
            if sGrab.perform() == Constant.STATE_FAILED:
                print "Grab failed in set play. Done."
                sGrab.resetPerform()
                Global.myRole = Global.myLastRole = Constant.ATTACKER
                return False
            if sGrab.isGrabbed:
                print "grabbed, best gap at local", bestHeading, \
                        "global", gBestHeading
                whenGrabbed = playCounter
            return True

        # Don't prevent other forward from being attacker
        Global.myRole = Global.myLastRole = Constant.SUPPORTER

        # Keep updating gap, but not with shared obs
        gap = getGapTo(kickX, kickY)
        if gap != None:
            (gapLeft, gapRight, bestHeading, angle) = gap
            bestHeading += hMath.getSign(5, bestHeading)
            gBestHeading = hMath.local2GlobalHeading(Global.selfLoc,
                                                     bestHeading)
            print "New gap global", gBestHeading,
        else:
            print "No gap left - using last global", gBestHeading,
            #bestHeading = 0 # Kick now
        relH = gBestHeading - Global.selfLoc.getHeading()
        print "relH", relH,
        if abs(relH) >= 4 and (playCounter - whenGrabbed) < 55:
            print "dribbling"
            if sGrabDribble.perform(0, 0, relH) == Constant.STATE_FAILED:
                print "dribble failed. Done."
                Global.myRole = Global.myLastRole = Constant.ATTACKER
                return False
            return True

        print "Kicking",
        Action.kick(Action.SoftTapWT)
        if Action.shouldIContinueKick():
            Action.continueKick()
            return True

        sGrab.resetPerform()
        print "success. Done."
        return False

    elif pReady.isForward(Global.kickOffPos):
        Global.myRole = Global.myLastRole = Constant.ATTACKER
        if playCounter < 60:
            hTrack.saGoToTarget(suppX, suppY, 25)
            hFWHead.DecideNextAction()
            return True
        elif playCounter < 100:
            if hTrack.canSeeBall and Global.ballD < 30:
                return False
            h = hMath.normalizeAngle_0_360(myH + Global.ballH)
            hTrack.saGoToTargetFacingHeading(suppX, suppY, h)
            hFWHead.DecideNextAction()
            return True
        else:
            rAttacker.perform()
            return False
    else:
        return False

    return False
コード例 #5
0
ファイル: rSetPlay.py プロジェクト: anorth/runswift-2005
def kickOffPushToSupporter():
    global playCounter, whenGrabbed
    global bestHeading, gBestHeading

    (myX, myY) = Global.selfLoc.getPos()
    myH = Global.selfLoc.getHeading()

    if pReady.chosenFormation == 0:
        (suppX, suppY) = (PUSH_TO_X + 40, PUSH_TO_Y - 40)
    else:
        (suppX, suppY) = (PUSH_TO_X - 40, PUSH_TO_Y - 40)

    if pReady.isCentre(Global.kickOffPos):
        if playCounter > 180:  # 6 sec, just in case
            return False

        if whenGrabbed == 0:
            #print "grabbing"
            if sGrab.grabbingCount == 0:
                # Find the obstacle gap just before we drop the head to grab
                #(gapLeft, gapRight, bestHeading, angle) = \
                #    VisionLink.getBestGap(lKickX, lKickY,
                #                            GAP_MAX_DIST,GAP_MIN_DIST,
                #                            GAP_MIN,GAP_MIN_INTENSITY,
                #                            Constant.OBS_USE_SHARED)
                gap = getGapTo(PUSH_TO_X, PUSH_TO_Y)
                if gap != None:
                    (gapLeft, gapRight, bestHeading, angle) = gap
                else:
                    bestHeading = hMath.getHeadingToAbsolute(
                        Global.selfLoc, PUSH_TO_X, PUSH_TO_Y)
                gBestHeading = hMath.local2GlobalHeading(
                    Global.selfLoc, bestHeading)
                print "gap ", bestHeading, gBestHeading
            if sGrab.perform() == Constant.STATE_FAILED:
                return False
            if sGrab.isGrabbed:
                #print "grabbed, best gap at local", bestHeading, \
                #        "global", gBestHeading
                whenGrabbed = playCounter
            return True

        # Don't prevent other forward from being attacker
        Global.myRole = Global.myLastRole = Constant.SUPPORTER

        relH = gBestHeading - Global.selfLoc.getHeading()
        if playCounter - whenGrabbed < 40:
            if sGrabDribble.perform(Action.MAX_FORWARD, 0, relH) \
                    == Constant.STATE_FAILED:
                return False
            return True

        Action.kick(Action.GTChestPushWT)
        if Action.shouldIContinueKick():
            Action.continueKick()
            return True

        sGrab.resetPerform()
        return False

    elif pReady.isForward(Global.kickOffPos):
        if playCounter < 80:
            sDodgyDog.dodgyDogTo(suppX, suppY)
            hTrack.stationaryLocalise(6, 30, -30)
            return True
        elif playCounter < 120:
            if hTrack.canSeeBall and Global.ballD < 30:
                Global.myRole = Global.myLastRole = Constant.ATTACKER
                return False
            h = hMath.normalizeAngle_0_360(myH + Global.ballH)
            hTrack.saGoToTargetFacingHeading(suppX, suppY, h)
            hFWHead.DecideNextAction()
            return True
        else:
            Global.myRole = Global.myLastRole = Constant.ATTACKER
            return False
    else:
        return False

    return False