ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Get mean of two ros::Time stamps

asked 2015-03-20 11:38:17 -0500

luator gravatar image

Given two ros::Time instances t1 and t2. What is the easiest, clearest way to compute the mean them, that is the time that is in the middle between t1 and t2?

The obvious solution (t1 + t2) / 2 does unfortunately not work, as + is undefined for two ros::Time instances.

My second idea, t1 + (t2 - t1) / 2 does still not work. The subtraction and addition work, but it will fail on the division.

Of course, I could just convert the time stamps to seconds to do the calculation, but I wonder if there is a nicer way, using ros::Time.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-03-20 19:03:11 -0500

This appears to work:

ros::Time start;
ros::Time end;

ros::Time mid = start + (end - start) *0.5;

You can only add a Duration to a time (and subtracting one Time from another gives a Duration).

edit flag offensive delete link more


Strange, that multiplication is implemented but division is not... Thanks a lot.

luator gravatar image luator  ( 2015-03-27 04:11:41 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-03-20 11:38:17 -0500

Seen: 830 times

Last updated: Mar 20 '15