2010-05-28 11:38:51 -03:00
|
|
|
#ifndef APM_Compass_h
|
|
|
|
#define APM_Compass_h
|
|
|
|
|
2010-10-22 11:07:41 -03:00
|
|
|
#include "../AP_Math/AP_Math.h"
|
|
|
|
|
|
|
|
// Rotation matrices
|
|
|
|
#define ROTATION_NONE Matrix3f(1, 0, 0, 0, 1, 0, 0 ,0, 1)
|
|
|
|
#define ROTATION_YAW_45 Matrix3f(0.70710678, -0.70710678, 0, 0.70710678, 0.70710678, 0, 0, 0, 1)
|
|
|
|
#define ROTATION_YAW_90 Matrix3f(0, -1, 0, 1, 0, 0, 0, 0, 1)
|
|
|
|
#define ROTATION_YAW_135 Matrix3f(-0.70710678, -0.70710678, 0, 0.70710678, -0.70710678, 0, 0, 0, 1)
|
|
|
|
#define ROTATION_YAW_180 Matrix3f(-1, 0, 0, 0, -1, 0, 0, 0, 1)
|
|
|
|
#define ROTATION_YAW_225 Matrix3f(-0.70710678, 0.70710678, 0, -0.70710678, -0.70710678, 0, 0, 0, 1)
|
|
|
|
#define ROTATION_YAW_270 Matrix3f(0, 1, 0, -1, 0, 0, 0, 0, 1)
|
|
|
|
#define ROTATION_YAW_315 Matrix3f(0.70710678, 0.70710678, 0, -0.70710678, 0.70710678, 0, 0, 0, 1)
|
|
|
|
#define ROTATION_ROLL_180 Matrix3f(1, 0, 0, 0, -1, 0, 0, 0, -1)
|
|
|
|
#define ROTATION_ROLL_180_YAW_45 Matrix3f(0.70710678, 0.70710678, 0, 0.70710678, -0.70710678, 0, 0, 0, -1)
|
|
|
|
#define ROTATION_ROLL_180_YAW_90 Matrix3f(0, 1, 0, 1, 0, 0, 0, 0, -1)
|
|
|
|
#define ROTATION_ROLL_180_YAW_135 Matrix3f(-0.70710678, 0.70710678, 0, 0.70710678, 0.70710678, 0, 0, 0, -1)
|
|
|
|
#define ROTATION_PITCH_180 Matrix3f(-1, 0, 0, 0, 1, 0, 0, 0, -1)
|
|
|
|
#define ROTATION_ROLL_180_YAW_225 Matrix3f(-0.70710678, -0.70710678, 0, -0.70710678, 0.70710678, 0, 0, 0, -1)
|
|
|
|
#define ROTATION_ROLL_180_YAW_270 Matrix3f(0, -1, 0, -1, 0, 0, 0, 0, -1)
|
|
|
|
#define ROTATION_ROLL_180_YAW_315 Matrix3f(0.70710678, -0.70710678, 0, -0.70710678, -0.70710678, 0, 0, 0, -1)
|
|
|
|
|
|
|
|
#define APM_COMPASS_COMPONENTS_UP_PINS_FORWARD ROTATION_NONE
|
|
|
|
#define APM_COMPONENTS_UP_PINS_FORWARD_RIGHT ROTATION_YAW_45
|
|
|
|
#define APM_COMPASS_COMPONENTS_UP_PINS_RIGHT ROTATION_YAW_90
|
|
|
|
#define APM_COMPONENTS_UP_PINS_BACK_RIGHT ROTATION_YAW_135
|
|
|
|
#define APM_COMPASS_COMPONENTS_UP_PINS_BACK ROTATION_YAW_180
|
|
|
|
#define APM_COMPONENTS_UP_PINS_BACK_LEFT ROTATION_YAW_225
|
|
|
|
#define APM_COMPASS_COMPONENTS_UP_PINS_LEFT ROTATION_YAW_270
|
|
|
|
#define APM_COMPONENTS_UP_PINS_FORWARD_LEFT ROTATION_YAW_315
|
|
|
|
#define APM_COMPASS_COMPONENTS_DOWN_PINS_FORWARD ROTATION_ROLL_180
|
|
|
|
#define APM_COMPONENTS_DOWN_PINS_FORWARD_RIGHT ROTATION_ROLL_180_YAW_45
|
|
|
|
#define APM_COMPASS_COMPONENTS_DOWN_PINS_RIGHT ROTATION_ROLL_180_YAW_90
|
|
|
|
#define APM_COMPONENTS_DOWN_PINS_BACK_RIGHT ROTATION_ROLL_180_YAW_135
|
|
|
|
#define APM_COMPASS_COMPONENTS_DOWN_PINS_BACK ROTATION_PITCH_180
|
|
|
|
#define APM_COMPONENTS_DOWN_PINS_BACK_LEFT ROTATION_ROLL_180_YAW_225
|
|
|
|
#define APM_COMPASS_COMPONENTS_DOWN_PINS_LEFT ROTATION_ROLL_180_YAW_270
|
|
|
|
#define APM_COMPONENTS_DOWN_PINS_FORWARD_LEFT ROTATION_ROLL_180_YAW_315
|
2010-09-26 10:54:24 -03:00
|
|
|
|
2010-05-28 11:38:51 -03:00
|
|
|
class APM_Compass_Class
|
|
|
|
{
|
2010-10-16 22:34:57 -03:00
|
|
|
private:
|
2010-10-09 20:22:46 -03:00
|
|
|
int orientation;
|
2010-10-22 11:07:41 -03:00
|
|
|
Matrix3f orientationMatrix;
|
2010-10-09 20:22:46 -03:00
|
|
|
float calibration[3];
|
|
|
|
int offset[3];
|
|
|
|
float declination;
|
2010-05-28 11:38:51 -03:00
|
|
|
public:
|
|
|
|
int Mag_X;
|
|
|
|
int Mag_Y;
|
|
|
|
int Mag_Z;
|
|
|
|
float Heading;
|
|
|
|
float Heading_X;
|
|
|
|
float Heading_Y;
|
2010-10-16 22:34:57 -03:00
|
|
|
unsigned long lastUpdate;
|
2010-05-28 11:38:51 -03:00
|
|
|
|
|
|
|
APM_Compass_Class(); // Constructor
|
2010-10-17 18:07:25 -03:00
|
|
|
bool Init();
|
2010-05-28 11:38:51 -03:00
|
|
|
void Read();
|
|
|
|
void Calculate(float roll, float pitch);
|
2010-10-22 11:07:41 -03:00
|
|
|
void SetOrientation(const Matrix3f &rotationMatrix);
|
2010-10-09 20:22:46 -03:00
|
|
|
void SetOffsets(int x, int y, int z);
|
|
|
|
void SetDeclination(float radians);
|
2010-05-28 11:38:51 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
extern APM_Compass_Class APM_Compass;
|
|
|
|
|
2010-09-27 01:05:10 -03:00
|
|
|
#endif
|