I have two IMU sensors giving me Euler angles. I convert them to Quaternion by following
quaternion_angle_1=tf.transformations.quaternion_from_euler(roll_1,pitch_1,yaw_1)
quaternion_angle_2=tf.transformations.quaternion_from_euler(roll_2,pitch_2,yaw_2)
Now I want to caculate the angle between these measurements from the IMU sensors. How can I do that?
Sounds like you want the relative rotation between two quaternions. You could simple calculate the angle between the euler angles, then convert that to a quaternion. But if you need to do it strictly with quaternions tf
allows you to do this directly:
relative_quat = quaternion_angle_1 * quaternion_angle_2.inverse()
An amazing python library for all quaternion/euler/matrix conversions and operations is transforms3d . To got from quaternion a, to quaternion b, you could just do -
quat_c = tf3.quaternions.qmult(quat_b, tf3.quaternions.qconjugate(quat_a))
Here is a github gist for the above example.
Or if you are using tf/transformations.py ,
quat_c = quaternion_multiply(quat_b, quaternion_conjugate(quat_a))
Quaternion multiplication involves taking a hamiltonian product , therefore simply taking the dot/cross/element-wise multiplication of two quaternions will not be enough.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.