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

Euler to quaternion conversion error

asked 2011-11-10 20:58:20 -0600

alfa_80 gravatar image

updated 2011-11-10 21:29:52 -0600

I try to convert Euler values into quaternion. Some parts of it are as follow:

       //data_set[t][8] = yaw = y, data_set[t][7] = pitch = x, data_set[t][6] = roll = z
        btQuaternion q(pcl::deg2rad(data_set[t][8]), pcl::deg2rad(data_set[t][7]), pcl::deg2rad(data_set[t][6]));

        new_pose.orientation.x = q.x();
        new_pose.orientation.y = q.y();
        new_pose.orientation.z = q.z();
        new_pose.orientation.w = q.w();

        cout << "new_pose.orientation.x = " << new_pose.orientation.x << endl;
        cout << "new_pose.orientation.y = " << new_pose.orientation.y << endl;
        cout << "new_pose.orientation.z = " << new_pose.orientation.z << endl;
        cout << "new_pose.orientation.w = " << new_pose.orientation.w << endl;

I have cross-checked with an on-line converter and found that the values returned somehow swapped and have sign(+ve and -ve) problem. The outputs are as below:

From my code:

new_pose.orientation.x = 0.0419219
new_pose.orientation.y = -0.0300053
new_pose.orientation.z = -0.184328
new_pose.orientation.w = 0.981512

From the on-line converter:

u0 = 0.9811347012447917 
u1 = -0.18632481923344862   
u2 = -0.04192188282716083   
u3 = -0.030005257724968114

I guess u0 corresponds to w, u1 corresponds to x and so on..

What is actually the problem of this conversion?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2011-11-10 22:17:28 -0600

AHornung gravatar image

Why do you manually create the Quaternion? I would suggest using tf::createQuaternionFromRPY() in tf/transform_datatypes.h.

Given that there are 24 difference possibilities to specify "Euler angles", it's hard to tell what goes wrong here and which format the online converter expects.

edit flag offensive delete link more

Comments

I didn't manually create it, i just used "btQuaternion" class functionality there.. or is it easier using "tf::createQuaternionFromRPY()"?
alfa_80 gravatar image alfa_80  ( 2011-11-10 23:38:04 -0600 )edit
Yes the better way would be to just use new_pose.orientation = tf::createQuaternionFromRPY(roll, pitch, yaw). Still, that leaves the question where your original data (data_set) comes from and what "roll", "picth", and "yaw" means in their representation!
AHornung gravatar image AHornung  ( 2011-11-10 23:57:27 -0600 )edit
Any such thing for position which is coupled with TF like in orientation that you just pointed out?
alfa_80 gravatar image alfa_80  ( 2011-11-11 00:12:24 -0600 )edit
new_pose.orientation = tf::createQuaternionFromRPY(data_set[t][6]/180.0*M_PI, data_set[t][7]/180.0*M_PI, data_set[t][8]/180.0*M_PI); Why am I still getting error of matching template problem? t is running in a loop for about 200 times..and the data_set is of type double already..
alfa_80 gravatar image alfa_80  ( 2011-11-11 00:29:39 -0600 )edit
@Ahornung: I think this tf::createQuaternionFromRPY() cannot be used because it's a static function while the input arguments need to be fed are a vector of values..Please correct me if I'm wrong.
alfa_80 gravatar image alfa_80  ( 2011-11-11 00:38:36 -0600 )edit
I use it regularly and it works fine in any context. However, you did not post complete code thus I can only guess of what type new_pose is. (I assumed a tf::Transform which is a btTransform). Positions can usually be directly assigned, there are no conversions necessary.
AHornung gravatar image AHornung  ( 2011-11-11 03:05:07 -0600 )edit
oo the new_pose is from "geometry_msgs::Pose new_pose;" It is of type Pose.
alfa_80 gravatar image alfa_80  ( 2011-11-11 03:53:02 -0600 )edit

Question Tools

Stats

Asked: 2011-11-10 20:58:20 -0600

Seen: 4,475 times

Last updated: Nov 10 '11