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

tf2 convert transform to msg

asked 2015-04-09 11:49:47 -0600

Michael Stoll gravatar image

This should be a simple task:

#include <tf2/transform_datatypes.h>
#include <geometry_msgs/PoseStamped.h>

...
geometry_msgs::TransformStamped transform = anything;
geometry_msgs::PoseStamped pose;
tf2::convert(transform, pose);
...

So this code should convert the TransformStamped to PoseStamped (similar to tf::poseTFtoMsg). But the compiler complains that toMsg and fromMsg aren't defined. IMO there are some includes missing. Where are toMsg and fromMsg for PoseStamped defined?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2015-04-10 01:13:35 -0600

tfoote gravatar image

updated 2015-04-10 01:14:46 -0600

If you are getting errors with missing definitions that means that you have do not have the correct headers included.

There are tutorials here: http://wiki.ros.org/tf2/Tutorials/Mig...

However you'll find that PoseStamped and TransformStamped do not have conversions defined between them because they contain different data. The convert method is designed for converting homogeneous datatypes between representations in different libraries. Any conversion must be reversible for it to work in this framework.

edit flag offensive delete link more
2

answered 2017-09-14 09:21:51 -0600

bsaund gravatar image

tf2::convert is not designed to convert one message to a different message. http://docs.ros.org/kinetic/api/tf2/h...

Technically, geometry_msgs::Transform and geometry_msgs::Pose are different data, though I frequently find that I want to convert between the two. You can overload "convert" or use a different function name in a helper file.

namespace tf2
{
    inline
    void convert(const geometry_msgs::Transform& trans, geometry_msgs::Pose& pose)
    {
        pose.orientation = trans.rotation;
        pose.position.x = trans.translation.x;
        pose.position.y = trans.translation.y;
        pose.position.z = trans.translation.z;
    }

    inline
    void convert(const geometry_msgs::Pose& pose, geometry_msgs::Transform& trans)
      {
        trans.rotation = pose.orientation;
        trans.translation.x = pose.position.x;
        trans.translation.y = pose.position.y;
        trans.translation.z = pose.position.z;
    }

    inline
    void convert(const geometry_msgs::TransformStamped& trans, geometry_msgs::PoseStamped& pose)
    {
        convert(trans.transform, pose.pose);
        pose.header = trans.header;
    }

    inline
    void convert(const geometry_msgs::PoseStamped& pose, geometry_msgs::TransformStamped& trans)
    {
        convert(pose.pose, trans.transform);
        trans.header = pose.header;
    }
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-04-09 11:49:47 -0600

Seen: 9,653 times

Last updated: Sep 14 '17