Ask Your Question

How to transform tf::Vector3 with tf::TransformListener::transformVector?

asked 2014-12-12 10:49:36 -0600

Sheridan Vespo gravatar image

I am trying to convert a tf::Vector3 with tf::TransfomListener::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);

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);


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

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-12-12 13:12:05 -0600

tfoote gravatar image

When you call the tf API the datatypes need to match, source and target. (tf2 supports implicit conversion but not tf.) Make sure that they both match and are stamped.

The assignment does not work between a tf datatype and geometry_msgs datatypes. You need to use the conversion functions:

edit flag offensive delete link more


Are there python equivalents of these functions available?

RohitM gravatar imageRohitM ( 2017-03-31 04:20:36 -0600 )edit

answered 2014-12-12 11:27:17 -0600

dornhege gravatar image

The API says this should work:

I suspect your output/target vector just has the wrong type. It also has to be a stamped type.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-12-12 10:49:36 -0600

Seen: 2,590 times

Last updated: Dec 12 '14