-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathsync_scripts.py
More file actions
53 lines (42 loc) · 1.29 KB
/
sync_scripts.py
File metadata and controls
53 lines (42 loc) · 1.29 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
import depthai as dai
import time
from datetime import timedelta
pipeline = dai.Pipeline()
script1 = pipeline.create(dai.node.Script)
script1.setScript("""
from time import sleep
while True:
sleep(1)
b = Buffer(512)
b.setData(bytes(4 * [i for i in range(0, 128)]))
b.setTimestamp(Clock.now())
node.io['out'].send(b)
""")
script2 = pipeline.create(dai.node.Script)
script2.setScript("""
from time import sleep
while True:
sleep(0.3)
b = Buffer(512)
b.setData(bytes(4 * [i for i in range(128, 256)]))
b.setTimestamp(Clock.now())
node.io['out'].send(b)
""")
sync = pipeline.create(dai.node.Sync)
sync.setSyncThreshold(timedelta(milliseconds=100))
xout = pipeline.create(dai.node.XLinkOut)
xout.setStreamName("xout")
sync.out.link(xout.input)
script1.outputs["out"].link(sync.inputs["s1"])
script2.outputs["out"].link(sync.inputs["s2"])
# script1.outputs["out"].link(xout.input)
with dai.Device(pipeline) as device:
print("Start")
q = device.getOutputQueue("xout", maxSize=10, blocking=True)
while True:
grp = q.get()
for name, msg in grp:
print(f"Received {name} with timestamp {msg.getTimestamp()}")
print(f"Time interval between messages: {grp.getIntervalNs() / 1e6}ms")
print("----------")
time.sleep(0.2)