Ask Your Question

Revision history [back]

In your first example, you make a tf::StampedTransform to hold the transform, then use transformTFToMsg to put it into a message object.

In the second example, tf2 is _already_ returning a geometry_msgs::TransformStamped message type (instead of a StampedTransform object). So you're trying to convert a message to a message. You're effectively doing this:

geometry_msgs::TransformStamped transformStamped;
geometry_msgs::Transform tt;
tf::transformTFToMsg(transformStamped, tt);

But those are both message types, so you don't need to do that at all. You have two options:

  1. Use transformStamped instead of tt in the rest of your code, since they are both messages.
  2. Just do this:

    geometry_msgs::TransformStamped transformStamped;
    <your transform try/catch block>
    geometry_msgs::Transform tt = transformStamped.transform;
    

In your first example, you make a tf::StampedTransform to hold the transform, then use transformTFToMsg to put it into a message object.

In the second example, tf2 is _already_ already returning a geometry_msgs::TransformStamped message type (instead of a StampedTransform object). So you're trying to convert a message to a message. You're effectively doing this:

geometry_msgs::TransformStamped transformStamped;
geometry_msgs::Transform tt;
tf::transformTFToMsg(transformStamped, tt);

But those are both message types, so you don't need to do that at all. You have two options:

  1. Use transformStamped instead of tt in the rest of your code, since they are both messages.
  2. Just do this:

    geometry_msgs::TransformStamped transformStamped;
    <your transform try/catch block>
    geometry_msgs::Transform tt = transformStamped.transform;