Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mgineer85 committed Oct 30, 2024
1 parent 32d5f06 commit d9a0510
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions node/services/backends/cameras/picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ def clamp(n, min_value, max_value):

def recover(self):
tms = time.time()
for _ in range(2): # 2 is size of buffer so tick->clear no processing.
pass
## self._event_request_tick.wait(timeout=2.0)
self._queue_timestamp_monotonic_ns.get(block=True, timeout=2)
self._queue_camera_timestamp_ns.get(block=True, timeout=2)
## self._picamera2.drop_frames(1, wait=True) # on start drop all old frames...
for _ in range(4): # 2 is size of buffer so tick->clear no processing.
try:
self._queue_timestamp_monotonic_ns.get(block=True, timeout=2.0)
self._queue_camera_timestamp_ns.get(block=True, timeout=2.0)
except Exception:
pass

logger.info(f"recovered, time taken: {round((time.time() - tms)*1.0e3, 0)}ms")

Expand Down Expand Up @@ -279,35 +279,22 @@ def _camera_fun(self):
logger.debug("starting _camera_fun")

while not current_thread().stopped():
job = self._picamera2.capture_request(wait=False)

try:
request = self._picamera2.wait(job, timeout=2.0)
except TimeoutError: # no information in exc avail so omitted
logger.warning("timeout while waiting for clock/camera")
# break thread run loop, so the function will quit and .alive is false for this thread -
# supervisor could then decide to start it again.
break

if self._capture.is_set():
self._capture.clear()
self._capture_in_progress = True

tms = time.time()
self._queue_processing.put(request.make_buffer("main"))
time.sleep(0.5)
self._queue_processing.put(self._picamera2.capture_buffer("main", wait=2.0))
logger.info(f"queued up buffer to process image, time taken: {round((time.time() - tms)*1.0e3, 0)}ms")
self._capture_in_progress = False

else:
picam_metadata = request.get_metadata()
picam_metadata = self._picamera2.capture_metadata(wait=2.0)
try:
self._queue_camera_timestamp_ns.put_nowait(picam_metadata["SensorTimestamp"])
except Full:
logger.warning("could not queue camera timestamp!")

request.release()

logger.info("_camera_fun left")

def _processing_fun(self):
Expand Down

0 comments on commit d9a0510

Please sign in to comment.