Jim Carver / eCompass_Lib

Dependents:   KL46_eCompass KL46_eCompass_TiltCompensed_Acel-Mag Ragnarok_2ejes compass_acc ... more

Fork of Wi-Go_eCompass_Lib_V3 by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers eCompass_Lib.h Source File

eCompass_Lib.h

00001 /************************************************************************************************
00002 * File       : eCompass.h
00003 * Date       : 18/07/2013 
00004 * Purpose    : Wi-Go eCompass interface and hardware peripherals definition 
00005 * Author     : Frank Vannieuwkerke
00006 * Description: ported from Avnet Wi-Go code
00007 *              For additional information on Wi-Go please visit
00008 *                    www.em.avnet.com/wi-go
00009 *              Additional info on the Freescale eCompass software is available at
00010 *                    http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=E-Compass
00011 ************************************************************************************************/
00012 #ifndef ECOMPASS_H__
00013 #define ECOMPASS_H__
00014 
00015 #include "mbed.h"
00016 #include "MotionSensor.h"
00017 
00018 
00019 #ifdef  __cplusplus
00020 extern "C" {
00021 #endif
00022 
00023 typedef short int16;
00024 typedef unsigned short uint16;
00025 typedef unsigned int uint32;
00026 typedef unsigned char byte;
00027 
00028 extern void run_eCompass(void);
00029 extern void init_eCompass(void);
00030 extern void calibrate_eCompass(void);
00031 
00032 #define NED_COMPASS     1
00033 #define ANDROID_COMPASS 2
00034 #define WINDOWS_COMPASS 3
00035 
00036 //  Macros for constants used in fractional decimal conversion routine.
00037 //  FRAC_2d1 = 2^-1 = 0.5
00038 //  FRAC_2d2 = 2^-2 = 0.25 etc...
00039 #define FRAC_2d1              5000
00040 #define FRAC_2d2              2500
00041 #define FRAC_2d3              1250
00042 #define FRAC_2d4               625  
00043 
00044 // sensor scaling constants
00045 #define FCOUNTSPERUT 10.0F              // sensor specific: MAG3110 provide 10 counts / uT 
00046 #define FCOUNTSPERG 4096.0F             // sensor specific: MMA8451 provide 4096 counts / g in 2g mode
00047 
00048 typedef struct  {
00049     // Always 1
00050        uint16              packet_id;
00051     // Light sensor
00052        int16               light;
00053     // Counts at a 0.020MS interval when sensor data is processed
00054        uint32              timestamp;
00055     // Ineeger data from accelerometer
00056        int16               acc_x, acc_y, acc_z;
00057     // Integer data from Magnetometer
00058        int16               mag_x, mag_y, mag_z;
00059      // Roll, Pitch, Yaw and Compass from the eCompass algorithm
00060        int16               roll, pitch, yaw, compass;
00061     // Altitude and temperature
00062        int16               alt, temp;
00063     // Data from Accelerometer converted to floating point
00064        float               fax, fay, faz;
00065     // Accelerometer data converted to G's
00066        float               fGax, fGay, fGaz;
00067     // Data from Magnetometer converted to floating point
00068        float               fmx, fmy, fmz;
00069     // Magnetometer data converted to UT's
00070        float               fUTmx, fUTmy, fUTmz;
00071        float               q0, q1, q2, q3;
00072     
00073 } axis6_t;
00074 
00075 class eCompass
00076 {
00077 public:
00078     eCompass();
00079     void run(MotionSensorDataCounts &acc_raw, MotionSensorDataCounts &mag_raw);
00080     void calibrate(void);
00081     void init(void);
00082     
00083 
00084 private:
00085 };
00086 
00087 #ifdef  __cplusplus
00088 }
00089 #endif
00090 
00091 #endif