Interface library for the Atmel Inertial One IMU. Contains drivers for the ITG 3200 3 axis gyro, BMA-150 3 axis accelerometer, and AK8975 3 axis compass

Files at this revision

API Documentation at this revision

Comitter:
Ductapemaster
Date:
Thu Feb 02 08:50:58 2012 +0000
Parent:
11:a70c76711630
Child:
13:eca05448904d
Commit message:
Fixed return values for gyroX, gyroY, and gryoZ functions, now return a proper 16 bit signed value. gyroXYZ has not been fixed, and the LPf bandwidth method has not been tested.

Changed in this revision

IMU.cpp Show annotated file Show diff for this revision Revisions of this file
IMU.h Show annotated file Show diff for this revision Revisions of this file
--- a/IMU.cpp	Thu Feb 02 08:31:20 2012 +0000
+++ b/IMU.cpp	Thu Feb 02 08:50:58 2012 +0000
@@ -47,7 +47,7 @@
     _i2c.write(GYRO_ADR, &poke, 1, false);
     _i2c.read(GYRO_ADR, peek, 2, false);
     
-    int result = ( peek[0] << 8 | peek[1] );
+    int16_t result = ( peek[0] << 8 | peek[1] );
     return result;
     
  }
@@ -60,7 +60,7 @@
     _i2c.write(GYRO_ADR, &poke, 1, false);
     _i2c.read(GYRO_ADR, peek, 2, false);
     
-    int result = ( peek[0] << 8 | peek[1] );
+    int16_t result = ( peek[0] << 8 | peek[1] );
     return result;
     
  }
@@ -73,7 +73,7 @@
     _i2c.write(GYRO_ADR, &poke, 1, false);
     _i2c.read(GYRO_ADR, peek, 2, false);
     
-    int result = ( peek[0] << 8 | peek[1] );
+    int16_t result = ( peek[0] << 8 | peek[1] );
     return result;
 
  }
@@ -86,7 +86,7 @@
     _i2c.write(GYRO_ADR, &poke, 1, false);
     _i2c.read(GYRO_ADR, peek, 6, false);
     
