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

truncating ros time

asked 2018-10-09 14:25:48 -0600

lahiruherath gravatar image

updated 2018-10-09 14:52:33 -0600

Hi, Is there anyway i could truncate the ros time value to certain length, lets say i need the time value to be only up to a certain decimal points

edit retag flag offensive close merge delete



So you want to reduce the precision of timestamps by truncating them?

If so, could I ask you for a topic title change? Right now it seems like you're asking about the precision of rostime and/or ROS timestamps. But that is not actually the case.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-09 14:45:00 -0600 )edit

And to avoid an xy-problem: can you describe why you'd want to do this?

gvdhoorn gravatar image gvdhoorn  ( 2018-10-09 14:45:25 -0600 )edit

Hi, I want to stop tf from looking into the exact time stamp to find a transform

lahiruherath gravatar image lahiruherath  ( 2018-10-09 14:51:30 -0600 )edit

And why do you want to do that? What is it exactly that you are trying to achieve?

gvdhoorn gravatar image gvdhoorn  ( 2018-10-09 14:57:31 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-10-09 16:23:55 -0600

updated 2018-10-10 03:56:44 -0600

I'll jump in here because I think exactly how the TF system works needs to be clarified.

TF doesn't look for a transform with exactly the right time stamp when you lookup a transform, it almost always interpolates the two nearest TF samples. It can also extrapolate into the future a short time based on previous data but this is not recommended.

Are you getting the Lookup would require extrapolation at time X error? In this case adding a timeout Duration to the lookupTransform call would be the preferred method of solving this.

But as @gvdhoorn says, it would be helpful to know the actual problem you're trying to solve before we can suggest the best solution for you.


Thanks for clarifying the problem you're trying to solve, I see two possible solutions you can look into.

  1. Use message filters to synchronise the messages as @tfoote has suggested

  2. You could request the most recent data when looking up the transform by setting the time to zero. This achieves exactly what you suggested initially via a different mechanism.

Hope this helps.

edit flag offensive delete link more


Hi Peter,

I know this, lemme explain my specific problem.

I have depth image from a sensor which i actually get using a another API and I convert to a ROS message. The odometry is also taken similarly and tf is broadcasted, I assign the time stamps myself. They are running on two separate threads.

lahiruherath gravatar image lahiruherath  ( 2018-10-09 16:37:22 -0600 )edit

The time stamps do not match because of this, I convert the depth to PCL and i need to transform it to another frame. The lookup gives an error. I cannot hang my conversion until a transform is taken. I just need to find a way to transform it in some viable rate. My sensors run on 15-25 Hz

lahiruherath gravatar image lahiruherath  ( 2018-10-09 16:40:44 -0600 )edit

So a time stamp in this range is okay for me. So i thought i would cap the initial stamp at some decimal place. Don't know whether it is viable or possible. Or maybe I'm just shooting in some uselss direction.

lahiruherath gravatar image lahiruherath  ( 2018-10-09 16:44:59 -0600 )edit

From your use case you should not be truncating your timestamps. What you're trying to do is basically extrapolate into the future by a small bit, but rounding all your timestamps. This has been explored many times and almost always leads to unintended consequences.

tfoote gravatar image tfoote  ( 2018-10-09 19:20:20 -0600 )edit

You cannot apply a transform until the data is available. It can actually make a difference when during the 40ms between a 25Hz signal is processed. I'd strongly recommend that you look at using a Message Filter in your pipeline to hold the data for the few milliseconds until the data is available.

tfoote gravatar image tfoote  ( 2018-10-09 19:22:08 -0600 )edit

And this was exactly why I asked about the xy-problem.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-10 01:22:34 -0600 )edit

@tfoote, Thanks didn't know about this message filter. Another small question what's your advice use tf since pcl_ros still has tf in its conversions, or shift to tf2?

lahiruherath gravatar image lahiruherath  ( 2018-10-10 05:11:25 -0600 )edit

Question Tools



Asked: 2018-10-09 14:25:48 -0600

Seen: 603 times

Last updated: Oct 10 '18