四元数参照系

2024-05-23 23:41:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个内置了IMU的Myo臂章,在python中,我想得到我想要的参考系中的滚转俯仰偏航。它在电脑的同一位置工作得很好,但是如果我移动到桌子的另一边,我会得到相反的音高值。我试着遵循这个指南:http://developerblog.myo.com/quaternions/

#Setting a center with the conjugation of the first set of Quaternions

centre = libmyo.Quaternion(myo.orientation[0], myo.orientation[1], myo.orientation[2], myo.orientation[3]).conjugate()


while True:

    obj = libmyo.Quaternion(myo.orientation[0], myo.orientation[1], myo.orientation[2], myo.orientation[3])

    #Multiplying the current Rotation with the centre

    frame =  obj.__mul__(centre).conjugate()

    x= frame[0]
    y= frame[1]
    z= frame[2]
    w= frame[3]

   roll = math.atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z)
   pitch = math.atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z)
   yaw = math.asin(2*x*y + 2*z*w)

   print(roll, pitch, yaw)
   time.sleep(0.2)

提前谢谢


Tags: oftheobjwithmathframerollmyo