Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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 }
Generated on Sun Jul 17 2022 22:09:51 by
1.7.2