This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
forked from sshane/openpilot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
msg_sync.py
executable file
·60 lines (49 loc) · 1.6 KB
/
msg_sync.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
from cereal import car
from common.params import Params
import cereal.messaging as messaging
import os
import cereal.messaging.messaging_pyx as messaging_pyx
import time
from cereal import log
import threading
import numpy as np
import math
def msg_sync_thread():
#start_sec = round(time.time())
sync_topics = ['modelV2', 'carState', 'liveTracks', 'radarState', 'controlsState']
# dMonitoringState', 'gpsLocation', 'radarState', 'model', 'gpsLocationExternal',
# 'pathPlan', 'liveCalibration', laneSpeed
frame_counts = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
SLEEP_TIME = 0.01
frame_limits = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
sub_list = []
pub_list = []
for topic in sync_topics:
sub_list.append(messaging.sub_sock(topic, conflate=True, timeout=100))
os.environ["ZMQ"] = "1"
pub_context = messaging_pyx.Context()
for topic in sync_topics:
pub = messaging_pyx.PubSocket()
pub.connect(pub_context, topic)
pub_list.append(pub)
del os.environ["ZMQ"]
while True:
for index, sub in enumerate(sub_list):
try:
data = sub.receive()
if data:
#print ('sending data ' + sync_topics[index])
frame_limit = frame_limits[index]
if frame_limit != 0 and (frame_counts[index] % frame_limit != 0):
pass
else:
pub_list[index].send(data)
frame_counts[index] += 1
except messaging_pyx.MessagingError:
print('msg_sync MessagingError error happens ' + sync_topics[index])
time.sleep(SLEEP_TIME)
def main():
msg_sync_thread()
if __name__ == "__main__":
main()