κΈ°μ‘΄ ν¬μŠ€νŒ…μ—μ„œ ν•œλ²ˆ μ–ΈκΈ‰ν–ˆλ˜ 적이 μžˆλ‹€
μ—¬κΈ°μ—μ„œ 확인가λŠ₯ !

ν•˜μ§€λ§Œβ€¦ ros와 python3을 λ™μ‹œμ— μ‚¬μš©ν•˜λ €λ‹ˆ tf.transformations ν•¨μˆ˜ μ‚¬μš© μ‹œ μ—λŸ¬κ°€ λ‚œλ‹€ γ…œγ…œ
κ·Έλž˜μ„œ 직접 μˆ˜μ‹μœΌλ‘œ κ΅¬ν•΄λ³΄μž

Quaternion to Euler

μ½”λ“œ 상단에 λ‹€μŒκ³Ό 같이 μž…λ ₯ν•΄μ£Όμž

import math
 
def euler_from_quaternion(x, y, z, w):
  """
  Convert a quaternion into euler angles (roll, pitch, yaw)
  roll is rotation around x in radians (counterclockwise)
  pitch is rotation around y in radians (counterclockwise)
  yaw is rotation around z in radians (counterclockwise)
  """
  t0 = +2.0 * (w * x + y * z)
  t1 = +1.0 - 2.0 * (x * x + y * y)
  roll_x = math.atan2(t0, t1)

  t2 = +2.0 * (w * y - z * x)
  t2 = +1.0 if t2 > +1.0 else t2
  t2 = -1.0 if t2 < -1.0 else t2
  pitch_y = math.asin(t2)

  t3 = +2.0 * (w * z + x * y)
  t4 = +1.0 - 2.0 * (y * y + z * z)
  yaw_z = math.atan2(t3, t4)

  return roll_x, pitch_y, yaw_z # in radians

Euler to Quaternion

μ½”λ“œ 상단에 λ‹€μŒκ³Ό 같이 μž…λ ₯ν•΄μ£Όμž

import numpy as np # Scientific computing library for Python
 
def get_quaternion_from_euler(roll, pitch, yaw):
  """
  Convert an Euler angle to a quaternion.
   
  Input
    :param roll: The roll (rotation around x-axis) angle in radians.
    :param pitch: The pitch (rotation around y-axis) angle in radians.
    :param yaw: The yaw (rotation around z-axis) angle in radians.
 
  Output
    :return qx, qy, qz, qw: The orientation in quaternion [x,y,z,w] format
  """
  qx = np.sin(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) - np.cos(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)
  qy = np.cos(roll/2) * np.sin(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.cos(pitch/2) * np.sin(yaw/2)
  qz = np.cos(roll/2) * np.cos(pitch/2) * np.sin(yaw/2) - np.sin(roll/2) * np.sin(pitch/2) * np.cos(yaw/2)
  qw = np.cos(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)
 
  return [qx, qy, qz, qw]


끝 !

Reference

Leave a comment