Hello,

I am trying to understand how to obtain a heading angle from 3D magnetometer like HMC5843. When I look at compass.cpp in AP_Compass library, I can't get how roll and pitch angles are used to compensate compass measurements.

Is there anyone who can explain the following code in Compass.cpp? (Especially the lines where headX and headY are first computed.)

void
Compass::calculate(float roll, float pitch)
{
float cos_roll;
float sin_roll;
float cos_pitch;
float sin_pitch;

cos_roll = cos(roll);  // Optimizacion, se puede sacar esto de la matriz DCM?
sin_roll = 1  - (cos_roll * cos_roll);
cos_pitch = cos(pitch);
sin_pitch = 1  - (cos_pitch * cos_pitch);

// Tilt compensated magnetic field X component:
// Tilt compensated magnetic field Y component:

// Declination correction (if supplied)
if( fabs(_declination) > 0.0 )
{
if (heading > M_PI)    // Angle normalization (-180 deg, 180 deg)
}

// Optimization for external DCM use. Calculate normalized components
}

Views: 12337

### Replies to This Discussion

This should help, take special notice on page 5 :

http://www.ssec.honeywell.com/position-sensors/datasheets/sae.pdf

1

2

3

4

5

6

7

8

9

10

## Groups

628 members

275 members

3162 members

34 members

• ### PIXHAWK

1123 members

Season Two of the Trust Time Trial (T3) Contest
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here