From 775b4906b0b2eae674c08c6798ca2a46f765883d Mon Sep 17 00:00:00 2001 From: Northern Bites Date: Sat, 17 Apr 2010 22:51:46 -0400 Subject: [PATCH] checkpoint in work on goalie --- noggin/navigator/NavConstants.py | 2 +- noggin/navigator/PlaybookPositionStates.py | 57 ++++++++++---- noggin/players/ChaseBallStates.py | 10 +-- noggin/players/ChaseBallTransitions.py | 2 +- noggin/players/GoaliePositionStates.py | 37 +++++---- noggin/players/GoalieTransitions.py | 61 +++++++-------- noggin/players/KickingStates.py | 6 -- noggin/players/SquatGameStates.py | 75 ------------------ noggin/players/SquatPositionStates.py | 90 ---------------------- noggin/players/pSquatGoalie.py | 44 ----------- 10 files changed, 98 insertions(+), 286 deletions(-) delete mode 100644 noggin/players/SquatGameStates.py delete mode 100644 noggin/players/SquatPositionStates.py delete mode 100644 noggin/players/pSquatGoalie.py diff --git a/noggin/navigator/NavConstants.py b/noggin/navigator/NavConstants.py index b8d20673..35e9bfb8 100644 --- a/noggin/navigator/NavConstants.py +++ b/noggin/navigator/NavConstants.py @@ -84,6 +84,6 @@ FINAL_HEADING_DIST = 100 FINAL_HEADING_READY_DIST = 60 HEADING_THRESHOLD_TO_SPIN = 60 -FRAMES_THRESHHOLD_TO_SPIN = 30 +FRAMES_THRESHOLD_TO_SPIN = 30 FRAMES_THRESHOLD_TO_POSITION_OMNI = 30 FRAMES_THRESHOLD_TO_POSITION_PLAYBOOK = 30 diff --git a/noggin/navigator/PlaybookPositionStates.py b/noggin/navigator/PlaybookPositionStates.py index f0008d7e..cbefdfd3 100644 --- a/noggin/navigator/PlaybookPositionStates.py +++ b/noggin/navigator/PlaybookPositionStates.py @@ -31,7 +31,7 @@ def playbookWalk(nav): bearingDiff = fabs(my.getRelativeBearing(dest)) if bearingDiff > constants.HEADING_THRESHOLD_TO_SPIN: nav.spinToPointCount += 1 - if nav.spinToPointCount > constants.FRAMES_THRESHHOLD_TO_SPIN: + if nav.spinToPointCount > constants.FRAMES_THRESHOLD_TO_SPIN: return nav.goLater('playbookSpin') else: nav.spinToPointCount = 0 @@ -56,15 +56,16 @@ def playbookOmni(nav): if helper.atDestinationCloser(my, dest) and helper.atHeading(my, dest.h): return nav.goNow('stop') - headingDiff = fabs(my.getRelativeBearing(dest)) - ## if headingDiff > constants.HEADING_THRESHOLD_TO_SPIN: - ## nav.spinToPointCount += 1 - ## if nav.spinToPointCount > constants.FRAMES_THRESHHOLD_TO_SPIN: - ## return nav.goLater('playbookSpin') - ## else: - ## nav.spinToPointCount = 0 - - if not helper.useFinalHeading(nav.brain, dest): + if helper.useFinalHeading(nav.brain, dest): + headingDiff = fabs(my.getRelativeBearing(dest)) + if headingDiff > constants.HEADING_THRESHOLD_TO_SPIN: + nav.spinToPointCount += 1 + if nav.spinToPointCount > constants.FRAMES_THRESHOLD_TO_SPIN: + return nav.goLater('playbookFinalSpin') + else: + nav.spinToPointCount = 0 + + else: nav.stopOmniCount += 1 if nav.stopOmniCount > constants.FRAMES_THRESHOLD_TO_POSITION_PLAYBOOK: return nav.goLater('playbookWalk') @@ -75,6 +76,7 @@ def playbookSpin(nav): if nav.firstFrame(): nav.walkOmniCount = 0 nav.spinToPointCount = 0 + nav.walkToPointCount = 0 my = nav.brain.my dest = nav.dest @@ -93,10 +95,39 @@ def playbookSpin(nav): headingDiff = fabs(my.getRelativeBearing(dest)) if headingDiff < constants.HEADING_THRESHOLD_TO_SPIN: - nav.spinToPointCount += 1 - if nav.spinToPointCount > constants.FRAMES_THRESHHOLD_TO_SPIN: + nav.walkToPointCount += 1 + if nav.walkToPointCount > constants.FRAMES_THRESHOLD_TO_SPIN: return nav.goLater('playbookWalk') else: - nav.spinToPointCount = 0 + nav.walkToPointCount = 0 + + return nav.stay() + +def playbookFinalSpin(nav): + if nav.firstFrame(): + nav.walkOmniCount = 0 + nav.walkToPointCount = 0 + + my = nav.brain.my + dest = nav.dest + + walkX, walkY, walkTheta = helper.getSpinOnlyParam(my, dest) + helper.setSpeed(nav, walkX, walkY, walkTheta) + + if not helper.atDestinationGoalie(my, dest): + if helper.useFinalHeading(nav.brain, dest): + nav.walkOmniCount += 1 + if nav.walkOmniCount > constants.FRAMES_THRESHOLD_TO_POSITION_OMNI: + return nav.goLater('playbookOmni') + else: + nav.walkOmniCount = 0 + nav.walkToPointCount += 1 + if nav.walkToPointCount > constants.FRAMES_THRESHOLD_TO_SPIN: + return nav.goLater('playbookWalk') + else: + nav.walkToPointCount = 0 + else: + if helper.atHeading(my, dest.h): + return nav.goNow('stop') return nav.stay() diff --git a/noggin/players/ChaseBallStates.py b/noggin/players/ChaseBallStates.py index 6431b1cd..28e63a1d 100644 --- a/noggin/players/ChaseBallStates.py +++ b/noggin/players/ChaseBallStates.py @@ -11,7 +11,6 @@ from .. import NogginConstants from ..playbook.PBConstants import GOALIE from math import fabs -import man.motion.RobotGaits as RobotGaits def chase(player): """ @@ -313,9 +312,9 @@ def positionForKick(player): sY = max(constants.PFK_MIN_Y_MAGNITUDE,sY) * MyMath.sign(sY) if transitions.shouldApproachForKick(player): - targetX = (ball.relX - - (constants.BALL_KICK_LEFT_X_CLOSE + - constants.BALL_KICK_LEFT_X_FAR) / 2.0) + # targetX = (ball.relX - + # (constants.BALL_KICK_LEFT_X_CLOSE + + # constants.BALL_KICK_LEFT_X_FAR) / 2.0) sX = MyMath.clip(ball.relX * constants.PFK_X_GAIN, constants.PFK_MIN_X_SPEED, constants.PFK_MAX_X_SPEED) @@ -493,12 +492,11 @@ def ballInMyBox(player): if not player.ballInMyGoalBox(): return player.goLater('chase') return player.stay() - +# TODO def approachDangerousBall(player): if player.firstFrame(): player.stopWalking() #print "approach dangerous ball" - my = player.brain.my #single steps towards ball and goal with spin player.setSteps(0, 0, 0, 0) diff --git a/noggin/players/ChaseBallTransitions.py b/noggin/players/ChaseBallTransitions.py index d15a6cb1..9f55685c 100644 --- a/noggin/players/ChaseBallTransitions.py +++ b/noggin/players/ChaseBallTransitions.py @@ -73,7 +73,7 @@ def shouldRepositionForKick(player): """ Stop waiting for kick and realign on the ball instead """ - ball = player.brain.ball + return False def shouldApproachForKick(player): diff --git a/noggin/players/GoaliePositionStates.py b/noggin/players/GoaliePositionStates.py index 6aae5f3f..161e67af 100644 --- a/noggin/players/GoaliePositionStates.py +++ b/noggin/players/GoaliePositionStates.py @@ -27,20 +27,19 @@ def goalieAwesomePosition(player): else: player.brain.tracker.trackBall() - useOmni = helper.useOmni(player) - changedOmni = False + heading = None ball = brain.ball - bearing = None if ball.on: - bearing = ball.bearing + heading = brain.my.h + ball.bearing elif ball.framesOff < 3: - bearing = ball.locBearing + heading = brain.my.h + ball.locBearing else: - bearing = NogginConstants.OPP_GOAL_HEADING + heading = NogginConstants.OPP_GOAL_HEADING - position = RobotLocation(brain.play.getPosition(), my.h + bearing) + position = player.brain.play.getPosition() + position = RobotLocation(position[0], position[1], heading) nav.positionPlaybook(position) if nav.isStopped(): @@ -65,11 +64,6 @@ def goaliePositionForSave(player): def goaliePositionBallClose(player): - nav = player.brain.nav - player.brain.tracker.trackBall() - - #if not nav.atHeading(NogginConstants.OPP_GOAL_HEADING): - # return player.goLater('goalieSpinToPosition') if helper.useLeftStrafeCloseSpeed(player): helper.strafeLeftSpeed(player) elif helper.useRightStrafeCloseSpeed(player): @@ -85,7 +79,6 @@ def goaliePositionBallClose(player): def goaliePositionBallFar(player): - nav = player.brain.nav player.brain.tracker.activeLoc() if helper.outOfPosition(player): @@ -105,7 +98,7 @@ def goaliePositionBallFar(player): return player.stay() def goalieSpinToPosition(player): - nav = player.brain.nav + if helper.useFarPosition(player): player.brain.tracker.activeLoc() else: @@ -145,16 +138,28 @@ def goalieOutOfPosition(player): def goalieAtPosition(player): brain = player.brain nav = player.brain.nav + if brain.ball.dist >= constants.ACTIVE_LOC_THRESH: player.brain.tracker.activeLoc() else: player.brain.tracker.trackBall() # Check that the position is correct - position = RobotLocation(player.brain.play.getPosition()) + ball = brain.ball + heading = None + + if ball.on: + heading = brain.my.h + ball.bearing + elif ball.framesOff < 3: + heading = brain.my.h + ball.locBearing + else: + heading = NogginConstants.OPP_GOAL_HEADING + + position = player.brain.play.getPosition() + position = RobotLocation(position[0], position[1], heading) if (abs(nav.dest.x - position.x) > constants.SHOULD_POSITION_DIFF or - abs(nav.dest.y - position,y) > constants.SHOULD_POSITION_DIFF or + abs(nav.dest.y - position.y) > constants.SHOULD_POSITION_DIFF or not player.atDestinationGoalie() or not player.atHeading()): return player.goNow("goalieAwesomePosition") diff --git a/noggin/players/GoalieTransitions.py b/noggin/players/GoalieTransitions.py index 049e5563..82b5fa3b 100644 --- a/noggin/players/GoalieTransitions.py +++ b/noggin/players/GoalieTransitions.py @@ -18,31 +18,32 @@ def goalieRunChecks(player): player.shouldChaseCounter = 0 return 'goalieSave' - ## elif not player.isChasing: - ## if shouldChaseLoc(player): - ## player.shouldChaseCounter+=1 - ## if DEBUG: print "should chase: ", player.shouldChaseCounter - ## if player.shouldChaseCounter >= goalCon.START_CHASE_BUFFER: - ## player.shouldChaseCounter = 0 - ## return 'chase' - ## else: - ## player.shouldChaseCounter = 0 + elif not player.isChasing: + if shouldChaseLoc(player): + player.shouldChaseCounter+=1 + if DEBUG: print "should chase: ", player.shouldChaseCounter + if player.shouldChaseCounter >= goalCon.START_CHASE_BUFFER: + player.shouldChaseCounter = 0 + return 'chase' + else: + player.shouldChaseCounter = 0 + + elif player.isChasing and\ + not chaseTran.shouldntStopChasing(player): + if shouldStopChaseLoc(player) : + player.shouldChaseCounter+=1 + if DEBUG: print "should stop chase: ", player.shouldChaseCounter + if player.shouldChaseCounter >= goalCon.STOP_CHASE_BUFFER: + player.shouldChaseCounter = 0 + player.isChasing = False + return 'goaliePosition' + else: + player.shouldChaseCounter = 0 + elif player.currentState == 'gamePlaying': player.isChasing = False return 'goalieAtPosition' - ## elif player.isChasing and\ - ## not chaseTran.shouldntStopChasing(player): - ## if shouldStopChaseLoc(player) : - ## player.shouldChaseCounter+=1 - ## if DEBUG: print "should stop chase: ", player.shouldChaseCounter - ## if player.shouldChaseCounter >= goalCon.STOP_CHASE_BUFFER: - ## player.shouldChaseCounter = 0 - ## player.isChasing = False - ## return 'goaliePosition' - ## else: - ## player.shouldChaseCounter = 0 - return player.currentState def useClosePosition(player): @@ -219,26 +220,18 @@ def shouldHoldSave(player): return False def shouldChaseLoc(player): - if player.penaltyKicking: + if player.penaltyKicking or player.saving: return False ball = player.brain.ball - my = player.brain.my - if (player.squatting and ball.locDist <= goalCon.CHASE_FROM_SQUAT_DIST and - abs(ball.locBearing) <= goalCon.CHASE_FROM_SQUAT_BEARING and - abs(ball.velX) <= goalCon.CHASE_FROM_SQUAT_VEL and - abs(ball.velY) <= goalCon.CHASE_FROM_SQUAT_VEL): + if (ball.y > Constants.MY_GOALBOX_BOTTOM_Y + and ball.y < Constants.MY_GOALBOX_TOP_Y + and ball.x < Constants.MY_GOALBOX_RIGHT_X + + goalCon.AGGRESSIVENESS_OFFSET): return True - if not player.squatting: - if (ball.y > Constants.MY_GOALBOX_BOTTOM_Y + goalCon.GOALBOX_Y_REDUCTION - and ball.y < Constants.MY_GOALBOX_TOP_Y -goalCon.GOALBOX_Y_REDUCTION - and ball.x < Constants.MY_GOALBOX_RIGHT_X + - goalCon.AGGRESSIVENESS_OFFSET): - return True return False def shouldStopChaseLoc(player): - my = player.brain.my ball = player.brain.ball #change to use ball uncertainty if ball.uncertX < Constants.GOOD_LOC_XY_UNCERT_THRESH: diff --git a/noggin/players/KickingStates.py b/noggin/players/KickingStates.py index 7e1a412a..a24346c1 100644 --- a/noggin/players/KickingStates.py +++ b/noggin/players/KickingStates.py @@ -51,12 +51,6 @@ def decideKick(player): player.inKickingState = False return player.goLater('scanFindBall') - # Get references to the collected data - myLeftPostBearing = player.kickDecider.myLeftPostBearing - myRightPostBearing = player.kickDecider.myRightPostBearing - oppLeftPostBearing = player.kickDecider.oppLeftPostBearing - oppRightPostBearing = player.kickDecider.oppRightPostBearing - player.printf(player.kickDecider) if player.penaltyKicking: diff --git a/noggin/players/SquatGameStates.py b/noggin/players/SquatGameStates.py deleted file mode 100644 index 7b2a3b97..00000000 --- a/noggin/players/SquatGameStates.py +++ /dev/null @@ -1,75 +0,0 @@ -import man.motion.SweetMoves as SweetMoves - -def gameInitial(player): - """ - Ensure we are sitting down and head is snapped forward. - In the future, we may wish to make the head move a bit slower here - Also, in the future, gameInitial may be responsible for turning off the gains - """ - if player.firstFrame() and not player.squatting: - player.stopWalking() - player.gainsOn() - player.zeroHeads() - player.GAME_INITIAL_satDown = False - - elif player.brain.nav.isStopped() and not player.GAME_INITIAL_satDown and\ - not player.squatting: - player.GAME_INITIAL_satDown = True - player.executeMove(SweetMoves.SIT_POS) - - return player.stay() - -def gameReady(player): - """ - Stand up, and pan for localization - """ - player.standup() - player.brain.tracker.locPans() - if player.lastDiffState == 'gameInitial': - return player.goLater('relocalize') - if player.firstFrame() and \ - player.lastDiffState == 'gamePenalized': - player.brain.resetLocalization() - - return player.goLater('squatPosition') - -def gameSet(player): - player.brain.resetGoalieLocalization() - if player.squatting: - return player.goLater('squatted') - return player.goLater('squat') - -def gamePlaying(player): - if player.squatting: - return player.goLater('squatted') - return player.goLater('squat') - -def gameFinished(player): - """ - Ensure we are sitting down and head is snapped forward. - In the future, we may wish to make the head move a bit slower here - Also, in the future, gameInitial may be responsible for turning off the gains - """ - if player.squatting: - player.executeMove(SweetMoves.GOALIE_SQUAT_STAND_UP) - player.squatting = False - - if player.firstFrame(): - player.zeroHeads() - player.GAME_FINISHED_satDown = False - return player.stay() - - # Sit down once we've finished walking - if player.brain.nav.isStopped() and not player.GAME_FINISHED_satDown: - player.GAME_FINISHED_satDown = True - player.executeMove(SweetMoves.SIT_POS) - return player.stay() - - if not player.motion.isBodyActive() and player.GAME_FINISHED_satDown: - player.gainsOff() - return player.stay() - -def gamePenalized(player): - if player.firstFrame(): - player.penalizeHeads() - return player.stay() diff --git a/noggin/players/SquatPositionStates.py b/noggin/players/SquatPositionStates.py deleted file mode 100644 index 16a13d2f..00000000 --- a/noggin/players/SquatPositionStates.py +++ /dev/null @@ -1,90 +0,0 @@ -import man.motion.SweetMoves as SweetMoves -import GoalieConstants as constants -import GoalieTransitions as helper -from ..playbook import PBConstants -from .. import NogginConstants - -DEBUG = False - -def squat(player): - if player.firstFrame(): - player.isChasing = False - player.executeMove(SweetMoves.INITIAL_POS) - player.squatting = True - if DEBUG: - player.executeMove(SweetMoves.SAVE_CENTER_DEBUG) - else: - player.executeMove(SweetMoves.GOALIE_SQUAT) - if (player.stateTime >= - SweetMoves.getMoveTime(SweetMoves.GOALIE_SQUAT) + - SweetMoves.getMoveTime(SweetMoves.INITIAL_POS)): - return player.goLater('squatted') - return player.stay() - -def squatted(player): - player.isChasing = False - player.squatting = True - brain = player.brain - if brain.ball.locDist >= constants.ACTIVE_LOC_THRESH: - brain.tracker.activeLoc() - else: - brain.tracker.trackBall() - - return player.stay() - -def squatPosition(player): - brain = player.brain - position = brain.play.getPosition() - nav = brain.nav - my = brain.my - - if player.firstFrame(): - player.changeOmniGoToCounter = 0 - player.isChasing = False - player.squatting = False - - if brain.ball.x >= constants.ACTIVE_LOC_THRESH: - brain.tracker.activeLoc() - else: - brain.tracker.trackBall() - - useOmni = helper.useOmni(player) - changedOmni = False - - ball = brain.ball - bearing = None - - if (not player.atDestinationGoalie() or - not player.atHeading()): - if not useOmni: - nav.goTo((PBConstants.GOALIE_HOME_X, PBConstants.GOALIE_HOME_Y,\ - NogginConstants.OPP_GOAL_HEADING)) - else: - nav.omniGoTo((PBConstants.GOALIE_HOME_X, PBConstants.GOALIE_HOME_Y,\ - NogginConstants.OPP_GOAL_HEADING)) - else: - player.stopWalking() - return player.goLater("squat") - - return player.stay() - -def chasePrepare(player): - if player.firstFrame(): - player.brain.tracker.trackBall() - player.isChasing = False - - if player.squatting: - if DEBUG: - pass - else: - player.executeMove(SweetMoves.GOALIE_SQUAT_STAND_UP) - else: - player.isChasing = True - return player.goNow('chase') - elif (player.stateTime >= - SweetMoves.getMoveTime(SweetMoves.GOALIE_SQUAT_STAND_UP)): - player.isChasing = True - player.squatting = False - return player.goNow('chase') - - return player.stay() diff --git a/noggin/players/pSquatGoalie.py b/noggin/players/pSquatGoalie.py deleted file mode 100644 index ecf97ecd..00000000 --- a/noggin/players/pSquatGoalie.py +++ /dev/null @@ -1,44 +0,0 @@ -from . import SoccerFSA -from . import SquatGameStates -from . import SquatPositionStates -from . import GoalieTransitions -from . import ChaseBallStates -from . import FindBallStates -from . import KickingStates -from . import PositionStates -from ..playbook.PBConstants import GOALIE - -class SoccerPlayer(SoccerFSA.SoccerFSA): - def __init__(self, brain): - SoccerFSA.SoccerFSA.__init__(self,brain) - self.addStates(SquatGameStates) - self.addStates(SquatPositionStates) - self.addStates(ChaseBallStates) - self.addStates(FindBallStates) - self.addStates(KickingStates) - self.addStates(PositionStates) - self.setName('pSquatGoalie') - - self.squatting = False - self.isChasing = False - self.penaltyKicking = False - self.inKickingState = False - self.hasKickedOffKick = True - - self.shouldChaseCounter = 0 - self.ballRelX = 0 - self.ballRelY = 0 - - def run(self): - gcState = self.brain.gameController.currentState - if gcState == 'gamePlaying' or\ - (gcState == 'penaltyShotsGamePlaying' - and self.brain.play.isRole(GOALIE)): - state = GoalieTransitions.goalieRunChecks(self) - if state == 'goaliePosition': - state = 'squatPosition' - elif state == 'chase': - state = 'chasePrepare' - if not state == self.currentState: - self.switchTo(state) - SoccerFSA.SoccerFSA.run(self)