Port of http://dev.qu.tu-berlin.de/projects/sf-razor-9dof-ahrs to an mbed, tested with a 9DOF Sensor Stick, SEN-10724

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Compass.cpp Source File

Compass.cpp

00001 /* This file is part of the Razor AHRS Firmware */
00002 #include "Razor_AHRS.h"
00003 #include <math.h>
00004 
00005 void IMU::Compass_Heading()
00006 {
00007   float mag_x;
00008   float mag_y;
00009   float cos_roll;
00010   float sin_roll;
00011   float cos_pitch;
00012   float sin_pitch;
00013   
00014   cos_roll = cos(roll);
00015   sin_roll = sin(roll);
00016   cos_pitch = cos(pitch);
00017   sin_pitch = sin(pitch);
00018   
00019   // Tilt compensated magnetic field X
00020   mag_x = magnetom[0]*cos_pitch + magnetom[1]*sin_roll*sin_pitch + magnetom[2]*cos_roll*sin_pitch;
00021   // Tilt compensated magnetic field Y
00022   mag_y = magnetom[1]*cos_roll - magnetom[2]*sin_roll;
00023   // Magnetic Heading
00024   MAG_Heading = atan2(-mag_y, mag_x);
00025 }