Currently, I am calculating quaternions using the Madgwick algorithm, incorporating magnetometer values. I have tried the code provided in Madgwick's original paper and also the implementation by Kris Winer. The results are reasonably accurate, as the quaternion values change correctly for each axis during rotation.
However, with this algorithm, the sensor fails to detect the correct north direction. When the program starts, the direction pointed to by the magnetometer's X-axis is always interpreted as north, even if the X-axis is actually pointing south. This is evident from the quaternion output, which is always (1, 0, 0, 0) when the sensor is first powered on or the program begins, regardless of whether the magnetometer's X-axis is pointing south, west, or east.
Could anyone help me to resolve this issue?
I tried implementing both Madgwick's original code from his paper and Kris Winer's implementation. I expected the sensor to correctly detect the north direction using the magnetometer, but instead, the sensor always treats the magnetometer's X-axis as pointing north regardless of its actual orientation.
so when the x axis of magnetometer pointed to west when the sensor first power on, the result is not 1,0,0,0 , but a value that represent the position of the sensor.