Negative Time Difference Across Machines

asked 2019-02-16 13:35:13 -0600

humanoid3 gravatar image

updated 2019-02-16 13:49:56 -0600

Hi,

My current ROS kinetic setup has a ROS master running on the robot which I can access on my laptop when they are connected to the same Wifi network.

I have been trying to quantify the delay between publishing a topic on my laptop and subscribing to the topic on the robot.

The talker node on my laptop uses the following code to publish the time before the topic is sent:

while not rospy.is_shutdown():
    send = Time()
    current_time = rospy.Time.now()
    send.data = current_time
    pub.publish(send)
    rate.sleep()

Thee listener node on the robot uses the following code to find the difference between the time when the topic was published by the talker and the time when the topic was received by the listener:

def callback(data):
    now = rospy.Time.now()
    time_before = float(data.data.nsecs)/10**9 + float(data.data.secs)
    time_now = float(now.nsecs)/10**9 + float(now.secs)
    print(time_now - time_before)

For some reason the difference in time is always negative, meaning the current time is always less than the time before the topic was published. I spent hours debugging but have no idea what the issue is. Any help would be greatly appreciated.

SOLUTION : Soon after posting this, I found a solution. I installed Chrony on both the robot computer and my laptop and followed instructions on page 52 of The PR2 Manual: https://www.clearpathrobotics.com/wp-... .

edit retag flag offensive close merge delete

Comments

1

Please post your SOLUTION section as an answer and accept your own answer. It's very easy to miss as-is and does not clearly signal that your problem was solved.

gvdhoorn gravatar image gvdhoorn  ( 2019-02-17 04:42:17 -0600 )edit

As to multi-host ROS node graphs: yes, syncing clocks is almost always necessary for that to work properly.

How would you be able to compare/correlate timestamps on data from one host to the other otherwise?

gvdhoorn gravatar image gvdhoorn  ( 2019-02-17 04:43:02 -0600 )edit