Ported to have same calls as L3G4200D lib so it can be substituted in HK10dof library ( which is being modified to use this and renamed IMU10DOF) platform NUCLEO-F401

WARNING: This project is not complete, but this library seems ok so far.

I have the module DFRobotics.com 10DOF MEMS IMU. I wanted a consise module for resolving direction and movement.

I found HK10DOF library (http://developer.mbed.org/users/pommzorz/code/HK10DOF/) with quaternions. But it used a different gyro. So I modified that code to use the same higher level calls but use the ITG3200 low level calls.

Committer:
svkatielee
Date:
Mon Nov 17 11:05:55 2014 +0000
Revision:
0:13648b72bdf8
Modified the L3G4200D gyro lib to be ITG3200 with the same calls so it can be substituted in HK10DOF MEMS library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
svkatielee 0:13648b72bdf8 1 /**
svkatielee 0:13648b72bdf8 2 * @author Larry Littlefield http://kb7kmo.blogspot.com
svkatielee 0:13648b72bdf8 3 * lots of copping
svkatielee 0:13648b72bdf8 4 * Ported from Pololu L3G4200D library for Arduino by
svkatielee 0:13648b72bdf8 5 * @author Michael Shimniok http://bot-thoughts.com
svkatielee 0:13648b72bdf8 6 * @author Uwe Gartmann
svkatielee 0:13648b72bdf8 7 * @author Used ITG3200 library developed Aaron Berk as template
svkatielee 0:13648b72bdf8 8 *
svkatielee 0:13648b72bdf8 9 * @section LICENSE
svkatielee 0:13648b72bdf8 10 *
svkatielee 0:13648b72bdf8 11 * Copyright (c) 2010 ARM Limited
svkatielee 0:13648b72bdf8 12 *
svkatielee 0:13648b72bdf8 13 * Permission is hereby granted, free of charge, to any person obtaining a copy
svkatielee 0:13648b72bdf8 14 * of this software and associated documentation files (the "Software"), to deal
svkatielee 0:13648b72bdf8 15 * in the Software without restriction, including without limitation the rights
svkatielee 0:13648b72bdf8 16 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
svkatielee 0:13648b72bdf8 17 * copies of the Software, and to permit persons to whom the Software is
svkatielee 0:13648b72bdf8 18 * furnished to do so, subject to the following conditions:
svkatielee 0:13648b72bdf8 19 *
svkatielee 0:13648b72bdf8 20 * The above copyright notice and this permission notice shall be included in
svkatielee 0:13648b72bdf8 21 * all copies or substantial portions of the Software.
svkatielee 0:13648b72bdf8 22 *
svkatielee 0:13648b72bdf8 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
svkatielee 0:13648b72bdf8 24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
svkatielee 0:13648b72bdf8 25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
svkatielee 0:13648b72bdf8 26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
svkatielee 0:13648b72bdf8 27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
svkatielee 0:13648b72bdf8 28 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
svkatielee 0:13648b72bdf8 29 * THE SOFTWARE.
svkatielee 0:13648b72bdf8 30 *
svkatielee 0:13648b72bdf8 31 * @section DESCRIPTION
svkatielee 0:13648b72bdf8 32 *
svkatielee 0:13648b72bdf8 33 * ITG-3200 triple axis, digital interface, gyroscope.
svkatielee 0:13648b72bdf8 34 *
svkatielee 0:13648b72bdf8 35 * Datasheet:
svkatielee 0:13648b72bdf8 36 *
svkatielee 0:13648b72bdf8 37 * http://invensense.com/mems/gyro/documents/PS-ITG-3200-00-01.4.pdf
svkatielee 0:13648b72bdf8 38 */
svkatielee 0:13648b72bdf8 39
svkatielee 0:13648b72bdf8 40 #ifndef ITG3200_H
svkatielee 0:13648b72bdf8 41 #define ITG3200_H
svkatielee 0:13648b72bdf8 42
svkatielee 0:13648b72bdf8 43 /**
svkatielee 0:13648b72bdf8 44 * Includes
svkatielee 0:13648b72bdf8 45 */
svkatielee 0:13648b72bdf8 46 #include "mbed.h"
svkatielee 0:13648b72bdf8 47
svkatielee 0:13648b72bdf8 48 /** Interface library for the ITG3200 3-axis gyro
svkatielee 0:13648b72bdf8 49 *
svkatielee 0:13648b72bdf8 50 * Ported from Pololu L3G4200D library for Arduino by
svkatielee 0:13648b72bdf8 51 * Michael Shimniok http://bot-thoughts.com
svkatielee 0:13648b72bdf8 52 * Then ported to ITG3200 by
svkatielee 0:13648b72bdf8 53 * Larry Littlefield http://kb7kmo.blogspot.com
svkatielee 0:13648b72bdf8 54 *
svkatielee 0:13648b72bdf8 55 * testing target: NUCLEO-F401RE
svkatielee 0:13648b72bdf8 56 * The reason for port is to make compatable calls so it can replace the
svkatielee 0:13648b72bdf8 57 * L3G4200D library in the renamed HK10DOK sensor library
svkatielee 0:13648b72bdf8 58 * new lib name is IMU10DOF
svkatielee 0:13648b72bdf8 59 *
svkatielee 0:13648b72bdf8 60 * @code
svkatielee 0:13648b72bdf8 61 * #include "mbed.h"
svkatielee 0:13648b72bdf8 62 * #include "ITG3200.h"
svkatielee 0:13648b72bdf8 63 * ITG3200 gyro(p28, p27);
svkatielee 0:13648b72bdf8 64 * ...
svkatielee 0:13648b72bdf8 65 * int g[3];
svkatielee 0:13648b72bdf8 66 * gyro.read(g);
svkatielee 0:13648b72bdf8 67 * @endcode
svkatielee 0:13648b72bdf8 68 */typedef char byte;
svkatielee 0:13648b72bdf8 69 /**
svkatielee 0:13648b72bdf8 70 * Defines
svkatielee 0:13648b72bdf8 71 */
svkatielee 0:13648b72bdf8 72 #define ITG3200_I2C_ADDRESS 0x68 //7-bit address.
svkatielee 0:13648b72bdf8 73
svkatielee 0:13648b72bdf8 74 //-----------
svkatielee 0:13648b72bdf8 75 // Registers
svkatielee 0:13648b72bdf8 76 //-----------
svkatielee 0:13648b72bdf8 77 #define WHO_AM_I_REG 0x00
svkatielee 0:13648b72bdf8 78 #define SMPLRT_DIV_REG 0x15
svkatielee 0:13648b72bdf8 79 #define DLPF_FS_REG 0x16
svkatielee 0:13648b72bdf8 80 #define INT_CFG_REG 0x17
svkatielee 0:13648b72bdf8 81 #define INT_STATUS 0x1A
svkatielee 0:13648b72bdf8 82 #define TEMP_OUT_H_REG 0x1B
svkatielee 0:13648b72bdf8 83 #define TEMP_OUT_L_REG 0x1C
svkatielee 0:13648b72bdf8 84 #define GYRO_XOUT_H_REG 0x1D
svkatielee 0:13648b72bdf8 85 #define GYRO_XOUT_L_REG 0x1E
svkatielee 0:13648b72bdf8 86 #define GYRO_YOUT_H_REG 0x1F
svkatielee 0:13648b72bdf8 87 #define GYRO_YOUT_L_REG 0x20
svkatielee 0:13648b72bdf8 88 #define GYRO_ZOUT_H_REG 0x21
svkatielee 0:13648b72bdf8 89 #define GYRO_ZOUT_L_REG 0x22
svkatielee 0:13648b72bdf8 90 #define PWR_MGM_REG 0x3E
svkatielee 0:13648b72bdf8 91
svkatielee 0:13648b72bdf8 92 //----------------------------
svkatielee 0:13648b72bdf8 93 // Low Pass Filter Bandwidths
svkatielee 0:13648b72bdf8 94 //----------------------------
svkatielee 0:13648b72bdf8 95 #define LPFBW_256HZ 0x00
svkatielee 0:13648b72bdf8 96 #define LPFBW_188HZ 0x01
svkatielee 0:13648b72bdf8 97 #define LPFBW_98HZ 0x02
svkatielee 0:13648b72bdf8 98 #define LPFBW_42HZ 0x03
svkatielee 0:13648b72bdf8 99 #define LPFBW_20HZ 0x04
svkatielee 0:13648b72bdf8 100 #define LPFBW_10HZ 0x05
svkatielee 0:13648b72bdf8 101 #define LPFBW_5HZ 0x06
svkatielee 0:13648b72bdf8 102
svkatielee 0:13648b72bdf8 103 /**
svkatielee 0:13648b72bdf8 104 * ITG-3200 triple axis digital gyroscope.
svkatielee 0:13648b72bdf8 105 */
svkatielee 0:13648b72bdf8 106
svkatielee 0:13648b72bdf8 107 class ITG3200
svkatielee 0:13648b72bdf8 108 {
svkatielee 0:13648b72bdf8 109 public:
svkatielee 0:13648b72bdf8 110 /** Create a new ITG3200 I2C interface
svkatielee 0:13648b72bdf8 111 * @param sda is the pin for the I2C SDA line
svkatielee 0:13648b72bdf8 112 * @param scl is the pin for the I2C SCL line
svkatielee 0:13648b72bdf8 113 */
svkatielee 0:13648b72bdf8 114 ITG3200(PinName sda, PinName scl);
svkatielee 0:13648b72bdf8 115
svkatielee 0:13648b72bdf8 116 /** Read gyro values
svkatielee 0:13648b72bdf8 117 * @param g Array containing x, y, and z gyro values
svkatielee 0:13648b72bdf8 118 * @return g Array containing x, y, and z gyro values
svkatielee 0:13648b72bdf8 119 */
svkatielee 0:13648b72bdf8 120 void init(void);
svkatielee 0:13648b72bdf8 121
svkatielee 0:13648b72bdf8 122 void status(byte *s); // read first 4 status registers of ITG3200 into passed array
svkatielee 0:13648b72bdf8 123
svkatielee 0:13648b72bdf8 124 /** Read gyro values
svkatielee 0:13648b72bdf8 125 * @param g Array containing x, y, and z gyro values
svkatielee 0:13648b72bdf8 126 * modifies the g Array containing x, y, and z gyro values
svkatielee 0:13648b72bdf8 127 */
svkatielee 0:13648b72bdf8 128 void read(int *g);
svkatielee 0:13648b72bdf8 129
svkatielee 0:13648b72bdf8 130 /** Read3 gyro values as integers
svkatielee 0:13648b72bdf8 131 * @param int x, y, and z gyro values
svkatielee 0:13648b72bdf8 132 * modifies the int x, y, and z gyro values
svkatielee 0:13648b72bdf8 133 */
svkatielee 0:13648b72bdf8 134 void read3(int x, int y, int z);
svkatielee 0:13648b72bdf8 135
svkatielee 0:13648b72bdf8 136 /** Reads
svkatielee 0:13648b72bdf8 137 * @parm unsigned int totSamples with
svkatielee 0:13648b72bdf8 138 * @parm unsigned int sampleDelayMS
svkatielee 0:13648b72bdf8 139 * then saves the calculated offsetsto private variables
svkatielee 0:13648b72bdf8 140 */
svkatielee 0:13648b72bdf8 141 void zeroCalibrate(unsigned int totSamples, unsigned int sampleDelayMS);
svkatielee 0:13648b72bdf8 142
svkatielee 0:13648b72bdf8 143 /** calls read with an array pointer, adds offsets to modify the array
svkatielee 0:13648b72bdf8 144 * x,y,z will contain calibrated integer values from the sensor
svkatielee 0:13648b72bdf8 145 */
svkatielee 0:13648b72bdf8 146 void readRawCal(int *_GyroXYZ);
svkatielee 0:13648b72bdf8 147
svkatielee 0:13648b72bdf8 148 /** calls readRawCal multiplies gains to modify the array
svkatielee 0:13648b72bdf8 149 */
svkatielee 0:13648b72bdf8 150 void readFin(float *_GyroXYZ); // includes gain and offset
svkatielee 0:13648b72bdf8 151
svkatielee 0:13648b72bdf8 152 private:
svkatielee 0:13648b72bdf8 153 volatile float gains[3];
svkatielee 0:13648b72bdf8 154 volatile int offsets[3];
svkatielee 0:13648b72bdf8 155 volatile float polarities[3];
svkatielee 0:13648b72bdf8 156
svkatielee 0:13648b72bdf8 157 void setGains(float _Xgain, float _Ygain, float _Zgain);
svkatielee 0:13648b72bdf8 158 void setOffsets(int _Xoffset, int _Yoffset, int _Zoffset);
svkatielee 0:13648b72bdf8 159 void setRevPolarity(bool _Xpol, bool _Ypol, bool _Zpol); // true = Reversed false = default
svkatielee 0:13648b72bdf8 160
svkatielee 0:13648b72bdf8 161
svkatielee 0:13648b72bdf8 162 byte data[6];
svkatielee 0:13648b72bdf8 163 int _rates[3];
svkatielee 0:13648b72bdf8 164 I2C _device;
svkatielee 0:13648b72bdf8 165 void writeReg(byte reg, byte value);
svkatielee 0:13648b72bdf8 166 byte readReg(byte reg);
svkatielee 0:13648b72bdf8 167 void enableDefault(void);
svkatielee 0:13648b72bdf8 168 };
svkatielee 0:13648b72bdf8 169
svkatielee 0:13648b72bdf8 170 #endif /* ITG3200_H */