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

Quaternion to RPY ROS2

asked 2019-12-09 16:54:17 -0500

LeoE gravatar image

updated 2019-12-09 16:54:56 -0500

In ROS1 we had the possibility to calculate RPY-euler angles from quaternion using tf like this:

tf::Quaternion q(
        msg->pose.pose.orientation.x,
        msg->pose.pose.orientation.y,
        msg->pose.pose.orientation.z,
        msg->pose.pose.orientation.w);
    tf::Matrix3x3 m(q);
    double roll, pitch, yaw;
    m.getRPY(roll, pitch, yaw);

Is there any similar way to do it in ROS2? And if so which file do I have to include? I'm using ROS2-dashing in C++

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-12-10 10:08:12 -0500

allenh1 gravatar image

The big thing to note is that tf is not in ROS 2. You need to convert to tf2 first. In tf2, that code would be identical (except for the namespace), however.

tf2::Quaternion q(
        msg->pose.pose.orientation.x,
        msg->pose.pose.orientation.y,
        msg->pose.pose.orientation.z,
        msg->pose.pose.orientation.w);
    tf2::Matrix3x3 m(q);
    double roll, pitch, yaw;
    m.getRPY(roll, pitch, yaw);

So, in short, just use tf2 instead of tf.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-12-09 16:54:17 -0500

Seen: 8,144 times

Last updated: Dec 10 '19