forked from iplayfast/zoidberg
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrealsense_node.py
40 lines (28 loc) · 1.05 KB
/
realsense_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from time import sleep
import messenger
from realsense_distance import CaptureDistance
class RealSenseNode(messenger.Node):
def __init__(self, mock=False, run=True, silent=True) -> None:
super().__init__('realsense')
self.publisher = messenger.Publisher('/distance/realsense', messenger.Messages.float)
self.silent = silent
self.mock = mock
if not mock:
self.sensor = CaptureDistance()
self.iter = iter(self.sensor)
if run:
print("realsense looper")
self.loop(35)
def step(self):
if self.mock:
return
is_running = next(self.iter, None)
if not is_running:
exit()
self.publisher.publish(self.sensor.distance)
delay = 2.5 if self.sensor.distance else 4
self.loginfo_throttle(delay, f"dist: {self.sensor.distance or 0:.1f} area: {self.sensor.area:.1f}, fps: {self.sensor.fps:.0f}")
if __name__ == '__main__':
node = RealSenseNode(mock=False, run=False)
messenger.test()
node.loop(30)