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

transformStamped get rotation

asked 2016-06-18 05:50:28 -0500

inflo gravatar image

updated 2016-06-18 07:05:28 -0500

hi, when i got this code

    geometry_msgs::TransformStamped transformStamped;
        try{
          transformStamped = tfBuffer.lookupTransform("tf-a", "tf-b",
                                   ros::Time(0));
        }
        catch (tf2::TransformException &ex) {
          ROS_WARN("%s",ex.what());
          ros::Duration(1.0).sleep();
          continue;
        }
double roll, yaw,pitch;
     tf::Quaternion q();
     q = transformStamped.transform.getRotation();
     tf::Matrix3x3 m(q)
     m.getRPY(roll,yaw,pitch);

     ROS_INFO("angles in degree: roll >%f<, yaw >%f<, pitch >%f<", roll, yaw, pitch);

it returns:

  error:
 ‘geometry_msgs::TransformStamped_<std::allocator<void>
 >::_transform_type’ has no member named ‘getRotation’
       q = transformStamped.transform.getRotation();

but here http://answers.ros.org/question/19340... its used ? Also transformStamped.getRotation() does not work.

i simply want to get the angle between both tf frames in degree ? but how?

thanks

EDIT: this code works for me, if there is better way, please tell me:

 double r,y,p;
 double d1,d2,d3;
 geometry_msgs::Quaternion q = transformStamped.transform.rotation;
 tf::Quaternion tfq;
 tf::quaternionMsgToTF(q, tfq);
 tf::Matrix3x3(tfq).getEulerYPR(y,p,r);
 d1 = angles::to_degrees(y);
 d2 = angles::to_degrees(p);
 d3 = angles::to_degrees(r);
 ROS_INFO("euler-angles::to_deg y >%f<, p >%f<, r >%f<", d1, d2, d3);
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2016-06-18 06:58:15 -0500

updated 2016-06-18 08:04:17 -0500

You are confusing the data types (well, they are confusing indeed).

There is geometry_msgs::TransformStamped and tf::StampedTransform in ROS. The first is just a container (C++ ROS message representation) used for data serialization, while the second is a full-featured class that allows to manipulate transformation matrices etc.

The code you gave the link to is using tf::StampedTransform. Also it uses the old tf methods, where lookupTransform accepts only tf data types and has the following signature:

void lookupTransform(const std::string& target_frame, const std::string& source_frame,
                       const ros::Time& time, StampedTransform& transform) const;

while the one you are trying to use is from tf2:

virtual geometry_msgs::TransformStamped 
    lookupTransform(const std::string& target_frame, const std::string& source_frame,
                    const ros::Time& time, const ros::Duration timeout) const;

P.S. Most of the examples you find on ROS Answers are likely to be for previous version of tf.


EDIT:

If the only thing you need is Euler angles, then it is enough. Though, if you are going to work with the whole transform, then it is better to convert the whole geometry_msgs::TransformStamped to tf::StampedTransform, or acquire the latter directly with tf::lookupTransform (in tf1).

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-06-18 05:50:28 -0500

Seen: 4,272 times

Last updated: Jun 18 '16