only test purpose not official
Diff: LSM9DS1.h
- Revision:
- 8:16e88babd42a
- Parent:
- 6:28c4b3c8b43d
- Child:
- 9:e0759c34eb93
--- a/LSM9DS1.h Thu Jun 15 08:42:23 2017 +0000 +++ b/LSM9DS1.h Mon Jun 19 02:25:48 2017 +0000 @@ -104,12 +104,20 @@ public: /// gyro_scale defines the possible full-scale ranges of the gyroscope: + /* enum gyro_scale { G_SCALE_245DPS = 0x0 << 3, // 00 << 3: +/- 245 degrees per second G_SCALE_500DPS = 0x1 << 3, // 01 << 3: +/- 500 dps G_SCALE_2000DPS = 0x3 << 3 // 11 << 3: +/- 2000 dps }; + */ + enum gyro_scale + { + G_SCALE_245DPS = 0x0, // 00: +/- 245 degrees per second + G_SCALE_500DPS = 0x1, // 01: +/- 500 dps + G_SCALE_2000DPS = 0x3 // 11: +/- 2000 dps + }; /// gyro_odr defines all possible data rate/bandwidth combos of the gyro: enum gyro_odr @@ -195,7 +203,7 @@ int16_t ax_raw, ay_raw, az_raw; // x, y, and z axis readings of the accelerometer int16_t mx_raw, my_raw, mz_raw; // x, y, and z axis readings of the magnetometer int16_t temperature_raw; - int16_t gBiasRaw[3], aBiasRaw[3]; + int16_t gBiasRaw[3], aBiasRaw[3]; // floating-point values of scaled data in real-world units float gx, gy, gz; @@ -206,7 +214,7 @@ float gBias[3], aBias[3]; bool autoCalib; - + /** LSM9DS1 -- LSM9DS1 class constructor * The constructor will set up a handful of private variables, and set the * communication mode as well. @@ -219,7 +227,7 @@ * If MODE_SPI, this is the cs pin of the mag (CS_M) */ LSM9DS1(PinName sda, PinName scl, uint8_t xgAddr = LSM9DS1_AG_I2C_ADDR(1), uint8_t mAddr = LSM9DS1_M_I2C_ADDR(1)); - + /** begin() -- Initialize the gyro, accelerometer, and magnetometer. * This will set up the scale and output rate of each sensor. It'll also * "turn on" every sensor and every axis of every sensor. @@ -234,59 +242,59 @@ * bytes of the output are the WHO_AM_I reading of the accel/gyro. The * least significant two bytes are the WHO_AM_I reading of the mag. * All parameters have a defaulted value, so you can call just "begin()". - * Default values are FSR's of: +/- 245DPS, 4g, 2Gs; ODRs of 119 Hz for + * Default values are FSR's of: +/- 245DPS, 4g, 2Gs; ODRs of 119 Hz for * gyro, 119 Hz for accelerometer, 80 Hz for magnetometer. * Use the return value of this function to verify communication. */ - uint16_t begin(gyro_scale gScl = G_SCALE_500DPS, - accel_scale aScl = A_SCALE_2G, mag_scale mScl = M_SCALE_4GS, - gyro_odr gODR = G_ODR_952_BW_100, accel_odr aODR = A_ODR_119, + bool begin(gyro_scale gScl = G_SCALE_2000DPS, + accel_scale aScl = A_SCALE_8G, mag_scale mScl = M_SCALE_4GS, + gyro_odr gODR = G_ODR_119_BW_31, accel_odr aODR = A_ODR_119, mag_odr mODR = M_ODR_80); - + /** readGyro() -- Read the gyroscope output registers. * This function will read all six gyroscope output registers. * The readings are stored in the class' gx_raw, gy_raw, and gz_raw variables. Read * those _after_ calling readGyro(). */ void readGyro(); - + /** readAccel() -- Read the accelerometer output registers. * This function will read all six accelerometer output registers. * The readings are stored in the class' ax_raw, ay_raw, and az_raw variables. Read * those _after_ calling readAccel(). */ void readAccel(); - + /** readMag() -- Read the magnetometer output registers. * This function will read all six magnetometer output registers. * The readings are stored in the class' mx_raw, my_raw, and mz_raw variables. Read * those _after_ calling readMag(). */ void readMag(); - + /** Read Interrupt **/ void readIntr(); - + /** readTemp() -- Read the temperature output register. * This function will read two temperature output registers. * The combined readings are stored in the class' temperature variables. Read * those _after_ calling readTemp(). */ void readTemp(); - + /** calibration() -- Calibrate Accel and Gyro sensor */ void calibration(); - + /** setGyroScale() -- Set the full-scale range of the gyroscope. - * This function can be called to set the scale of the gyroscope to + * This function can be called to set the scale of the gyroscope to * 245, 500, or 2000 degrees per second. * Input: * - gScl = The desired gyroscope scale. Must be one of three possible * values from the gyro_scale enum. */ void setGyroScale(gyro_scale gScl); - + /** setAccelScale() -- Set the full-scale range of the accelerometer. * This function can be called to set the scale of the accelerometer to * 2, 4, 8, or 16 g's. @@ -295,7 +303,7 @@ * values from the accel_scale enum. */ void setAccelScale(accel_scale aScl); - + /** setMagScale() -- Set the full-scale range of the magnetometer. * This function can be called to set the scale of the magnetometer to * 4, 8, 12, or 16 Gs. @@ -304,29 +312,29 @@ * values from the mag_scale enum. */ void setMagScale(mag_scale mScl); - + /** setGyroODR() -- Set the output data rate and bandwidth of the gyroscope * Input: * - gRate = The desired output rate and cutoff frequency of the gyro. * Must be a value from the gyro_odr enum (check above). */ void setGyroODR(gyro_odr gRate); - + /** setAccelODR() -- Set the output data rate of the accelerometer * Input: * - aRate = The desired output rate of the accel. * Must be a value from the accel_odr enum (check above). */ void setAccelODR(accel_odr aRate); - + /** setMagODR() -- Set the output data rate of the magnetometer * Input: * - mRate = The desired output rate of the mag. * Must be a value from the mag_odr enum (check above). */ void setMagODR(mag_odr mRate); - - + + /** enableFIFO() -- Turn on FIFO state (CTRL_REG9) * Input: * - enable = true - turn on FIFO @@ -342,58 +350,58 @@ */ void setXgFIFO(uint8_t fifoMode, uint8_t fifoThs); -private: +private: /** xgAddress and mAddress store the I2C address * for each sensor. */ uint8_t xgAddress, mAddress; - + // I2C bus I2C i2c; - /** gScale, aScale, and mScale store the current scale range for each + /** gScale, aScale, and mScale store the current scale range for each * sensor. Should be updated whenever that value changes. */ gyro_scale gScale; accel_scale aScale; mag_scale mScale; - - /** gRes, aRes, and mRes store the current resolution for each sensor. + + /** gRes, aRes, and mRes store the current resolution for each sensor. * Units of these values would be DPS (or g's or Gs's) per ADC tick. * This value is calculated as (sensor scale) / (2^15). */ float gRes, aRes, mRes; - + /** initGyro() -- Sets up the gyroscope to begin reading. * This function steps through all three gyroscope control registers. */ void initGyro(); - + /** initAccel() -- Sets up the accelerometer to begin reading. * This function steps through all accelerometer related control registers. */ void initAccel(); - + /** Initialize Interrupts **/ void initIntr(); - + /** initMag() -- Sets up the magnetometer to begin reading. * This function steps through all magnetometer-related control registers. */ void initMag(); - + /** calcgRes() -- Calculate the resolution of the gyroscope. * This function will set the value of the gRes variable. gScale must * be set prior to calling this function. */ void calcgRes(); - + /** calcmRes() -- Calculate the resolution of the magnetometer. * This function will set the value of the mRes variable. mScale must * be set prior to calling this function. */ void calcmRes(); - + /** calcaRes() -- Calculate the resolution of the accelerometer. * This function will set the value of the aRes variable. aScale must * be set prior to calling this function.