feat: split camera worker and tick worker

This commit is contained in:
2020-08-28 13:39:21 +02:00
parent 955ceb9977
commit 44cb97b44e
2 changed files with 29 additions and 10 deletions

28
cameraworker.py Normal file
View File

@@ -0,0 +1,28 @@
import sched
from redis import Redis
from control.camera import Camera
INTERVAL_TICK = 0.0125 # 20/s
INTERVAL_IMAGE = 0.05 # 20/s
scheduler = sched.scheduler()
camera = Camera()
def camera_image():
scheduler.enter(INTERVAL_IMAGE, 1, camera_image)
image = camera.get_image()
redisdb.publish('image', image)
scheduler.enter(INTERVAL_IMAGE, 1, camera_image)
if __name__ == '__main__':
redisdb = Redis()
try:
scheduler.run()
except KeyboardInterrupt:
raise

View File

@@ -6,10 +6,8 @@ import json
from redis import Redis
from control.walle import WallE
from control.camera import Camera
INTERVAL_TICK = 0.0125 # 20/s
INTERVAL_IMAGE = 0.05 # 20/s
class EventListener(Thread):
@@ -51,23 +49,16 @@ class EventListener(Thread):
scheduler = sched.scheduler()
camera = Camera()
walle = WallE()
walle.setup()
def walle_tick():
scheduler.enter(INTERVAL_TICK, 1, walle_tick)
walle.tick()
def camera_image():
scheduler.enter(INTERVAL_IMAGE, 1, camera_image)
image = camera.get_image()
redisdb.publish('image', image)
scheduler.enter(INTERVAL_TICK, 1, walle_tick)
scheduler.enter(INTERVAL_IMAGE, 1, camera_image)
if __name__ == '__main__':
redisdb = Redis()