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

Committer:
Ductapemaster
Date:
Thu Feb 02 08:50:58 2012 +0000
Revision:
12:cab3f7305522
Parent:
10:85636c7eb8aa
Child:
13:eca05448904d
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.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ductapemaster 12:cab3f7305522 1 /* Atmel Inertial One IMU Library
Ductapemaster 12:cab3f7305522 2 * Copyright (c) 2012 Daniel Kouba
Ductapemaster 12:cab3f7305522 3 *
Ductapemaster 12:cab3f7305522 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
Ductapemaster 12:cab3f7305522 5 * of this software and associated documentation files (the "Software"), to deal
Ductapemaster 12:cab3f7305522 6 * in the Software without restriction, including without limitation the rights
Ductapemaster 12:cab3f7305522 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Ductapemaster 12:cab3f7305522 8 * copies of the Software, and to permit persons to whom the Software is
Ductapemaster 12:cab3f7305522 9 * furnished to do so, subject to the following conditions:
Ductapemaster 12:cab3f7305522 10 *
Ductapemaster 12:cab3f7305522 11 * The above copyright notice and this permission notice shall be included in
Ductapemaster 12:cab3f7305522 12 * all copies or substantial portions of the Software.
Ductapemaster 12:cab3f7305522 13 *
Ductapemaster 12:cab3f7305522 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Ductapemaster 12:cab3f7305522 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Ductapemaster 12:cab3f7305522 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Ductapemaster 12:cab3f7305522 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Ductapemaster 12:cab3f7305522 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Ductapemaster 12:cab3f7305522 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Ductapemaster 12:cab3f7305522 20 * THE SOFTWARE.
Ductapemaster 12:cab3f7305522 21 */
Ductapemaster 12:cab3f7305522 22
Ductapemaster 12:cab3f7305522 23 #ifndef IMU_AIO_H //IMU Atmel Inertial One
Ductapemaster 12:cab3f7305522 24 #define IMU_AIO_H
Ductapemaster 12:cab3f7305522 25
Ductapemaster 12:cab3f7305522 26 #include "mbed.h"
Ductapemaster 12:cab3f7305522 27
Ductapemaster 12:cab3f7305522 28 /* Defines */
Ductapemaster 12:cab3f7305522 29
Ductapemaster 12:cab3f7305522 30 //7 bit I2C Addresses, shifted left to allow for read/write bit as LSB
Ductapemaster 12:cab3f7305522 31
Ductapemaster 12:cab3f7305522 32 #define GYRO_ADR 0x68 << 1
Ductapemaster 12:cab3f7305522 33 #define ACC_ADR 0x38 << 1
Ductapemaster 12:cab3f7305522 34 #define COMP_ADR 0x0C << 1
Ductapemaster 12:cab3f7305522 35
Ductapemaster 12:cab3f7305522 36 // ITG3200 Gyro Registers
Ductapemaster 12:cab3f7305522 37
Ductapemaster 12:cab3f7305522 38 #define GYRO_WHO_AM_I_REG 0x00
Ductapemaster 12:cab3f7305522 39 #define GYRO_SAMPLE_DIV_REG 0x15
Ductapemaster 12:cab3f7305522 40 #define GYRO_DLPF_REG 0x16
Ductapemaster 12:cab3f7305522 41 #define GYRO_INT_CFG_REG 0x17
Ductapemaster 12:cab3f7305522 42 #define GYRO_INT_STATUS_REG 0x1A
Ductapemaster 12:cab3f7305522 43 #define GYRO_TEMP_H_REG 0x1B
Ductapemaster 12:cab3f7305522 44 #define GYRO_TEMP_L_REG 0x1C
Ductapemaster 12:cab3f7305522 45 #define GYRO_XOUT_H_REG 0x1D
Ductapemaster 12:cab3f7305522 46 #define GYRO_XOUT_L_REG 0x1E
Ductapemaster 12:cab3f7305522 47 #define GYRO_YOUT_H_REG 0x1F
Ductapemaster 12:cab3f7305522 48 #define GYRO_YOUT_L_REG 0x20
Ductapemaster 12:cab3f7305522 49 #define GYRO_ZOUT_H_REG 0x21
Ductapemaster 12:cab3f7305522 50 #define GYRO_ZOUT_L_REG 0x22
Ductapemaster 12:cab3f7305522 51
Ductapemaster 12:cab3f7305522 52 // Gyro LPF bandwidths
Ductapemaster 12:cab3f7305522 53
Ductapemaster 12:cab3f7305522 54 #define BW_256HZ 0x00 //8kHz sample rate
Ductapemaster 12:cab3f7305522 55 #define BW_188HZ 0x01 //1kHz sample rate for 188Hz and below
Ductapemaster 12:cab3f7305522 56 #define BW_98HZ 0x02
Ductapemaster 12:cab3f7305522 57 #define BW_42HZ 0x03
Ductapemaster 12:cab3f7305522 58 #define BW_20HZ 0x04
Ductapemaster 12:cab3f7305522 59 #define BW_10HZ 0x05
Ductapemaster 12:cab3f7305522 60 #define BW_5HZ 0x06
Ductapemaster 12:cab3f7305522 61
Ductapemaster 12:cab3f7305522 62 // Gyro Initial FS_SEL Register Config
Ductapemaster 12:cab3f7305522 63
Ductapemaster 12:cab3f7305522 64 #define FS_SEL_INIT 0x03 << 3
Ductapemaster 12:cab3f7305522 65
Ductapemaster 12:cab3f7305522 66 // BMA150 Accelerometer Registers
Ductapemaster 12:cab3f7305522 67
Ductapemaster 12:cab3f7305522 68
Ductapemaster 12:cab3f7305522 69
Ductapemaster 12:cab3f7305522 70 // AK8973 Compass Registers
Ductapemaster 12:cab3f7305522 71
Ductapemaster 12:cab3f7305522 72
Ductapemaster 12:cab3f7305522 73 /** Atmel Inertial One IMU Control Class
Ductapemaster 12:cab3f7305522 74 *
Ductapemaster 12:cab3f7305522 75 * Includes control routines for:
Ductapemaster 12:cab3f7305522 76 * - ITG-3200 3-axis, 16 bit gyroscope
Ductapemaster 12:cab3f7305522 77 * - BMA-150 3-axis, 16 bit accelerometer
Ductapemaster 12:cab3f7305522 78 * - AK8975 3-axis, 16 bit magnetometer
Ductapemaster 12:cab3f7305522 79 *
Ductapemaster 12:cab3f7305522 80 * Datasheets:
Ductapemaster 12:cab3f7305522 81 *
Ductapemaster 12:cab3f7305522 82 * http://www.atmel.com/dyn/resources/prod_documents/doc8354.pdf
Ductapemaster 12:cab3f7305522 83 *
Ductapemaster 12:cab3f7305522 84 * http://invensense.com/mems/gyro/documents/PS-ITG-3200A.pdf
Ductapemaster 12:cab3f7305522 85 *
Ductapemaster 12:cab3f7305522 86 * http://www.bosch-sensortec.com/content/language1/downloads/BMA150_DataSheet_Rev.1.5_30May2008.pdf
Ductapemaster 12:cab3f7305522 87 *
Ductapemaster 12:cab3f7305522 88 * http://pdf1.alldatasheet.com/datasheet-pdf/view/219477/AKM/AK8973/+Q18W89VYpLawLCDwv+/datasheet.pdf
Ductapemaster 12:cab3f7305522 89 *
Ductapemaster 12:cab3f7305522 90 */
Ductapemaster 12:cab3f7305522 91 class IMU {
Ductapemaster 12:cab3f7305522 92
Ductapemaster 12:cab3f7305522 93 public:
Ductapemaster 12:cab3f7305522 94
Ductapemaster 12:cab3f7305522 95 /** Creates IMU object and initializes all three chips
Ductapemaster 12:cab3f7305522 96 *
Ductapemaster 12:cab3f7305522 97 * Gyro: FS_SEL register is set to 0x03, as required by datasheet
Ductapemaster 12:cab3f7305522 98 *
Ductapemaster 12:cab3f7305522 99 * Accelerometer:
Ductapemaster 12:cab3f7305522 100 *
Ductapemaster 12:cab3f7305522 101 * Compass:
Ductapemaster 12:cab3f7305522 102 *
Ductapemaster 12:cab3f7305522 103 * @param sda pin for I2C sda signal
Ductapemaster 12:cab3f7305522 104 * @param scl pin for I2C scl signal
Ductapemaster 12:cab3f7305522 105 */
Ductapemaster 12:cab3f7305522 106 IMU(PinName sda, PinName scl);
Ductapemaster 12:cab3f7305522 107
Ductapemaster 12:cab3f7305522 108 /* Gyro Methods */
Ductapemaster 12:cab3f7305522 109
Ductapemaster 12:cab3f7305522 110 /** Gets current X axis gyro measurement
Ductapemaster 12:cab3f7305522 111 *
Ductapemaster 12:cab3f7305522 112 * @return Raw X axis ADC measurement (signed 16 bits)
Ductapemaster 12:cab3f7305522 113 */
Ductapemaster 12:cab3f7305522 114 int gyroX(void);
Ductapemaster 12:cab3f7305522 115
Ductapemaster 12:cab3f7305522 116 /** Gets current Y axis gyro measurement
Ductapemaster 12:cab3f7305522 117 *
Ductapemaster 12:cab3f7305522 118 * @return Raw Y axis ADC measurement (signed 16 bits)
Ductapemaster 12:cab3f7305522 119 */
Ductapemaster 12:cab3f7305522 120 int gyroY(void);
Ductapemaster 12:cab3f7305522 121
Ductapemaster 12:cab3f7305522 122 /** Gets current Z axis gyro measurement
Ductapemaster 12:cab3f7305522 123 *
Ductapemaster 12:cab3f7305522 124 * @return Raw Z axis ADC measurement (signed 16 bits)
Ductapemaster 12:cab3f7305522 125 */
Ductapemaster 12:cab3f7305522 126 int gyroZ(void);
Ductapemaster 12:cab3f7305522 127
Ductapemaster 12:cab3f7305522 128 /** Gets current ADC data from all axes of gyro (uses burst read mode)
Ductapemaster 12:cab3f7305522 129 *
Ductapemaster 12:cab3f7305522 130 * @return Array of X, Y, and Z axis gyro measurements (signed 16 bits)
Ductapemaster 12:cab3f7305522 131 */
Ductapemaster 12:cab3f7305522 132 int* gyroXYZ(void);
Ductapemaster 12:cab3f7305522 133
Ductapemaster 12:cab3f7305522 134 /** Sets digital LPF bandwidth for all gyro channels
Ductapemaster 12:cab3f7305522 135 *
Ductapemaster 12:cab3f7305522 136 * @param _BW Filter Bandwidth (use defined bandwidths)
Ductapemaster 12:cab3f7305522 137 */
Ductapemaster 12:cab3f7305522 138 void gyroSetLPF(char _BW);
Ductapemaster 12:cab3f7305522 139
Ductapemaster 12:cab3f7305522 140 /* Accelerometer Methods */
Ductapemaster 12:cab3f7305522 141
Ductapemaster 12:cab3f7305522 142
Ductapemaster 12:cab3f7305522 143
Ductapemaster 12:cab3f7305522 144 /* Compass Methods */
Ductapemaster 12:cab3f7305522 145
Ductapemaster 12:cab3f7305522 146
Ductapemaster 12:cab3f7305522 147
Ductapemaster 12:cab3f7305522 148 private:
Ductapemaster 12:cab3f7305522 149
Ductapemaster 12:cab3f7305522 150 I2C _i2c; //I2C object constructor
Ductapemaster 12:cab3f7305522 151
Ductapemaster 12:cab3f7305522 152 };
Ductapemaster 12:cab3f7305522 153
Ductapemaster 0:5a636973285e 154 #endif