Using Arduino > Sensors

Magnetometer Tilt Compensation for Yaw Axis Using HMC5883L and BMA180

(1/4) > >>

mamette:
Hi, i want to make yaw Axis for my 3 Axis Gimbal project, but i really confused to solve the magnetometer tilt compensation. I use HMC5883L magnetometer and BMA 180 Accelerometer. From the reference that i found on the internet, i need magnetometer and accelerometer to solve Magnetometer Tilt Compensation. Anda i found this algorithm from https://code.google.com/p/sf9domahrs/:

CMx = mag_x*cos(pitch) + mag_y*sin(roll)sin(pitch) + mag_z*cos(roll)sin(pitch)
CMy = mag_y*cos(roll) - mag_z*sin(roll)

MAG_Heading = Atan(CMy/CMx)

So, i applying the algorithm to my sketch:


--- Code: ---pitchAccelXh = atan2((accelResult[1] - biasAccelY) / 1024, (accelResult[2] - biasAccelZ) / 1024); //Accelerometer Pitch Degrees in radian
 rollAccelYh = atan2((accelResult[0] - biasAccelX) / 1024, (accelResult[2] - biasAccelZ) / 1024); //Accelerometer Roll Degrees in radian
 
 float cos_roll= cos(pitchAccelXh);
 float sin_roll = sin(pitchAccelXh);
 float cos_pitch = cos(rollAccelYh);
 float sin_pitch = sin(rollAccelYh);
 
 float mag_X = scaled.XAxis;  //magnetometer X Axis
 float mag_Y = scaled.YAxis;  //magnetometer Y Axis
 float mag_Z = scaled.ZAxis;  //magnetometer Z Axis
 
 // The tilt compensation algorithem.
 Yh = mag_Y * cos_roll - mag_Z * sin_roll;
 Xh = mag_X * cos_pitch + mag_Y * sin_roll * sin_pitch + mag_Z * cos_roll * sin_pitch;
 
 realHeading = atan2(Yh, Xh) * (360.0 / (2*PI));
--- End code ---


But it didn't works, it is still like just use magnetometer without accelerometer, but different in data value.
Anybody know about the right algorithm for Magnetometer Tilt Compensation?

Thank You..

Erdin:
I know this one, https://www.loveelectronics.co.uk/Tutorials/13/tilt-compensated-compass-arduino-tutorial
But I have not used it for my HMC5883L yet.

mamette:
I have try those one, but not working. It is working for you?

mamette:
Any Idea?

michinyon:
I don't use that concept at all,   and I think the logic and methodology for it is spurious.

The basic feature of the geomagnetic field is that it isn't parallel to the ground,  as you would
think when you have a magnetic compass sitting on a map on a table.

It is a vector field shooting down into the ground at a diagonal angle,   which is more or less
constant over short distances and which you can easily find out what it is for your region.

The 3-axis magnetometer is going to give you a vector in 3D which is going to show you the
direction of that field.    Since you already know the direction of the field,   you can determine
the orientation of the magnetometer,  with the exception of rotation about the vector direction.

If you also have an accelerometer,  and you assume your device is stationary or moving at a constant
velocity ( so it has no actual acceleration ),   you can fully determine the orientation of your device.


Navigation

[0] Message Index

[#] Next page

Go to full version