More work on goal-ball alignment

This commit is contained in:
2018-06-23 20:50:28 +02:00
parent 73ca100c83
commit 67a8cccd51
5 changed files with 33 additions and 21 deletions

View File

@@ -39,7 +39,6 @@ class FieldFinder(object):
def mask_it(self, frame, field, inverse=False): def mask_it(self, frame, field, inverse=False):
if field is not None: if field is not None:
print(frame.shape)
mask = np.zeros(frame.shape[:2], dtype=np.uint8) mask = np.zeros(frame.shape[:2], dtype=np.uint8)
cv2.drawContours(mask, (field,), -1, 255, -1) cv2.drawContours(mask, (field,), -1, 255, -1)
if inverse: if inverse:
@@ -123,6 +122,8 @@ class GoalFinder(object):
def goal_center(self, contour): def goal_center(self, contour):
l, r = self.left_right_post(contour) l, r = self.left_right_post(contour)
print('Left goal post:', l,
'Right goal post:', r)
return (l + r) / 2 return (l + r) / 2
def draw(self, frame, goal): def draw(self, frame, goal):

View File

@@ -32,6 +32,7 @@ class NaoImageReader(object):
) )
def to_relative(self, x, y): def to_relative(self, x, y):
print('Camera resolution:', self.res)
return x / self.res[1], y / self.res[0] return x / self.res[1], y / self.res[0]
def get_frame(self): def get_frame(self):

View File

@@ -7,13 +7,18 @@ if __name__ == "__main__":
mover = NaoMover(cfg['ip'], cfg['port']) mover = NaoMover(cfg['ip'], cfg['port'])
mover.stand_up() mover.stand_up()
while True: while True:
axis = int(raw_input('Axis: '))
amount = float(raw_input('How much: ')) amount = float(raw_input('How much: '))
if axis == 0: mover.move_to(0, 0, 0.5 * amount)
mover.move_to(amount, 0, 0) mover.wait()
elif axis == 1: mover.move_to(0, -0.3 * amount, 0)
mover.move_to(0, amount, 0) mover.wait()
elif axis == 2: mover.move_to(-0.1 * abs(amount), 0, 0)
mover.move_to(0, 0, amount) # amount = float(raw_input('How much: '))
else: # if axis == 0:
print('Axis out of range (0, 1, 2)') # mover.move_to(amount, 0, 0)
# elif axis == 1:
# mover.move_to(0, amount, 0)
# elif axis == 2:
# mover.move_to(0, 0, amount)
# else:
# print('Axis out of range (0, 1, 2)')

View File

@@ -11,7 +11,6 @@
255 255
] ]
], ],
"cam": 1,
"goal": [ "goal": [
[ [
0, 0,
@@ -24,6 +23,7 @@
255 255
] ]
], ],
"fps": 30,
"res": 2, "res": 2,
"ball_min_radius": 0.01, "ball_min_radius": 0.01,
"field": [ "field": [
@@ -38,7 +38,7 @@
255 255
] ]
], ],
"fps": 30, "cam": 1,
"ip": "192.168.0.11", "ip": "192.168.0.11",
"port": 9559 "port": 9559
} }

View File

@@ -212,12 +212,14 @@ class Striker(object):
print(x, y) print(x, y)
self.turn_to_ball(x, y, tol=0.15) self.turn_to_ball(x, y, tol=0.15)
goal_center_x = None
goal_center_x = self.get_goal_center_angle_from_camera( for i in range(3):
self.upper_camera if goal_center_x is None:
) goal_center_x = self.get_goal_center_angle_from_camera(
self.upper_camera
)
print('Goal center:', goal_center_x) print('Goal center:', goal_center_x)
if goal_center_x is not None and abs(goal_center_x) < 0.01: if goal_center_x is not None and abs(goal_center_x) < 0.1:
print('Goal ball aligned!') print('Goal ball aligned!')
raise SystemExit raise SystemExit
@@ -232,7 +234,9 @@ class Striker(object):
# return False # return False
self.mover.move_to(0, 0.2, 0) self.mover.move_to(0, 0.2, 0)
print('Moving sideways')
self.mover.wait() self.mover.wait()
print('Finished moving')
return False return False
def close(self): def close(self):
@@ -362,7 +366,7 @@ if __name__ == '__main__':
# (see diagram above) # (see diagram above)
else: else:
try: # Hit Ctrl-C to stop, cleanup and exit try: # Hit Ctrl-C to stop, cleanup and exit
state = 'goal_align' state = 'tracking'
# t = None # t = None
while True: while True:
# meassure time for debbuging # meassure time for debbuging
@@ -381,10 +385,10 @@ if __name__ == '__main__':
striker.lower_camera striker.lower_camera
) )
print(ball_in_lower) print(ball_in_lower)
if (ball_in_lower is not None and ball_in_lower[1] > 0.10): if (ball_in_lower is not None and ball_in_lower[1] > 0):
print('Ball is close enough, stop approach') print('Ball is close enough, stop approach')
striker.mover.stop_moving() striker.mover.stop_moving()
striker.say('Align to goal') striker.speak('Align to goal')
state = 'goal_align' state = 'goal_align'
else: else:
print('Continue running') print('Continue running')
@@ -425,5 +429,6 @@ if __name__ == '__main__':
loop_end = time() loop_end = time()
print('Loop time:', loop_end - loop_start) print('Loop time:', loop_end - loop_start)
print('\n\n')
finally: finally:
striker.close() striker.close()