IMU 10dof MEMS from DR Robot adapted from HK10DOF Changed gyro to ITG3200

Fork of HK10DOF by Aloïs Wolff

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ITG3200.h Source File

ITG3200.h

00001 /**
00002  * @author Larry Littlefield http://kb7kmo.blogspot.com
00003  * lots of copping
00004  * Ported from Pololu L3G4200D library for Arduino by
00005  * @author Michael Shimniok http://bot-thoughts.com
00006  * @author Uwe Gartmann
00007  * @author Used ITG3200 library developed Aaron Berk as template
00008  *
00009  * @section LICENSE
00010  *
00011  * Copyright (c) 2010 ARM Limited
00012  *
00013  * Permission is hereby granted, free of charge, to any person obtaining a copy
00014  * of this software and associated documentation files (the "Software"), to deal
00015  * in the Software without restriction, including without limitation the rights
00016  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00017  * copies of the Software, and to permit persons to whom the Software is
00018  * furnished to do so, subject to the following conditions:
00019  *
00020  * The above copyright notice and this permission notice shall be included in
00021  * all copies or substantial portions of the Software.
00022  *
00023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00024  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00025  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00026  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00027  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00028  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00029  * THE SOFTWARE.
00030  *
00031  * @section DESCRIPTION
00032  *
00033  * ITG-3200 triple axis, digital interface, gyroscope.
00034  *
00035  * Datasheet:
00036  *
00037  * http://invensense.com/mems/gyro/documents/PS-ITG-3200-00-01.4.pdf
00038  */
00039 
00040 #ifndef ITG3200_H
00041 #define ITG3200_H
00042 
00043 /**
00044  * Includes
00045  */
00046 #include "mbed.h"
00047 
00048 /** Interface library for the ITG3200 3-axis gyro
00049  *
00050  * Ported from Pololu L3G4200D library for Arduino by
00051  * Michael Shimniok http://bot-thoughts.com
00052  * Then ported to ITG3200 by
00053  * Larry Littlefield http://kb7kmo.blogspot.com
00054  *
00055  * testing target: NUCLEO-F401RE
00056  * The reason for port is to make compatable calls so it can replace the 
00057  * L3G4200D library in the renamed HK10DOK sensor library
00058  * new lib name is IMU10DOF
00059  * 
00060  * @code
00061  * #include "mbed.h"
00062  * #include "ITG3200.h"
00063  * ITG3200 gyro(p28, p27);
00064  * ...
00065  * int g[3];
00066  * gyro.read(g);
00067  * @endcode
00068  */typedef char byte;
00069 /**
00070  * Defines
00071  */
00072 #define ITG3200_I2C_ADDRESS 0x68 //7-bit address.
00073 
00074 //-----------
00075 // Registers
00076 //-----------
00077 #define WHO_AM_I_REG    0x00
00078 #define SMPLRT_DIV_REG  0x15
00079 #define DLPF_FS_REG     0x16
00080 #define INT_CFG_REG     0x17
00081 #define INT_STATUS      0x1A
00082 #define TEMP_OUT_H_REG  0x1B
00083 #define TEMP_OUT_L_REG  0x1C
00084 #define GYRO_XOUT_H_REG 0x1D
00085 #define GYRO_XOUT_L_REG 0x1E
00086 #define GYRO_YOUT_H_REG 0x1F
00087 #define GYRO_YOUT_L_REG 0x20
00088 #define GYRO_ZOUT_H_REG 0x21
00089 #define GYRO_ZOUT_L_REG 0x22
00090 #define PWR_MGM_REG     0x3E
00091 
00092 //----------------------------
00093 // Low Pass Filter Bandwidths
00094 //----------------------------
00095 #define LPFBW_256HZ 0x00
00096 #define LPFBW_188HZ 0x01
00097 #define LPFBW_98HZ  0x02
00098 #define LPFBW_42HZ  0x03
00099 #define LPFBW_20HZ  0x04
00100 #define LPFBW_10HZ  0x05
00101 #define LPFBW_5HZ   0x06
00102 
00103 /**
00104  * ITG-3200 triple axis digital gyroscope.
00105  */
00106 
00107 class ITG3200
00108 {
00109     public:
00110         /** Create a new ITG3200 I2C interface
00111          * @param sda is the pin for the I2C SDA line
00112          * @param scl is the pin for the I2C SCL line
00113          */
00114         ITG3200(PinName sda, PinName scl);
00115         
00116         /** Read gyro values
00117          * @param g Array containing x, y, and z gyro values
00118          * @return g Array containing x, y, and z gyro values
00119          */
00120         void init(void);
00121         
00122         void status(byte *s); // read first 4 status registers of ITG3200 into passed array
00123         
00124         /** Read gyro values
00125          * @param g Array containing x, y, and z gyro values
00126          * modifies the g Array containing x, y, and z gyro values
00127          */
00128         void read(int *g);
00129         
00130         /** Read3 gyro values as integers
00131          * @param int x, y, and z gyro values
00132          * modifies the int x, y, and z gyro values
00133          */
00134         void read3(int x, int y, int z);
00135         
00136         /** Reads 
00137          * @parm unsigned int totSamples with 
00138          * @parm unsigned int sampleDelayMS
00139          * then saves the calculated offsetsto private variables
00140          */
00141         void zeroCalibrate(unsigned int totSamples, unsigned int sampleDelayMS);
00142         
00143         /** calls read with an array pointer, adds offsets to modify the array
00144          * x,y,z will contain calibrated integer values from the sensor
00145          */
00146         void readRawCal(int *_GyroXYZ);
00147         
00148         /** calls readRawCal multiplies gains to modify the array
00149          */
00150         void readFin(float *_GyroXYZ); // includes gain and offset
00151         
00152     private:
00153         volatile float gains[3]; 
00154         volatile int offsets[3];
00155         volatile float polarities[3];
00156         
00157         void setGains(float _Xgain, float _Ygain, float _Zgain);
00158         void setOffsets(int _Xoffset, int _Yoffset, int _Zoffset);
00159         void setRevPolarity(bool _Xpol, bool _Ypol, bool _Zpol);  // true = Reversed  false = default
00160     
00161     
00162         byte data[6];
00163         int _rates[3];
00164         I2C _device;
00165         void writeReg(byte reg, byte value);
00166         byte readReg(byte reg);
00167         void enableDefault(void);
00168 };
00169 
00170 #endif /* ITG3200_H */