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: 2114

### 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

## Contests

Season Two of the Trust Time Trial (T3) Contest has now begun. The fourth round is an accuracy round for multicopters, which requires contestants to fly a cube. The deadline is April 14th.

A list of all T3 contests is here

1277 members

24 members

183 members

246 members