Advertisement
Guest User

Untitled

a guest
Jun 20th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. /* This file is part of the Razor AHRS Firmware */
  2.  
  3. void Compass_Heading()
  4. {
  5.   float mag_x;
  6.   float mag_y;
  7.   float cos_roll;
  8.   float sin_roll;
  9.   float cos_pitch;
  10.   float sin_pitch;
  11.  
  12.   cos_roll = cos(roll);
  13.   sin_roll = sin(roll);
  14.   cos_pitch = cos(pitch);
  15.   sin_pitch = sin(pitch);
  16.  
  17.   // Tilt compensated magnetic field X
  18.   mag_x = magnetom[0]*cos_pitch + magnetom[1]*sin_roll*sin_pitch + magnetom[2]*cos_roll*sin_pitch;
  19.   // Tilt compensated magnetic field Y
  20.   mag_y = magnetom[1]*cos_roll - magnetom[2]*sin_roll;
  21.   // Magnetic Heading
  22.   MAG_Heading = atan2(-mag_y, mag_x);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement