Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

[rospy] keep all tf frames with short validity


I need to save the poses of several objects and then perform transformations between them (for instance what was the coordinates of the pen with respect to the table at time t). The fact is that coordinates are not published in real time, they are read from a file publishing the frames of the objects from 0 to 100 seconds.

I would like a cache of, say 100ms, but if I want the transformer not to drop all the first 0 to 99.900 seconds so I cannot use them later. So I need a cache of 100 seconds. But with this long cache a transform is valid during 100 seconds, so when an objects disappears 10 seconds, the lookupTransform continues returning the 10s aged transform , while I would prefer it raises an exception in it's more than 100ms old.

My code is, at the moment, something like: cache_time = 100 # 100 seconds of cache to keep all frames in memory transformer = tf.Transformer(False, cache_time) transform = TransformStamped() transform.header.frame_id = "world"

for line in file:
    (time, obj_name, x, y, z, qx, qy, qz, qw) = line.split()
    transform.child_frame_id = obj_name
    transform.header.stamp = rospy.Time(float(time))
    transform.transform = ... # Fill with x, y, z, qx, qy, qz, qw

for t in all_times:
    print t, transformer.lookupTransform("table", "pen", rospy.Time(t))

I could solve it by doing everything in one pass instead of two, but I would like to separate the step "Reading of frame data" and "Usage of frame data" since the second step may be complicated or done interactively with ipython, etc... I could also use the tf.transformations methods with transforms stored in my own arrays but I'm seduced by the idea of the tf.Transformer being the only data structure that I can talk to to perform transformations.

In my problem I consider two kinds of caches: the duration a frame VALID and the duration a frame is KEPT in memory. I'm afraid this is not the tf philosophy.

Any idea before definitively dropping the tf.Transformer option? Thanks :)