Skip to content

Commit

Permalink
stop device properly when clock got inavailable or any of the device …
Browse files Browse the repository at this point in the history
…threads broke.
  • Loading branch information
mgineer85 committed Nov 23, 2024
1 parent 2947c66 commit 2e2d99d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ The primary node has a display attached and is responsible to generate the clock
Edit `~/.env.primary` and place following for the reference 3d printed wigglecam:

```sh
# enable clock generator on primary:
# enable clock generator and trigger forwarding on primary:
acquisition__is_primary="True"
# io config:
acquisition__io_backends__active_backend="Gpio" # default "VirtualIo"
acquisition__io_backends__gpio__fps_nominal=5
acquisition__io_backends__gpio__pwmchip="pwmchip0" # or pwmchip2 for Pi5
acquisition__io_backends__gpio__pwm_channel=0 # or 2 for Pi5
# cam config:
acquisition__camera_backends__active_backend="Picamera2" # default "VirtualCamera"
acquisition__camera_backends__picamera2__enable_preview_display="True"
```

Expand Down
9 changes: 9 additions & 0 deletions wigglecam/services/acquisitionservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,22 @@ def _clock_impulse_detected(self, timeout: float = None):

def _supervisor_fun(self):
logger.info("device supervisor started, checking for clock, then starting device")
flag_stopped_orphaned_already = False

while not current_thread().stopped():
if not self._device_alive():
if not flag_stopped_orphaned_already:
# to ensure after device was not alive (means just 1 thread stopped), we stop all threads
self._device_stop()
flag_stopped_orphaned_already = True

if not self._clock_impulse_detected(timeout=2.0):
# loop restart until we got an impulse from master
time.sleep(1)
continue

flag_stopped_orphaned_already = False

logger.info("got clock impulse, continue starting...")

try:
Expand Down Expand Up @@ -227,6 +235,7 @@ def _sync_fun(self):
except TimeoutError:
# stop devices when no clock is avail, supervisor enables again after clock is received, derives new framerate ans starts backends
logger.warning("clock signal missing.")
self._device_stop() # if device was started once, stop here all before waiting for restart...
break
else:
self._camera_backend.sync_tick(timestamp_ns)
Expand Down

0 comments on commit 2e2d99d

Please sign in to comment.