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

How to invert the Z axis of the referential (XYZ). The orientation is expressed in quarternion?

asked 2022-04-08 05:50:54 -0500

RB_Code gravatar image

updated 2022-04-11 09:31:26 -0500

I am acquiring the position and orientation of a tag from an RGBD camera. If this tag is placed on a table the z axis is represented upwards, which is correct. My problem arises when I try to invert the tag's referential so that the z axis direction is reversed. By inverting the axis I make the tag orientation coincident with the axis of my end-effector of my robotic arm. Thus allowing to have the orientation to perform the pick of the object.

The position and orientation of the tag is represented in quaternion, which makes it more difficult to understand. I read in several places that to invert the referential just negate the value of orientation.z and orientation.w. I tried but it doesn't work.

image description

In the image the Z axis has been inverted so that the Z axis orientation is coincident / has the same orientation as the gripper Z axis.

I use the function quat_to_ur_axis_angle -> [https://gist.github.com/felixvd/ffafe...]

def quat_to_ur_axis_angle(quaternion):
angle = 2*atan2(norm2(quaternion[0], quaternion[1], quaternion[2]), quaternion[3])
if abs(angle) > 1e-6:
axis_normed = [ quaternion[0]/sin(angle/2), quaternion[1]/sin(angle/2), quaternion[2]/sin(angle/2) ]
else:
axis_normed = 0.0
return [axis_normed[0]*angle, axis_normed[1]*angle, axis_normed[2]*angle]

Qauternion to euler and add pi

orientation_list = [0.00840802170772, -0.0617530093498, 0.047875229621, 0.996907133787]
euler_ang = quat_to_ur_axis_angle(orientation_list)
euler_ang[0] = euler_ang[0]+pi
print(euler_ang)

result: [3.1584260550724412, -0.12363350563099307, 0.09584929598175379]

Qauternion to euler and inverse signal orientation.w

orientation_list = [0.00840802170772, -0.0617530093498, 0.047875229621, -0.996907133787] 
euler_ang = quat_to_ur_axis_angle(orientation_list) 
print(euler_ang)

result: [0.6553908732887168, -4.813541179230207, 3.731792048228847]

The solution I applied to get around the problem was the conversion of the quaternion to euler angles, and then add "pi" to the ROLL, to invert the referential.

How can I reverse the referential in a more correct way?

edit retag flag offensive close merge delete

Comments

I tried but it doesn't work. - how exactly does it not work? Can you edit the question and add your reasons and how you checked it?

ljaniec gravatar image ljaniec  ( 2022-04-08 06:06:41 -0500 )edit
1

Thanks, I have already edited the question. I know adding "pi" works because I've tested it on the robot and I have it working that way.

RB_Code gravatar image RB_Code  ( 2022-04-08 06:37:14 -0500 )edit

When you say "If this tag is placed on a table the z axis is represented upwards", which Transform Frame are you using for that pose?

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-04-08 08:12:35 -0500 )edit
1

That position is in the camera frame. Which I then transform to the frame of the robotic arm. The transformations are correct because the position is right, my only problem is in the orientation. Which only works by adding that "pi" to invert the z axis.

RB_Code gravatar image RB_Code  ( 2022-04-08 08:20:53 -0500 )edit

Can you draw your setup in Gimp or something like that? Adding pi to invert the z axis sounds like a rotation, not inverting, which one exactly?

ljaniec gravatar image ljaniec  ( 2022-04-08 09:37:09 -0500 )edit
1

Yes, in this case I rotate around the Y-axis, so that the z-axis is reversed. Sorry I'm not allowed to upload a picture

RB_Code gravatar image RB_Code  ( 2022-04-08 10:26:38 -0500 )edit

I upvoted the question and your comments, you should have now enough karma to upload pictures, I hope

ljaniec gravatar image ljaniec  ( 2022-04-09 12:22:48 -0500 )edit

Thank you very much. I have now placed the images with the axis. To better understand how the inversion of the axis is made.

RB_Code gravatar image RB_Code  ( 2022-04-11 09:29:39 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-04-12 01:26:03 -0500

Hamid Didari gravatar image

You shouldn't simply add pi to your roll axis. for rotating a frame, you should use a quaternion or transformation. for this scenario, first, define a quaternion like:

tf2::Quaternion rotation;
rotation.setRPY( pi, 0, 0 );

then you can rotate your frame like this:

myQuaternion = rotation * myQuaternion;
edit flag offensive delete link more

Comments

Hi Thanks for your reply.

I initially did it that way, only I get very different results.

Here's an example. I know that the second is correct because the robot orientation is correct.

Solution_1

q_orig = [ -0.0538553385067, 0.0173003073213, 0.274594514647, 0.95989486633]
  q_rot = quaternion_from_euler(pi, 0, 0)
  q_new = quaternion_multiply(q_rot, q_orig)
  euler_ang = quat_to_ur_axis_angle(q_new)
  angle_ur3 = rpy_euler_angles_to_vector_angle_axis_ur(euler_ang[0], euler_ang[1], euler_ang[2])

Answer: angle_ur3-> [2.7005039280238252, -0.064251627627787106, 1.2031676069790376]

Solution_2

   orientation_list =  [ -0.0538553385067, 0.0173003073213, 0.274594514647, 0.95989486633]
   euler_ang = quat_to_ur_axis_angle(orientation_list)
   euler_ang[0] = euler_ang[0]+pi
   angle_ur3 = rpy_euler_angles_to_vector_angle_axis_ur(euler_ang[0], euler_ang[1], euler_ang[2])

Answer: angle_ur3-> [2.9097130155879225, 0.83444405309616887, -0.0055993304592328831]

RB_Code gravatar image RB_Code  ( 2022-04-12 04:01:13 -0500 )edit

I think you should use this one:

  q_new = quaternion_multiply(q_orig,q_rot)

Could you try that?

Hamid Didari gravatar image Hamid Didari  ( 2022-04-12 05:27:16 -0500 )edit

I try:

q_orig = [ -0.0538553385067, 0.0173003073213, 0.274594514647, 0.95989486633]
  q_rot = quaternion_from_euler(pi, 0, 0)
  q_new = quaternion_multiply(q_orig, q_rot)
  euler_ang = quat_to_ur_axis_angle(q_new)
  angle_ur3 = rpy_euler_angles_to_vector_angle_axis_ur(euler_ang[0], euler_ang[1], euler_ang[2])

and return angle_ur3 = [2.7005039280238252, 0.064251627627787106, -1.2031676069790376]

but the correct result should be:

[2.9097130155879225, 0.83444405309616887, -0.0055993304592328831]

RB_Code gravatar image RB_Code  ( 2022-04-12 05:34:09 -0500 )edit

There is a really nice description of the Quaternion Rotation - especially parts with active and passive rotation (15a and 15b). Can you check your rotations with these steps? It seems like there should be two multiplications for p to be rotated: p' = q^(-1)pq, q - rotation quaternion

ljaniec gravatar image ljaniec  ( 2022-04-18 18:46:08 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2022-04-08 05:50:54 -0500

Seen: 435 times

Last updated: Apr 12 '22