tf2_ros.Buffer.transform() in Python (Tutorial is lacking?)
Situation
I have the following rough TF(2) setup (simpified):
odom -> base_link -> tool_link
where
odom
is generated by the diff drive controller from here.base_link
is the "root" of my mobile base (ie it moves around)tool_link
is the tf frame of a tool into which I want to transform coordinates
Now I would like to transform sensor measurements that I receive as PoseStamped
messages in the odom
frame into the tool_link
frame.
What I tried
- I followed the Python tutorials until here (writing a tf2 listener in Python). The solution seems to be at the bottom of the page. However, the MessageFilter approach mentioned there only contains an example for C++.
- Searching rosanswers brought up this - where the guy just implemented his own filter in python. The answer is also pretty old so Id hope that there is something more recent?
The Current Code
My code follows the abovementioned tutorial, ie (stripped down version):
import tf2_ros
tfBuffer = tf2_ros.Buffer()
listener = tf2_ros.TransformListener(tfBuffer)
try:
trans = tfBuffer.lookup_transform(turtle_name, 'turtle1', rospy.Time())
# MARKER (Transform point here? See below)
except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException):
continue
This works so far. However, it leaves me with a transform message that I would still need to apply to the input message The problem here is basically this - but that answer is for tf1. For tf2, as far as I understand the following should be used to transform a PointStamped (and therefore be inserted at MARKER in the above code):
tfBuffer.transform(pose_stamped_to_be_converted, "tool_link", timeout=rospy.Duration(10.0))
But that line fails with
Lookup would require extrapolation into the past. Requested time 166.496000000 but the earliest data is at time 170.614000000, when looking up transform from frame [odom] to frame [m2_blade_horizon]
The delta between requested and earliest time is always in the range above ~2-8s. As you can see I have picked a very large timeout (to hopefully rule out this), even though the tf publishers for the revelant frames at all running at 10+Hz.
Questions
- How do I get the above transform to work (actually using tf2 - what is the point of using tf2 if I still have to do the transform myself?)
- Is there any tf2 python documentation that I missed?
- Was an "official" python message filter developed in the meantime?