Skip to content

Commit

Permalink
checkpoint in work on goalie
Browse files Browse the repository at this point in the history
  • Loading branch information
Northern Bites committed Apr 18, 2010
1 parent 016a63f commit 775b490
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 286 deletions.
2 changes: 1 addition & 1 deletion noggin/navigator/NavConstants.py
Expand Up @@ -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
57 changes: 44 additions & 13 deletions noggin/navigator/PlaybookPositionStates.py
Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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
Expand All @@ -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()
10 changes: 4 additions & 6 deletions noggin/players/ChaseBallStates.py
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion noggin/players/ChaseBallTransitions.py
Expand Up @@ -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):
Expand Down
37 changes: 21 additions & 16 deletions noggin/players/GoaliePositionStates.py
Expand Up @@ -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():
Expand All @@ -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):
Expand All @@ -85,7 +79,6 @@ def goaliePositionBallClose(player):

def goaliePositionBallFar(player):

nav = player.brain.nav
player.brain.tracker.activeLoc()

if helper.outOfPosition(player):
Expand All @@ -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:
Expand Down Expand Up @@ -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")
Expand Down
61 changes: 27 additions & 34 deletions noggin/players/GoalieTransitions.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions noggin/players/KickingStates.py
Expand Up @@ -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:
Expand Down
75 changes: 0 additions & 75 deletions noggin/players/SquatGameStates.py

This file was deleted.

0 comments on commit 775b490

Please sign in to comment.