feat: split camera worker and tick worker
This commit is contained in:
28
cameraworker.py
Normal file
28
cameraworker.py
Normal 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
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user