I have just started learning how to fuse the data measured by the gyro and accelerometer to estimate the attitude of an IMU in Matlab. I have no problem estimating or understanding the Euler angles calculated from at set of gyro data. But when I calculate the Euler angles from the accelerometer data, the rotation always seem to go in the opposite direction to that of the gyro's.
(note:the order of rotation is X(Phi) -> Y(Theta) -> Z(Psi))
To troubleshoot, I ran a very simple experiment where I first fixed the x-axis parallel to the ground with the y-axis pointing straight down. Then I gradually rotated the object around the x-axis positively (CCW) by roughly ~+40°. All the signs and direction of rotation follow the right-hand-rule and right-hand-curl rule.
For clarity I attach the following drawing to associate sections of the accelerometer data to the state of rotation (note: +x-axis points out of the page):
The accelerometer data looks correct. ay stays pointing downward for the first few seconds and logs a value of -1g before rotating. As the object frame rotates around the x-axis (positively or CCW), ay decreases in magnitude as az increases its.
I expect the Phi-delta measured by gyro should start with 0 deg and end with ~+40 deg because the rotation is positive (CCW), if we ignore the noise, drift, and accumulation of error due to numerical integration - the calculated graph pretty much agrees.
Then with the accelerometer, I expect the Phi to go from -90 deg to -45 deg. The slope should be positive because, again, the rotation is identical and is positive (CCW). Phi-delta is positive, whereas the Phi values should remain negative because the frame position is still CW or negative away from the horizontal orientation. But when I calculate the Phi, I get the complete opposite:
I am not sure what is wrong in my thought process and hope someone can point out or correct that for me.