-    int result[3] = [ 
+    int result[] = { 
         ( peek[0] << 8 | peek[1] ),     // X
         ( peek[2] << 8 | peek[3] ),     // Y
         ( peek[4] << 8 | peek[5] )      // Z
@@ -97,7 +97,7 @@
 
  void IMU::gyroSetLPF(char _BW) {
  
-    char poke[2] = [ GYRO_DLPF_REG, _BW };
+    char poke[2] = { GYRO_DLPF_REG, _BW };
     
     _i2c.write(GYRO_ADR, poke, 2, false);
     
--- a/IMU.h	Thu Feb 02 08:31:20 2012 +0000
+++ b/IMU.h	Thu Feb 02 08:50:58 2012 +0000
@@ -1,154 +1,154 @@
-/* Atmel Inertial One IMU Library
- * Copyright (c) 2012 Daniel Kouba
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- 
- #ifndef IMU_AIO_H        //IMU Atmel Inertial One
- #define IMU_AIO_H
- 
- #include "mbed.h"
- 
- /* Defines */
- 
- //7 bit I2C Addresses, shifted left to allow for read/write bit as LSB
- 
- #define GYRO_ADR  0x68 << 1
- #define ACC_ADR   0x38 << 1
- #define COMP_ADR  0x0C << 1
- 
- // ITG3200 Gyro Registers
- 
- #define GYRO_WHO_AM_I_REG         0x00
- #define GYRO_SAMPLE_DIV_REG       0x15
- #define GYRO_DLPF_REG             0x16
- #define GYRO_INT_CFG_REG          0x17
- #define GYRO_INT_STATUS_REG       0x1A
- #define GYRO_TEMP_H_REG           0x1B
- #define GYRO_TEMP_L_REG           0x1C
- #define GYRO_XOUT_H_REG           0x1D
- #define GYRO_XOUT_L_REG           0x1E
- #define GYRO_YOUT_H_REG           0x1F
- #define GYRO_YOUT_L_REG           0x20
- #define GYRO_ZOUT_H_REG           0x21
- #define GYRO_ZOUT_L_REG           0x22
- 
- // Gyro LPF bandwidths
- 
- #define BW_256HZ       0x00        //8kHz sample rate
- #define BW_188HZ       0x01        //1kHz sample rate for 188Hz and below
- #define BW_98HZ        0x02
- #define BW_42HZ        0x03
- #define BW_20HZ        0x04
- #define BW_10HZ        0x05
- #define BW_5HZ         0x06
- 
- // Gyro Initial FS_SEL Register Config
- 
- #define FS_SEL_INIT   0x03 << 3
-  
- // BMA150 Accelerometer Registers
- 
- 
- 
- // AK8973 Compass Registers
-
- 
- /** Atmel Inertial One IMU Control Class
- * 
- * Includes control routines for:
- * - ITG-3200 3-axis, 16 bit gyroscope
- * - BMA-150 3-axis, 16 bit accelerometer
- * - AK8975 3-axis, 16 bit magnetometer
- *
- * Datasheets:
- *
- * http://www.atmel.com/dyn/resources/prod_documents/doc8354.pdf
- * 
- * http://invensense.com/mems/gyro/documents/PS-ITG-3200A.pdf
- *
- * http://www.bosch-sensortec.com/content/language1/downloads/BMA150_DataSheet_Rev.1.5_30May2008.pdf
- * 
- * http://pdf1.alldatasheet.com/datasheet-pdf/view/219477/AKM/AK8973/+Q18W89VYpLawLCDwv+/datasheet.pdf
- * 
- */
- class IMU {
- 
- public:
- 
-    /** Creates IMU object and initializes all three chips
-    *
-    * Gyro: FS_SEL register is set to 0x03, as required by datasheet
-    *
-    * Accelerometer:
-    *
-    * Compass:
-    *
-    * @param sda pin for I2C sda signal
-    * @param scl pin for I2C scl signal
-    */
-    IMU(PinName sda, PinName scl);
-    
-    /* Gyro Methods */
-    
-    /** Gets current X axis gyro measurement
-    *
-    * @return Raw X axis ADC measurement (signed 16 bits)
-    */
-    int gyroX(void);
-    
-    /** Gets current Y axis gyro measurement
-    * 
-    * @return Raw Y axis ADC measurement (signed 16 bits)
-    */
-    int gyroY(void);
-    
-    /** Gets current Z axis gyro measurement
-    * 
-    * @return Raw Z axis ADC measurement (signed 16 bits)
-    */
-    int gyroZ(void);
-    
-    /** Gets current ADC data from all axes of gyro (uses burst read mode)
-    * 
-    * @return Array of X, Y, and Z axis gyro measurements (signed 16 bits)
-    */
-    int* gyroXYZ(void);
-    
-    /** Sets digital LPF bandwidth for all gyro channels
-    * 
-    * @param _BW Filter Bandwidth (use defined bandwidths)
-    */
-    void gyroSetLPF(char _BW);
-    
-    /* Accelerometer Methods */
-    
-    
-    
-    /* Compass Methods */
-    
-    
- 
- private:
- 
-    I2C _i2c;       //I2C object constructor
- 
- };
- 
+/* Atmel Inertial One IMU Library
+ * Copyright (c) 2012 Daniel Kouba
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+ 
+ #ifndef IMU_AIO_H        //IMU Atmel Inertial One
+ #define IMU_AIO_H
+ 
+ #include "mbed.h"
+ 
+ /* Defines */
+ 
+ //7 bit I2C Addresses, shifted left to allow for read/write bit as LSB
+ 
+ #define GYRO_ADR  0x68 << 1
+ #define ACC_ADR   0x38 << 1
+ #define COMP_ADR  0x0C << 1
+ 
+ // ITG3200 Gyro Registers
+ 
+ #define GYRO_WHO_AM_I_REG         0x00
+ #define GYRO_SAMPLE_DIV_REG       0x15
+ #define GYRO_DLPF_REG             0x16
+ #define GYRO_INT_CFG_REG          0x17
+ #define GYRO_INT_STATUS_REG       0x1A
+ #define GYRO_TEMP_H_REG           0x1B
+ #define GYRO_TEMP_L_REG           0x1C
+ #define GYRO_XOUT_H_REG           0x1D
+ #define GYRO_XOUT_L_REG           0x1E
+ #define GYRO_YOUT_H_REG           0x1F
+ #define GYRO_YOUT_L_REG           0x20
+ #define GYRO_ZOUT_H_REG           0x21
+ #define GYRO_ZOUT_L_REG           0x22
+ 
+ // Gyro LPF bandwidths
+ 
+ #define BW_256HZ       0x00        //8kHz sample rate
+ #define BW_188HZ       0x01        //1kHz sample rate for 188Hz and below
+ #define BW_98HZ        0x02
+ #define BW_42HZ        0x03
+ #define BW_20HZ        0x04
+ #define BW_10HZ        0x05
+ #define BW_5HZ         0x06
+ 
+ // Gyro Initial FS_SEL Register Config
+ 
+ #define FS_SEL_INIT   0x03 << 3
+  
+ // BMA150 Accelerometer Registers
+ 
+ 
+ 
+ // AK8973 Compass Registers
+
+ 
+ /** Atmel Inertial One IMU Control Class
+ * 
+ * Includes control routines for:
+ * - ITG-3200 3-axis, 16 bit gyroscope
+ * - BMA-150 3-axis, 16 bit accelerometer
+ * - AK8975 3-axis, 16 bit magnetometer
+ *
+ * Datasheets:
+ *
+ * http://www.atmel.com/dyn/resources/prod_documents/doc8354.pdf
+ * 
+ * http://invensense.com/mems/gyro/documents/PS-ITG-3200A.pdf
+ *
+ * http://www.bosch-sensortec.com/content/language1/downloads/BMA150_DataSheet_Rev.1.5_30May2008.pdf
+ * 
+ * http://pdf1.alldatasheet.com/datasheet-pdf/view/219477/AKM/AK8973/+Q18W89VYpLawLCDwv+/datasheet.pdf
+ * 
+ */
+ class IMU {
+ 
+ public:
+ 
+    /** Creates IMU object and initializes all three chips
+    *
+    * Gyro: FS_SEL register is set to 0x03, as required by datasheet
+    *
+    * Accelerometer:
+    *
+    * Compass:
+    *
+    * @param sda pin for I2C sda signal
+    * @param scl pin for I2C scl signal
+    */
+    IMU(PinName sda, PinName scl);
+    
+    /* Gyro Methods */
+    
+    /** Gets current X axis gyro measurement
+    *
+    * @return Raw X axis ADC measurement (signed 16 bits)
+    */
+    int gyroX(void);
+    
+    /** Gets current Y axis gyro measurement
+    * 
+    * @return Raw Y axis ADC measurement (signed 16 bits)
+    */
+    int gyroY(void);
+    
+    /** Gets current Z axis gyro measurement
+    * 
+    * @return Raw Z axis ADC measurement (signed 16 bits)
+    */
+    int gyroZ(void);
+    
+    /** Gets current ADC data from all axes of gyro (uses burst read mode)
+    * 
+    * @return Array of X, Y, and Z axis gyro measurements (signed 16 bits)
+    */
+    int* gyroXYZ(void);
+    
+    /** Sets digital LPF bandwidth for all gyro channels
+    * 
+    * @param _BW Filter Bandwidth (use defined bandwidths)
+    */
+    void gyroSetLPF(char _BW);
+    
+    /* Accelerometer Methods */
+    
+    
+    
+    /* Compass Methods */
+    
+    
+ 
+ private:
+ 
+    I2C _i2c;       //I2C object constructor
+ 
+ };
+ 
  #endif
\ No newline at end of file