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

tf2_ros::Buffer.transform() missing timestamp

asked 2020-09-14 07:50:19 -0500

dimitri gravatar image

updated 2020-09-24 09:03:36 -0500

Hello everyone I use tf2_ros::Buffer.transform() to transform a geometry_msgs::WrenchStamped into ageometry_msgs::WrenchStamped in another frame at the same time. So the syntax is:

tf2_ros::Buffer.transform(geometry_msgs::WrenchStamped wrenchStamped1, geometry_msgs::WrenchStamped wrenchStamped2, const std::string & target_frame, ros::Duration timDur);

It seems to work fine but the wrenchStamped2 has an empty timestamp. Is this on purpose by the function and do I need to manually assign the timestamp?

The code looks basically like this (msg is the message from the subscriber callback function this code snippet is part of):

 geometry_msgs::WrenchStamped msgWrench = msg->wrench;
 msgWrench.header = msg->header;
 msgWrench.header.frame_id = "EE_FORCETORQUESENSOR";

 geometry_msgs::WrenchStamped worldFrameWrenchFTSensorStamped;
  try 
  {
    ros::Duration timDur(0.1);
    std::string target_frame_("world");
    buffer_.transform(msgWrench, worldFrameWrenchFTSensorStamped, target_frame_, timDur);
  }
  catch (tf2::TransformException &ex) 
  {
    ROS_WARN("Failure %s\n", ex.what()); //Print exception which was caught
  }

  worldFrameWrenchFTSensorStamped.header = msgWrench.header;
edit retag flag offensive close merge delete

Comments

1

Can you provide the actual code in which you're using your tf2_ros::Buffer object? Just the surrounding function or a few lines above and below would help.

Josh Whitley gravatar image Josh Whitley  ( 2020-09-15 23:09:39 -0500 )edit

Sorry. I added the code. I hope it is clear what i am doing there.

dimitri gravatar image dimitri  ( 2020-09-24 09:04:19 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2020-09-24 11:41:12 -0500

Josh Whitley gravatar image

updated 2020-09-24 11:41:50 -0500

tf2_ros::Buffer.transform() is a templated function that calls tf2::doTransform(in, out, lookupTransform(target_frame, tf2::getFrameId(in), tf2::getTimestamp(in), timeout)); under the hood. The lookupTransform() part is the one we care about here, because it is the one that generates a geometry_msgs::TransformStamped with a timestamp that gets passed to doTransform. Through a few redirections, this eventually ends up with a call to BufferCore::doTransform() here. Looking at that function doesn't help a ton because it requires knowledge of how the TF frame cache works, but, essentially, if both the input WrenchStamped and the TF that gets published between the two frames have valid timestamps, the output WrenchStamped should have a valid timestamp too. Verify this on both of those messages - I'm guessing this will point to the source of your problem.

edit flag offensive delete link more

Comments

Thanks. You were right. The problem was not with the code but with the data in the messages I was using.

dimitri gravatar image dimitri  ( 2020-09-25 04:27:58 -0500 )edit
2

answered 2020-09-24 18:19:06 -0500

tfoote gravatar image

Looking at your code, you're continuing even if the exception happens. You should not continue processing after you catch the exception. That's an exception and will not have changed the worldFrameWrenchFTSensorStamped data values, which will consequently be zero as you're describing. Which is the most likely reason for a zero time stamp as you describe.

Please see the tf2 tutorials to make sure that you're catching the exceptions properly, as well as potentially using a MessageFilter to hold data until the transform is available.

edit flag offensive delete link more

Comments

Thanks for pointing that out. It wasn't the reason for the problem but it was obviously wrong to not return after the exception was thrown.

dimitri gravatar image dimitri  ( 2020-09-25 04:28:58 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2020-09-14 07:50:19 -0500

Seen: 847 times

Last updated: Sep 24 '20