ROS Answers: Open Source Q&A Forum - RSS feedhttps://answers.ros.org/questions/Open source question and answer forum written in Python and DjangoenROS Answers is licensed under Creative Commons Attribution 3.0Wed, 08 May 2019 17:36:24 -0500"euler_from_quaternion": when pitch close to ±90°, roll drift? Any solutions?https://answers.ros.org/question/322762/euler_from_quaternion-when-pitch-close-to-90deg-roll-drift-any-solutions/I'm working with an IMU to estimate orientation. I provide the raw IMU data to `imu_filter_madgwick` topic `imu/data_raw`, it gives me back `imu/data` which includes a quaternion representing the orientation of the sensor.
Let's say the following code has the quaternion I get from the filter message `msg`:
quaternion = (msg.orientation.x, msg.orientation.y, msg.orientation.z, msg.orientation.w)
If I compute euler angles by `roll, pitch, yaw = tf.transformations.euler_from_quaternion(quaternion)`, and print them. I noticed that if the pitch angle is close to ±90°, the roll angle will drift about ±180°. I also noticed that this singularity behavior is mentioned [here](http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/).
**My question is how to solve this problem, and I'm asking because `rviz` is able to visualize this orientation perfectly without any drifting.** *So, if I use `rviz` to visualize the orientation using the same quaternion, `rviz` doesn't have this problem of roll angle drifts when pitch is close to ±90°. The frame moves smoothly at any roll/pitch/yaw angles.*
Below is the code I used for `rviz` to visualized the same quaternion I used to get euler angles:
quaternion = (msg.orientation.x, msg.orientation.y, msg.orientation.z, msg.orientation.w)
br = tf.TransformBroadcaster()
br.sendTransform((0,0,0), quaternion, rospy.Time.now(), 'imu', 'world')
Then, I use `rviz` to display the `imu` frame w.r.t `world` frame. There's simply no drifting or whatever.Wed, 08 May 2019 14:44:03 -0500https://answers.ros.org/question/322762/euler_from_quaternion-when-pitch-close-to-90deg-roll-drift-any-solutions/Comment by jayess for <p>I'm working with an IMU to estimate orientation. I provide the raw IMU data to <code>imu_filter_madgwick</code> topic <code>imu/data_raw</code>, it gives me back <code>imu/data</code> which includes a quaternion representing the orientation of the sensor. </p>
<p>Let's say the following code has the quaternion I get from the filter message <code>msg</code>:</p>
<pre><code>quaternion = (msg.orientation.x, msg.orientation.y, msg.orientation.z, msg.orientation.w)
</code></pre>
<p>If I compute euler angles by <code>roll, pitch, yaw = tf.transformations.euler_from_quaternion(quaternion)</code>, and print them. I noticed that if the pitch angle is close to ±90°, the roll angle will drift about ±180°. I also noticed that this singularity behavior is mentioned <a href="http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/">here</a>.</p>
<p><strong>My question is how to solve this problem, and I'm asking because <code>rviz</code> is able to visualize this orientation perfectly without any drifting.</strong> <em>So, if I use <code>rviz</code> to visualize the orientation using the same quaternion, <code>rviz</code> doesn't have this problem of roll angle drifts when pitch is close to ±90°. The frame moves smoothly at any roll/pitch/yaw angles.</em> </p>
<p>Below is the code I used for <code>rviz</code> to visualized the same quaternion I used to get euler angles:</p>
<pre><code>quaternion = (msg.orientation.x, msg.orientation.y, msg.orientation.z, msg.orientation.w)
br = tf.TransformBroadcaster()
br.sendTransform((0,0,0), quaternion, rospy.Time.now(), 'imu', 'world')
</code></pre>
<p>Then, I use <code>rviz</code> to display the <code>imu</code> frame w.r.t <code>world</code> frame. There's simply no drifting or whatever.</p>
https://answers.ros.org/question/322762/euler_from_quaternion-when-pitch-close-to-90deg-roll-drift-any-solutions/?comment=322769#post-id-322769For future questions/edits, to enable syntax highlighting please don't wrap code/terminal out/etc. in `<code>` tags, you can use the preformatted text (`101010`) button. To use it, highlight the text and then click on the preformatted text (`101010`) button. Also, no need to use `<br>` tags either. You can just hit `Enter` to get text to a new line.Wed, 08 May 2019 17:36:24 -0500https://answers.ros.org/question/322762/euler_from_quaternion-when-pitch-close-to-90deg-roll-drift-any-solutions/?comment=322769#post-id-322769