ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

how to sync two ROS topics by adjusting the time stamp

asked 2016-05-13 03:09:14 -0500

A G gravatar image

updated 2016-05-18 02:37:16 -0500

Actual Issue: I have a topic published with images from a camera and another topic with details of point cloud. When I plot these two topics, there is a time lag between the two plots. Is there any method to synchronize this time lag by adjusting the time stamp of point cloud message?

I am using rosbag play for the above mentioned purpose.

Re-creating the Scenario I tried to simulate the above scenario using the below mentioned points: i. Created a subscriber node which subscribe to the topic(/point_cloud) with point cloud data. ii. Inside the callback function, I copied the message to a new pointer variable of the same type (sensor_msgs::PointCloud2) and incremented the timestamp by 3sec (The debug print shows that the timestamp has been successfully updated). iii. Then I published the modified point cloud data in a new topic(/point_cloud_new). iv. Created two instances of rviz which subscribes to the two topics, /point_cloud and /point_cloud_new respectively. v. Since the timestamp of /point_cloud_new was incremented by 3sec, I expected a 3sec delay between the two plots in the rviz. But it is not happening.

Since I am new to ROS, I am not sure whether it is the correct method to approach this issue. Please comment on the actual issue and the scenario re-created.

Please help me to sort out this issue.

edit retag flag offensive close merge delete


When you play the bag file are you setting the parameter use_sim_time to true? That will be a required step for time synchronization when using bag files.

Thomas D gravatar image Thomas D  ( 2016-05-13 17:47:22 -0500 )edit

Yes. I set use_sim_time to true and I am using --clock option while playing the rosbag.

A G gravatar image A G  ( 2016-05-14 20:25:55 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-05-13 04:02:33 -0500

mgruhler gravatar image

updated 2016-05-13 04:02:43 -0500

Typically, you use a TimeSynchronizer for this issue. See the wiki for details.

edit flag offensive delete link more


Thanks, mig. I tried the above mentioned option. But it didn't work. Also i found a similar issue in the link mentioned below: I even tried with approximate time policy mentioned in the above link.

A G gravatar image A G  ( 2016-05-13 05:35:12 -0500 )edit

An addition to the above comment: When I tried with the TimeSynchronizer and ApproximateTimePolicy method , the behavior was like the callback function was never called.

A G gravatar image A G  ( 2016-05-15 20:45:07 -0500 )edit

Thanks @mig! Approximate time policy mentioned in your link worked. But I have to increment the timestamp of point cloud by 5sec using a subscriber node before passing it on to the TimeSynchronizer. Otherwise the callback function has never been called!

A G gravatar image A G  ( 2016-05-18 02:06:12 -0500 )edit

@mig@Thomas D New issue-If I play rosbag with the loop option,the 1st loop will work,but during 2nd loop,callback function is not called.similar to the issue mentioned in the link Please help me with your suggestions

A G gravatar image A G  ( 2016-05-18 02:13:58 -0500 )edit

can't help you there. Also, for a new issue/question, please open a new one.

mgruhler gravatar image mgruhler  ( 2016-05-18 02:17:59 -0500 )edit

ok. Thanks mig!

A G gravatar image A G  ( 2016-05-18 02:27:32 -0500 )edit

Did you find a solution ?

Master_Matrix gravatar image Master_Matrix  ( 2023-07-21 11:43:17 -0500 )edit

Question Tools



Asked: 2016-05-13 03:09:14 -0500

Seen: 7,633 times

Last updated: May 18 '16