-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubscriber.py
More file actions
40 lines (34 loc) · 1.01 KB
/
subscriber.py
File metadata and controls
40 lines (34 loc) · 1.01 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
#!/usr/bin/env python
import rospy
from std_msgs.msg import Header
import time, threading
average = 0.0
counter = 0
counter_througput = 0.0
def callback(msg):
global average
global counter
global counter_througput
receive_time = rospy.Time.now().to_nsec()
send_time = msg.stamp.to_nsec()
# Calculate the latency
latency = receive_time - send_time
counter = counter +1
average = average + latency
counter_througput = counter_througput +1
if counter == 1000:
rospy.loginfo("Received message with latency: %f ns", average/100.0)
counter = 0
average = 0
def msg_throuput():
global counter_througput
print("Message delivered ",counter_througput)
counter_througput = 0
threading.Timer(1, msg_throuput).start()
def listener():
rospy.init_node('listener', anonymous=True)
rospy.Subscriber('chatter', Header, callback)
msg_throuput()
rospy.spin()
if __name__ == '__main__':
listener()