title: Quaternion - Angle computation using accelerometer and gyroscope
body: <p>I have been using a <strong>6dof</strong> LSM6DS0 IMU unit (with accelerometer and gyroscope). And I am trying to calculate the angle of rotation around all the three axes. I have tried may methods but not getting the results as expected.</p>
  
  <p><strong>Methods tried:</strong></p>
  
  <p>(i) Complementatry filter approach - I am able to get the angles using the formula provided in the link <a href="http://www.pieter-jan.com/node/11" rel="nofollow">Angle comutation method</a>. </p>
  
  <p>But the problem is that angles are not at all consistent and drifts a lot. Moreover when the IMU is rotated around one axis, angles calculated over other axis are wobbling too much.</p>
  
  <p>(ii) Quaternion based angle calculation : There were plenty of resources claiming the angles are calcluated very well using quaternion approach but none had a  clear explanation. I have used <a href="http://www.x-io.co.uk/open-source-imu-and-ahrs-algorithms/" rel="nofollow">this method</a> in order to update the quaternion for every values taken from the IMU unit. But the link dint explain how to calculate the angles from quaternion.</p>
  
  <p>I have used <strong>glm math</strong> library inorder to convert the quaternion to euler angles and also have tried the formula specified in <a href="https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles" rel="nofollow">wiki link</a>. With this method since in pitch calculation asin returns only -90 to +90 degrees I am not able to rotate the object in 3D as the one they have been doing in the mentioned link.</p>
  
  <p>Does anyone have tried the quaternion to angle conversion before?? I need to calculate the angles around all the three axis in the range 0 to 360 degrees or -180 to +180 degrees. </p>
  
  <p>Any help could be really appreciated. Thanks in advance.</p>