Hi everyone,
I already started searching for a solution in this topic of GitHub: Calibrating Yaw Pitch Roll angles to zero whenever
I will explain again.
-> I need to calibrate the MPU6050 sensor regardless of its orientation.
First, see the image I attach.
The MPU sensor is tilted 30º Roll approx and it's calibrated horizontally. Using the code MPU6050_DMP6.ino code from i2cdevlib library, it shows me this (I show also raw values):
a/g: 0 7044 14638 5 4 -3 ypr 44.41 -0.05 25.60
If I rotate Yaw in gravity axis Yaw increases/decreases and Roll/Pitch don't move.
a/g: -356 7462 14142 -4 -20 -87 ypr 18.72 -1.08 28.08
a/g: -726 7406 14378 2 -35 -102 ypr 18.79 -1.09 28.07
a/g: -754 7468 14364 -20 -78 -147 ypr 18.90 -1.11 28.05
a/g: -830 7280 14840 -30 -137 -172 ypr 19.02 -1.08 28.01
a/g: -11650 -2366 19932 -129 -356 -509 ypr 19.72 -1.21 27.69
a/g: -10782 -228 20250 -173 -1239 -1838 ypr 21.24 -1.35 27.29
a/g: -10708 1498 18748 -206 -1866 -2867 ypr 23.36 -1.40 26.89
a/g: -9314 1280 17302 -245 -2247 -3665 ypr 25.98 -1.47 26.47
a/g: -6056 3058 14452 -304 -2330 -4271 ypr 28.90 -1.58 26.07
a/g: -3828 4846 12212 -415 -2122 -4715 ypr 32.10 -1.82 25.67
a/g: 1134 8080 14834 -187 -2179 -5163 ypr 35.50 -1.95 25.53
a/g: 2182 8694 16874 -117 -2771 -5704 ypr 39.40 -1.78 25.25
a/g: 354 8714 14860 -523 -3480 -6480 ypr 43.93 -1.49 24.82
a/g: 52 8512 13130 -573 -3866 -7091 ypr 48.93 -1.11 24.41
And then when it finished moving:
a/g: -594 7646 14200 -56 257 501 ypr 119.67 2.48 24.49
This is correct because just Yaw is affected. But what I need for this experiment is that the serial shows me:
a/g: 0 0 16384 0 0 0 ypr 0 0 0
...or near 0. So I use mpu.CalibrateAccel(20); to force calibration in that position. Then it shows me this:
a/g: 4 20 16382 4 3 -1 ypr -16.72 -0.06 -0.01
Perfect! I can subtract o add a Yaw offset, it's simple. BUT I can't do the same with Pitch and Roll because adding or subtracting offset angles will NOT change coordinate system. It will generate conflicts when obtaining values as it move away from the calibration origin.
To see this problem, let's repeat the experiment with the new calibration. I move the object quickly the same way as before. What I expect:
ypr 0 0 0
ypr 3 0 0
ypr 9 0 0
ypr 15 0 0
ypr 21 0 0
ypr 32 0 0
ypr 37 0 0
Reality:
a/g: -70 148 16618 -22 -52 -28 ypr 12.59 -0.30 0.64
a/g: -204 -452 17076 -70 -163 -95 ypr 12.71 -0.18 0.56
a/g: -19426 -8956 20868 -295 -683 -1248 ypr 13.82 0.02 0.16
a/g: -20420 -10134 25062 -364 -2093 -3451 ypr 16.24 0.93 -0.32
a/g: -19200 -15252 28192 -636 -3285 -5396 ypr 19.87 2.64 -1.01
a/g: -22956 -17330 27476 -860 -4702 -7557 ypr 24.93 5.24 -1.65
a/g: -16860 -5934 26418 -861 -6270 -9992 ypr 31.47 8.83 -1.70
a/g: -12840 2884 19976 -1136 -7403 -11637 ypr 39.15 13.16 -1.06
a/g: -2134 6466 9058 -1688 -8039 -12306 ypr 47.50 17.93 0.15
a/g: -17256 7566 17860 -1865 -8121 -12833 ypr 56.61 22.29 2.00
a/g: -15830 8672 15476 -3081 -8444 -14061 ypr 66.66 26.37 4.36
a/g: -15582 15804 10248 -2904 -8390 -14055 ypr 76.51 29.94 7.77
a/g: -12978 19518 4450 -2856 -7632 -12675 ypr 85.46 32.70 11.63
a/g: -6900 28132 3080 -2507 -6522 -11068 ypr 93.18 34.49 15.68
As you see, Yaw changes apparently correctly, but Pitch and Roll are not still. After some seconds they go to 0 again.
So, I need to change somehow the origin orientation or coordinate system orientation and prepare the MPU to read values from this orientation.
Do you think this (or my main objective) is possible?