fixed RuntimeError('Cannot capture')
This commit is contained in:
@@ -21,8 +21,9 @@ class NaoImageReader(object):
|
||||
self.res = self.RESOLUTIONS[res]
|
||||
self.cam_id=cam_id
|
||||
self.vd = ALProxy('ALVideoDevice', ip, port)
|
||||
streamer_name = '_'.join(['lower' if cam_id else 'upper', str(res)])
|
||||
self.sub = self.vd.subscribeCamera(
|
||||
"video_streamer", cam_id, res, 13, fps
|
||||
streamer_name, cam_id, res, 13, fps
|
||||
)
|
||||
|
||||
def to_angles(self, x, y):
|
||||
@@ -36,10 +37,8 @@ class NaoImageReader(object):
|
||||
def get_frame(self):
|
||||
result = self.vd.getImageRemote(self.sub)
|
||||
self.vd.releaseImage(self.sub)
|
||||
if result == None:
|
||||
raise RuntimeError('cannot capture')
|
||||
elif result[6] == None:
|
||||
raise ValueError('no image data string')
|
||||
if result is None or result[6] is None:
|
||||
raise RuntimeError("Couldn't capture")
|
||||
else:
|
||||
height, width = self.res
|
||||
return np.frombuffer(result[6], dtype=np.uint8).reshape(
|
||||
|
||||
@@ -37,7 +37,10 @@ class Striker(object):
|
||||
self.last_speak = None
|
||||
|
||||
def speak(self, text):
|
||||
if (self.tts_thread is None or not self.tts_thread.isAlive() ) and text!=self.last_speak:
|
||||
if (
|
||||
(self.tts_thread is None or not self.tts_thread.isAlive())
|
||||
and text != self.last_speak
|
||||
):
|
||||
self.tts_thread = Thread(
|
||||
target=lambda text: self.speaker.say(str(text)),
|
||||
args=(text,)
|
||||
@@ -45,8 +48,6 @@ class Striker(object):
|
||||
self.tts_thread.start()
|
||||
self.last_speak = text
|
||||
|
||||
|
||||
|
||||
def ball_scan(self):
|
||||
"""Intelligently rotate the robot to search for stuff."""
|
||||
yaw = self.mover.get_head_angles()[0]
|
||||
@@ -68,7 +69,12 @@ class Striker(object):
|
||||
|
||||
def get_ball_angles_from_camera(self, cam):
|
||||
"""Detect the ball and return its angles in camera coordinates."""
|
||||
try:
|
||||
ball = self.ball_finder.find(cam.get_frame())
|
||||
except RuntimeError as e:
|
||||
print(e)
|
||||
return None
|
||||
|
||||
if ball is None:
|
||||
return None
|
||||
|
||||
@@ -153,7 +159,6 @@ class Striker(object):
|
||||
self.mover.move_to(0, 0, yaw)
|
||||
self.mover.wait()
|
||||
|
||||
|
||||
def align_to_ball(self):
|
||||
ball_angles = self.get_ball_angles_from_camera(self.lower_camera)
|
||||
if ball_angles is None:
|
||||
@@ -302,7 +307,6 @@ if __name__ == '__main__':
|
||||
striker.mover.kick()
|
||||
striker.mover.rest()
|
||||
|
||||
|
||||
# perform normal state-machine if no input argument is given
|
||||
# (see diagram above)
|
||||
else:
|
||||
@@ -328,8 +332,6 @@ if __name__ == '__main__':
|
||||
print(ball_in_lower)
|
||||
if (ball_in_lower is not None and ball_in_lower[1] > 0.28):
|
||||
|
||||
#t = Thread(target=striker.speak, args=["Ball is close enough, stop approach"])
|
||||
#t.start()
|
||||
print('Ball is close enough, stop approach')
|
||||
# striker.speak("Ball is close enough stop approach")
|
||||
# striker.mover.stop_moving()
|
||||
@@ -337,7 +339,7 @@ if __name__ == '__main__':
|
||||
state = 'simple_kick'
|
||||
else:
|
||||
print('Continue running')
|
||||
##striker.speak("Continue running")
|
||||
# striker.speak("Continue running")
|
||||
striker.run_to_ball()
|
||||
state = 'tracking'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user