Hello,
I want to calibrate my lsm303c magnetometer after changing its plane of orientation from X-Y to Y-Z plane which is parallel to earth surface but whatever method available for calculation the heading angle is w.r.t X-Y plane.
Can anybody help to calculate heading after changing its orientation?
magnetometer_check.ino (3.65 KB)
The best approach is to use the accelerometer as well, and make a tilt compensated compass. Pololu has good Arduino code for that device.
But to a first approximation, it would help a lot to understand how this line works:
heading1=(atan2(my,mx) * 180) / Pi;
To make a useful compass, you will need to calibrate the magnetometer. Follow the directions in this tutorial:
Prateek22:
Hello,
I want to calibrate my lsm303c magnetometer after changing its plane of orientation from X-Y to Y-Z plane which is parallel to earth surface but whatever method available for calculation the heading angle is w.r.t X-Y plane.
Can anybody help to calculate heading after changing its orientation?
Something to contemplate about calibrating the magnetic compass, is that once the compass is moved the calibration does not apply.
Doing a search, using your favorite internet search engine, on the words " calculating heading angle from magnetometer " will give you many pointers of useful information related to your question. As has been mentioned, you will find a need for, in the least, an accelerometer package.
If you had 2 magnetic measurement units with each unit mounted 180 degree out of phase with the other, then the readings from each plane can be used as compensation for moment to moment movements.
You may, also, find this to be an important source of information:
https://os.mbed.com/users/onehorse/
Thanks for support but I am able to calculate heading angle the magnetometer using
heading1=(atan2(my,mx) * 180) / Pi;
And it's working fine if I place magnetometer placed its z-axis parallel to gravity which mathematically correct w.r.t formula for calculating heading.
but if change the orientation after which my z-axis becomes x-axis according to the datasheet so now the formula for calculating heading angle is
heading1=(atan2(my,mz) * 180) / Pi;
Now, in this case, I am facing the issue of getting the wrong heading angle.
Can this problem be solved using tilt compensation (since I have rotated the sensor 90 degrees) and what formula can be used for roll and pitch in Arduino?