How to transform tf::Vector3 with tf::TransformationListener? [closed]

asked Dec 12 '14

Sheridan Vespo gravatar image

I am trying to convert a tf::Vector3 with tf::TransfomationListener::transformVector(string("/base_link"), sourceV, targetV). What I get is the following:

*no known conversion for argument 2 from 'const tf::Vector3' to 'const Vector3Stamped& {aka const geometry_msgs::Vector3Stamped_<std::allocator<void> >&}' *

Ok, so I figured I need a Stamped version of my vector. I tried this:

tf::Stamped<tf::Vector3> sv(sourceV, ros::Time(), string("/odom"));

and got this:

no known conversion for argument 2 from 'tf::Stamped<tf::vector3>' to 'const Vector3Stamped& {aka const geometry_msgs::Vector3Stamped_<std::allocator<void> >&}'

Then I realized that it is requesting geometry_msgs::Vector3Stamped. How come the transformation listener from tf doesn't take tf::Vector3?

Ok, then I tried to get the right type:

    geometry_msgs::Vector3Stamped gV;
    gV.vector = sourceV;
    gV.header.stamp = ros::Time();
    gV.header.frame_id = "/odom";

This resulted in:

no match for 'operator=' (operand types are 'geometry_msgs::Vector3Stamped_<std::allocator<void> >::_vector_type {aka geometry_msgs::Vector3_<std::allocator<void> >}' and 'const tf::Vector3')

In the end my code looked like this:

    geometry_msgs::Vector3Stamped gV, tV;
    gV.vector.x = sourceV.x();
    gV.vector.y = sourceV.y();
    gV.vector.z = sourceV.z();
    gV.header.stamp = ros::Time();
    gV.header.frame_id = "/odom";
    getTransformListener()->transformVector(string("/base_link"), gV, tV);
    targetV.setX(tV.vector.x);
    targetV.setY(tV.vector.y);
    targetV.setZ(tV.vector.z);

Even though I think this should be a one-liner without all that unnecessary object creation and assigment:

    getTransformListener()->transformVector(string("/base_link"), sourceV, targetV);

Question:

Is the one-liner somehow possible? Is there another easy way to do this that I am missing?

Preview: (hide)

Closed for the following reason duplicate question by dornhege
close date 2014-12-12 11:24:49.529752