-
Notifications
You must be signed in to change notification settings - Fork 29
/
GoaliePositionStates.py
166 lines (130 loc) · 4.76 KB
/
GoaliePositionStates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from .. import NogginConstants
import GoalieTransitions as helper
import GoalieConstants as constants
from ..util import MyMath
from man.noggin.typeDefs.Location import RobotLocation
def goaliePosition(player):
#consider using ball.x < fixed point- locDist could cause problems if
#goalie is out of position. difference in accuracy?
player.isChasing = False
return player.goNow('goalieAwesomePosition')
def goalieAwesomePosition(player):
"""
Have the robot navigate to the position reported to it from playbook
"""
brain = player.brain
nav = brain.nav
my = brain.my
if player.firstFrame():
player.changeOmniGoToCounter = 0
if brain.ball.dist >= constants.ACTIVE_LOC_THRESH:
player.brain.tracker.activeLoc()
else:
player.brain.tracker.trackBall()
heading = None
ball = brain.ball
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)
nav.positionPlaybook(position)
if nav.isStopped():
return player.goLater("goalieAtPosition")
return player.stay()
def goaliePositionForSave(player):
if player.firstFrame():
player.stopWalking()
player.brain.tracker.trackBall()
strafeDir = helper.strafeDirForSave(player)
if strafeDir == -1:
helper.strafeRightSpeed(player)
elif strafeDir == 1:
helper.strafeLeftSpeed(player)
else:
player.stopWalking()
return player.stay()
def goaliePositionBallClose(player):
if helper.useLeftStrafeCloseSpeed(player):
helper.strafeLeftSpeed(player)
elif helper.useRightStrafeCloseSpeed(player):
helper.strafeRightSpeed(player)
else:
player.stopWalking()
#switch out if we lose the ball for multiple frames
if helper.useFarPosition(player):
return player.goNow('goaliePositionBallFar')
return player.stay()
def goaliePositionBallFar(player):
player.brain.tracker.activeLoc()
if helper.outOfPosition(player):
player.goLater('goalieOutOfPosition')
#elif not nav.atHeading(NogginConstants.OPP_GOAL_HEADING):
# return player.goLater('goalieSpinToPosition')
elif helper.useLeftStrafeFarSpeed(player):
helper.strafeLeftSpeed(player)
elif helper.useRightStrafeFarSpeed(player):
helper.strafeRightSpeed(player)
else:
player.stopWalking()
#Don't switch out if we don't see the ball
if helper.useClosePosition(player):
return player.goLater('goaliePositionBallClose')
return player.stay()
def goalieSpinToPosition(player):
if helper.useFarPosition(player):
player.brain.tracker.activeLoc()
else:
player.brain.tracker.trackBall()
if not player.atHeading(NogginConstants.OPP_GOAL_HEADING):
spinDir = player.brain.my.spinDirToHeading(NogginConstants.OPP_GOAL_HEADING)
player.setWalk(0, 0, spinDir*10)
return player.stay()
else:
player.stopWalking()
return player.goLater('goaliePosition')
return player.stay()
def goalieOutOfPosition(player):
nav = player.brain.nav
if helper.useFarPosition(player):
player.brain.tracker.activeLoc()
else:
player.brain.tracker.trackBall()
position = RobotLocation(player.brain.play.getPosition())
if player.firstFrame() or\
nav.dest.x != position.x or nav.dest.y != position.y:
nav.omniGoTo(position)
if helper.useClosePosition(player):
return player.goLater('goaliePositionBallClose')
if nav.isStopped() and player.counter > 0:
player.framesFromCenter = 0
player.stepOffCenter = 0
return player.goLater('goaliePosition')
return player.stay()
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
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
not player.atDestinationGoalie() or
not player.atHeading()):
return player.goNow("goalieAwesomePosition")
return player.stay()