Many messages, if the information is delayed or not useful specifically, but may be useful to others, as I found it after some research:
but. Using a Kalman (linear or non-linear) filter, you perform the following actions:
Gyroscope for integrating the delta angle, while accelerometers tell you about the outer limit.
b. Euler frequencies are different from the rate of change of the gyroscope angle, so you need a quaternion or Eulerโs representation:
Quaternion is not trivial, but two main steps: ----
1. For Roll, pitch,yaw you get three quaternions as cos(w) +sin(v) where w is scalar part and v is vector part (or when coding just another variable) Then simply multiply all 3 quat. to get a delta quaternion ie quatDelta[0] =c1c2*c3 - s1s2*s3; quatDelta[1] =c1c2*s3 + s1s2*c3; quatDelta[2] =s1*c2*c3 + c1*s2*s3; quatDelta[3] =c1*s2*c3 - s1*c2*s3; where c1,c2,c3 are cos of roll,pitch,yaw and s stands for sin of the same actually half of those gyro pre integrated angles. 2. Then just multiply by old quaternion you had newQuat[0]=(quaternion[0]*quatDelta[0] - quaternion[1]*quatDelta[1] - quaternion[2]*quatDelta[2] - quaternion[3]*quatDelta[3]); newQuat[1]=(quaternion[0]*quatDelta[1] + quaternion[1]*quatDelta[0] + quaternion[2]*quatDelta[3] - quaternion[3]*quatDelta[2]); newQuat[2]=(quaternion[0]*quatDelta[2] - quaternion[1]*quatDelta[3] + quaternion[2]*quatDelta[0] + quaternion[3]*quatDelta[1]); newQuat[3]=(quaternion[0]*quatDelta[3] + quaternion[1]*quatDelta[2] - quaternion[2]*quatDelta[1] + quaternion[3]*quatDelta[0]);
As you progress through the code, it is updated, so only quatenion are global variables, not the rest
3. Lastly if you want Euler angles from them then do the following: `euler[2]=atan2(2.0*(quaternion[0]*quaternion[1]+quaternion[2]*quaternion[3]), 1-2.0*(quaternion[1]*quaternion[1]+quaternion[2]*quaternion[2]))euler[1]=safe_asin(2.0*(quaternion[0]*quaternion[2] - quaternion[3]*quaternion[1]))euler[0]=atan2(2.0*(quaternion[0]*quaternion[3]+quaternion[1]*quaternion[2]), 1-2.0*(quaternion[2] *quaternion[2]+quaternion[3]*quaternion[3]))` euler[1] is pitch and so on..
I just wanted to describe the general steps for implementing a quaternion. There may be some minor errors, but I tried this myself and it works. Please note that when you change the Euler angles, you will get singularities, also called "Gimbal lock"
Itโs important to note that this is not my job, but I found it on the Internet and wanted to thank who ever made this priceless code ... Cheers
tej Oct 16 '13 at 12:15 2013-10-16 12:15
source share