I am running the while True
loop in a separate thread. I don't want to close the connection to the camera, not sure why it closes.
Here's an example of what that looks like:
def start_stream(self):
self.stream_running = True
def streaming():
with self.device:
encoded = self.device.getOutputQueue("encoded", maxSize=30, blocking=True)
try:
while self.stream_running: #when this loop breaks, it closes connection to the cam
if encoded.has():
data = encoded.get().getData()
self.server.send_data(data) # This is defined in a separate class
except Exception as e:
rospy.logerr(f"Exception: {e}")
self.oak_thread = threading.Thread(target=streaming)
self.oak_thread.start()
def stop_stream():
self.stream_running = False
if self.oak_thread and self.oak_thread.is_alive():
self.oak_thread.join(timeout=5.0)
I monitor if the device is closed in a separate function:
while not rospy.is_shutdown():
if self.device.isClosed():
rospy.logerr('connection was closed.')
self.initalize_camera() # This function establishes the connection and create the DAI pipeline