# How to get unix/posix time stamp in header of ROS msg?

I am using two sensors each connected to different machine (each machine separately runs Ubuntu 16.04 and ROS Kinetic). When I echo topic on these two machines, I see the time stamps in header of messages are different. Even though they are running at the same time. So I faced issues in synchronizing topics recorded on different machines.

Machine 1: sec 4583 | nsec 855689180

Machine 2: sec 1570727234 | nsec 4864000

It seems that the time stamp on machine 1 is based on sim_time. Machine 2 is showing a Posix/Unix time stamp. So on machine 1, I issued the command rosparam set /use_sim_time false. Still when I fire the node on machine 1, time stamp starts from zero which is sim_time.

What I need is to get all time stamps in unix/posix format (10 digit).

P.S. the node running on Machine 1 is OS-1 Lidar Ros Driver

You do not state which topic you are looking at - this answer assumes that you are looking at the pointcloud topic published by the cloud node.

The ROS message time of the pointclouds is not the host system time, but is taken from the lidar's internal clock (see batch_and_publish lambda in os1_cloud_node.cpp and trace back where scan_ts variable comes from).

The ROS message time of the packets is taken from the host system, so if these exhibit the problem you described then I would assume that your problem is indeed with the host time. If not, then your problem is with the lidar clock(s) which you probably want to sync with the host (or some other clock) e.g. via PTP - there are instructions in the software manual.

The times in your machines are a bit different. Even if you convert the times it is highly possible that you still have the problem of synchronizing these two topics. One way is that look at one of the topics as the main. On the other topic subscribe to the main one and change its time as the main. Or if you are working by these two in a third machine write an interface node for both and set the time as ros::time::now().

• This solution usually doesn't work as per two general cases: 1) ONLINE: ROS nodes/sensors running on two separate machines (mobile stations) are not able to communicate sensor data in real time, so one cannot subscribe to other one. 2) OFFLINE: when two rosbag files are collected from two machines, even processing them on a third machine, writing an interface or having one of nodes subscribed to the topic of second node won't guarantee synchronization as it actually depends on if we have issued rosbag record command on two machines at the same time or not.
– fhm
Nov 6, 2019 at 15:59
• So I wish to get Posix-based stamps on two bag files recorded on two machines, with the assumption that both machines are already synced with an external NTP server. Given that, I guess the time difference on two bag file would be within ms or ns scale. Correct me please, if I am wrong.
– fhm
Nov 6, 2019 at 16:06
• I had an Xtion RGBD-camera on my robot which sents its data to the ground station. On the ground station, I had faced by time error between my PC (which wants to run SLAM) and received data. By setting the received data time to the current time my problem solved. I do not have any idea about your NTP solution. I will be happy to see its result! Nov 6, 2019 at 16:20