Pose Rotation Order

In the description of a Pose, it says the last 3 values are “an axis-angle”, but if you look at a Waypoint, it shows a Rotation Vector as RX, RY, RZ. I am used to working with compound Euler angles (Yaw, Pitch, Roll), but haven’t worked with a rotation vector before.

Is there a way to convert between RPY and a Rotation Vector, either through math or a built-in script function, or a way a pose can be defined directly using YPR? I can’t find any examples in the manual or an explanation any further than pointing to a wikipedia page.

You can use the URScript codes rotvec2rpy(rotation_vector) and rpy2rotvec(rpy_vector) to convert the rotation vectors to RPY and vice versa in URScript.
They are both explained in the script manual.

Below are some example formulas that can be used in URScript before the above functions were implemented (3.3.0.145), other methods might work just as fine.

For conversion from RPY to rotation vector:

  def rpy2rv(roll,pitch,yaw):
  
  alpha = yaw
  beta = pitch
  gamma = roll
  
  ca = cos(alpha)
  cb = cos(beta)
  cg = cos(gamma)
  sa = sin(alpha)
  sb = sin(beta)
  sg = sin(gamma)
  
  r11 = ca*cb
  r12 = ca*sb*sg-sa*cg
  r13 = ca*sb*cg+sa*sg
  r21 = sa*cb
  r22 = sa*sb*sg+ca*cg
  r23 = sa*sb*cg-ca*sg
  r31 = -sb
  r32 = cb*sg
  r33 = cb*cg
  
  theta = acos((r11+r22+r33-1)/2)
  sth = sin(theta)
  kx = (r32-r23)/(2*sth)
  ky = (r13-r31)/(2*sth)
  kz = (r21-r12)/(2*sth)
  
  rv[0] = theta*kx
  rv[1] = theta*ky
  rv[2] = theta*kz
  
  return rv
  
  end

For conversion from rotation vector to RPY:

  def rv2rpy(rx,ry,rz):
  
  theta = sqrt(rx*rx + ry*ry + rz*rz)
  kx = rx/theta
  ky = ry/theta
  kz = rz/theta
  cth = cos(theta)
  sth = sin(theta)
  vth = 1-cos(theta)
  
  r11 = kx*kx*vth + cth
  r12 = kx*ky*vth - kz*sth
  r13 = kx*kz*vth + ky*sth
  r21 = kx*ky*vth + kz*sth
  r22 = ky*ky*vth + cth
  r23 = ky*kz*vth - kx*sth
  r31 = kx*kz*vth - ky*sth
  r32 = ky*kz*vth + kx*sth
  r33 = kz*kz*vth + cth
  
  beta = atan2(-r31,sqrt(r11*r11+r21*r21))
  
  if beta > d2r(89.99):
  beta = d2r(89.99)
  alpha = 0
  gamma = atan2(r12,r22)
  elif beta < -d2r(89.99):
  beta = -d2r(89.99)
  alpha = 0
  gamma = -atan2(r12,r22)
  else:
  cb = cos(beta)
  alpha = atan2(r21/cb,r11/cb)
  gamma = atan2(r32/cb,r33/cb)
  end
  
  rpy[0]= gamma
  rpy[1]= beta
  rpy[2]= alpha
  
  return rpy
  
  end

Additionally, check out this article.

4 Likes

Thanks so much for the help. I’m currently using 3.2 so that explains why I couldn’t find anything. This is exactly what I was looking for

This code is a good approach, but beware of gimbal lock.
For example rv2rpy(0,180,180) leads to a division by zero.

Another solution is to use quaternions, like in this library: Convert position types - UnderAutomation

Pose p = new Pose(x, y, z, rx, ry, rz);

Pose rpy = p.FromRotationVectorToRPY();

Pose rotVect = p.FromRPYToRotationVector();
1 Like