IMU LSM9DS1 Library
Dependents: IMU 4180Lab2Part1 segway-selfBalancingRobot test
Diff: LSM9DS1.h
- Revision:
- 1:87d535bf8c53
- Parent:
- 0:e8167f37725c
diff -r e8167f37725c -r 87d535bf8c53 LSM9DS1.h --- a/LSM9DS1.h Mon Oct 26 14:55:43 2015 +0000 +++ b/LSM9DS1.h Mon Oct 26 16:14:04 2015 +0000 @@ -64,150 +64,172 @@ // LSM9DS1 -- LSM9DS1 class constructor // The constructor will set up a handful of private variables, and set the // communication mode as well. - // Input: - // - interface = Either IMU_MODE_SPI or IMU_MODE_I2C, whichever you're using - // to talk to the IC. - // - xgAddr = If IMU_MODE_I2C, this is the I2C address of the accel/gyroscope. - // If IMU_MODE_SPI, this is the chip select pin of the gyro (CS_AG) - // - mAddr = If IMU_MODE_I2C, this is the I2C address of the magnetometer. - // If IMU_MODE_SPI, this is the cs pin of the magnetometer (CS_M) + /**Input: + * - interface = Either IMU_MODE_SPI or IMU_MODE_I2C, whichever you're using + * to talk to the IC. + * - xgAddr = If IMU_MODE_I2C, this is the I2C address of the accel/gyroscope. + * If IMU_MODE_SPI, this is the chip select pin of the gyro (CS_AG) + * - mAddr = If IMU_MODE_I2C, this is the I2C address of the magnetometer. + * If IMU_MODE_SPI, this is the cs pin of the magnetometer (CS_M) + + */ LSM9DS1(PinName sda, PinName scl, uint8_t xgAddr, uint8_t mAddr); - LSM9DS1(interface_mode interface, uint8_t xgAddr, uint8_t mAddr); - LSM9DS1(); - - // begin() -- Initialize the gyro, accelerometer, and magnetometer. - // This will set up the scale and output rate of each sensor. The values set - // in the IMUSettings struct will take effect after calling this function. + //LSM9DS1(interface_mode interface, uint8_t xgAddr, uint8_t mAddr); + //LSM9DS1(); + + + /** begin() -- Initialize the gyro, accelerometer, and magnetometer. + *This will set up the scale and output rate of each sensor. The values set + * in the IMUSettings struct will take effect after calling this function. + */ uint16_t begin(); void calibrate(bool autoCalc = true); void calibrateMag(bool loadIn = true); void magOffset(uint8_t axis, int16_t offset); - // accelAvailable() -- Polls the accelerometer status register to check - // if new data is available. - // Output: 1 - New data available - // 0 - No new data available + /** accelAvailable() -- Polls the accelerometer status register to check + * if new data is available. + * Output: 1 - New data available + * 0 - No new data available + */ uint8_t accelAvailable(); - // gyroAvailable() -- Polls the gyroscope status register to check - // if new data is available. - // Output: 1 - New data available - // 0 - No new data available + /** gyroAvailable() -- Polls the gyroscope status register to check + * if new data is available. + * Output: 1 - New data available + * 0 - No new data available + */ uint8_t gyroAvailable(); - // gyroAvailable() -- Polls the temperature status register to check - // if new data is available. - // Output: 1 - New data available - // 0 - No new data available + /** gyroAvailable() -- Polls the temperature status register to check + * if new data is available. + * Output: 1 - New data available + * 0 - No new data available + */ uint8_t tempAvailable(); - // magAvailable() -- Polls the accelerometer status register to check - // if new data is available. - // Input: - // - axis can be either X_AXIS, Y_AXIS, Z_AXIS, to check for new data - // on one specific axis. Or ALL_AXIS (default) to check for new data - // on all axes. - // Output: 1 - New data available - // 0 - No new data available + /** magAvailable() -- Polls the accelerometer status register to check + * if new data is available. + * Input: + * - axis can be either X_AXIS, Y_AXIS, Z_AXIS, to check for new data + * on one specific axis. Or ALL_AXIS (default) to check for new data + * on all axes. + * Output: 1 - New data available + * 0 - No new data available + */ uint8_t magAvailable(lsm9ds1_axis axis = ALL_AXIS); - // readGyro() -- Read the gyroscope output registers. - // This function will read all six gyroscope output registers. - // The readings are stored in the class' gx, gy, and gz variables. Read - // those _after_ calling readGyro(). + /** readGyro() -- Read the gyroscope output registers. + * This function will read all six gyroscope output registers. + * The readings are stored in the class' gx, gy, and gz variables. Read + * those _after_ calling readGyro(). + */ void readGyro(); - // int16_t readGyro(axis) -- Read a specific axis of the gyroscope. - // [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS. - // Input: - // - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS. - // Output: - // A 16-bit signed integer with sensor data on requested axis. + /** int16_t readGyro(axis) -- Read a specific axis of the gyroscope. + * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS. + * Input: + * - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS. + * Output: + * A 16-bit signed integer with sensor data on requested axis. + */ int16_t readGyro(lsm9ds1_axis axis); - // readAccel() -- Read the accelerometer output registers. - // This function will read all six accelerometer output registers. - // The readings are stored in the class' ax, ay, and az variables. Read - // those _after_ calling readAccel(). + /** readAccel() -- Read the accelerometer output registers. + * This function will read all six accelerometer output registers. + * The readings are stored in the class' ax, ay, and az variables. Read + * those _after_ calling readAccel(). + */ void readAccel(); - // int16_t readAccel(axis) -- Read a specific axis of the accelerometer. - // [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS. - // Input: - // - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS. - // Output: - // A 16-bit signed integer with sensor data on requested axis. + /** int16_t readAccel(axis) -- Read a specific axis of the accelerometer. + * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS. + * Input: + * - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS. + * Output: + * A 16-bit signed integer with sensor data on requested axis. + */ int16_t readAccel(lsm9ds1_axis axis); - // readMag() -- Read the magnetometer output registers. - // This function will read all six magnetometer output registers. - // The readings are stored in the class' mx, my, and mz variables. Read - // those _after_ calling readMag(). + /** readMag() -- Read the magnetometer output registers. + * This function will read all six magnetometer output registers. + * The readings are stored in the class' mx, my, and mz variables. Read + * those _after_ calling readMag(). + */ void readMag(); - // int16_t readMag(axis) -- Read a specific axis of the magnetometer. - // [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS. - // Input: - // - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS. - // Output: - // A 16-bit signed integer with sensor data on requested axis. + /** int16_t readMag(axis) -- Read a specific axis of the magnetometer. + * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS. + * Input: + * - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS. + * Output: + * A 16-bit signed integer with sensor data on requested axis. + */ int16_t readMag(lsm9ds1_axis axis); - // 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(). + /** 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(); - // calcGyro() -- Convert from RAW signed 16-bit value to degrees per second - // This function reads in a signed 16-bit value and returns the scaled - // DPS. This function relies on gScale and gRes being correct. - // Input: - // - gyro = A signed 16-bit raw reading from the gyroscope. + /** calcGyro() -- Convert from RAW signed 16-bit value to degrees per second + * This function reads in a signed 16-bit value and returns the scaled + * DPS. This function relies on gScale and gRes being correct. + * Input: + * - gyro = A signed 16-bit raw reading from the gyroscope. + */ float calcGyro(int16_t gyro); - // calcAccel() -- Convert from RAW signed 16-bit value to gravity (g's). - // This function reads in a signed 16-bit value and returns the scaled - // g's. This function relies on aScale and aRes being correct. - // Input: - // - accel = A signed 16-bit raw reading from the accelerometer. + /** calcAccel() -- Convert from RAW signed 16-bit value to gravity (g's). + * This function reads in a signed 16-bit value and returns the scaled + * g's. This function relies on aScale and aRes being correct. + * Input: + * - accel = A signed 16-bit raw reading from the accelerometer. + */ float calcAccel(int16_t accel); - // calcMag() -- Convert from RAW signed 16-bit value to Gauss (Gs) - // This function reads in a signed 16-bit value and returns the scaled - // Gs. This function relies on mScale and mRes being correct. - // Input: - // - mag = A signed 16-bit raw reading from the magnetometer. + /** calcMag() -- Convert from RAW signed 16-bit value to Gauss (Gs) + * This function reads in a signed 16-bit value and returns the scaled + * Gs. This function relies on mScale and mRes being correct. + * Input: + * - mag = A signed 16-bit raw reading from the magnetometer. + */ float calcMag(int16_t mag); - // setGyroScale() -- Set the full-scale range of the gyroscope. - // This function can be called to set the scale of the gyroscope to - // 245, 500, or 200 degrees per second. - // Input: - // - gScl = The desired gyroscope scale. Must be one of three possible - // values from the gyro_scale. + /** setGyroScale() -- Set the full-scale range of the gyroscope. + * This function can be called to set the scale of the gyroscope to + * 245, 500, or 200 degrees per second. + * Input: + * - gScl = The desired gyroscope scale. Must be one of three possible + * values from the gyro_scale. + */ void setGyroScale(uint16_t 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, 6, 8, or 16 g's. - // Input: - // - aScl = The desired accelerometer scale. Must be one of five possible - // values from the accel_scale. + /** setAccelScale() -- Set the full-scale range of the accelerometer. + * This function can be called to set the scale of the accelerometer to + * 2, 4, 6, 8, or 16 g's. + * Input: + * - aScl = The desired accelerometer scale. Must be one of five possible + * values from the accel_scale. + */ void setAccelScale(uint8_t aScl); - // setMagScale() -- Set the full-scale range of the magnetometer. - // This function can be called to set the scale of the magnetometer to - // 2, 4, 8, or 12 Gs. - // Input: - // - mScl = The desired magnetometer scale. Must be one of four possible - // values from the mag_scale. + /** setMagScale() -- Set the full-scale range of the magnetometer. + * This function can be called to set the scale of the magnetometer to + * 2, 4, 8, or 12 Gs. + * Input: + * - mScl = The desired magnetometer scale. Must be one of four possible + * values from the mag_scale. + */ void setMagScale(uint8_t mScl); - // setGyroODR() -- Set the output data rate and bandwidth of the gyroscope - // Input: - // - gRate = The desired output rate and cutoff frequency of the gyro. + /** setGyroODR() -- Set the output data rate and bandwidth of the gyroscope + * Input: + * - gRate = The desired output rate and cutoff frequency of the gyro. + */ void setGyroODR(uint8_t gRate); // setAccelODR() -- Set the output data rate of the accelerometer @@ -284,52 +306,56 @@ void configInt(interrupt_select interupt, uint8_t generator, h_lactive activeLow = INT_ACTIVE_LOW, pp_od pushPull = INT_PUSH_PULL); - // configMagInt() -- Configure Magnetometer Interrupt Generator - // Input: - // - generator = Interrupt axis/high-low events - // Any OR'd combination of ZIEN, YIEN, XIEN - // - activeLow = Interrupt active configuration - // Can be either INT_ACTIVE_HIGH or INT_ACTIVE_LOW - // - latch: latch gyroscope interrupt request. + /** configMagInt() -- Configure Magnetometer Interrupt Generator + * Input: + * - generator = Interrupt axis/high-low events + * Any OR'd combination of ZIEN, YIEN, XIEN + * - activeLow = Interrupt active configuration + * Can be either INT_ACTIVE_HIGH or INT_ACTIVE_LOW + */ - latch: latch gyroscope interrupt request. void configMagInt(uint8_t generator, h_lactive activeLow, bool latch = true); - // configMagThs() -- Configure the threshold of a gyroscope axis - // Input: - // - threshold = Interrupt threshold. Possible values: 0-0x7FF. - // Value is equivalent to raw magnetometer value. + /** configMagThs() -- Configure the threshold of a gyroscope axis + * Input: + * - threshold = Interrupt threshold. Possible values: 0-0x7FF. + * Value is equivalent to raw magnetometer value. + */ void configMagThs(uint16_t threshold); - // getGyroIntSrc() -- Get contents of Gyroscope interrupt source register + //! getGyroIntSrc() -- Get contents of Gyroscope interrupt source register uint8_t getGyroIntSrc(); - // getGyroIntSrc() -- Get contents of accelerometer interrupt source register + //! getGyroIntSrc() -- Get contents of accelerometer interrupt source register uint8_t getAccelIntSrc(); - // getGyroIntSrc() -- Get contents of magnetometer interrupt source register + //! getGyroIntSrc() -- Get contents of magnetometer interrupt source register uint8_t getMagIntSrc(); - // getGyroIntSrc() -- Get status of inactivity interrupt + //! getGyroIntSrc() -- Get status of inactivity interrupt uint8_t getInactivity(); - // sleepGyro() -- Sleep or wake the gyroscope - // Input: - // - enable: True = sleep gyro. False = wake gyro. + /** sleepGyro() -- Sleep or wake the gyroscope + * Input: + * - enable: True = sleep gyro. False = wake gyro. + */ void sleepGyro(bool enable = true); - // enableFIFO() - Enable or disable the FIFO - // Input: - // - enable: true = enable, false = disable. + /** enableFIFO() - Enable or disable the FIFO + * Input: + * - enable: true = enable, false = disable. + */ void enableFIFO(bool enable = true); - // setFIFO() - Configure FIFO mode and Threshold - // Input: - // - fifoMode: Set FIFO mode to off, FIFO (stop when full), continuous, bypass - // Possible inputs: FIFO_OFF, FIFO_THS, FIFO_CONT_TRIGGER, FIFO_OFF_TRIGGER, FIFO_CONT - // - fifoThs: FIFO threshold level setting - // Any value from 0-0x1F is acceptable. + /** setFIFO() - Configure FIFO mode and Threshold + * Input: + * - fifoMode: Set FIFO mode to off, FIFO (stop when full), continuous, bypass + * Possible inputs: FIFO_OFF, FIFO_THS, FIFO_CONT_TRIGGER, FIFO_OFF_TRIGGER, FIFO_CONT + * - fifoThs: FIFO threshold level setting + * Any value from 0-0x1F is acceptable. + */ void setFIFO(fifoMode_type fifoMode, uint8_t fifoThs); - // getFIFOSamples() - Get number of FIFO samples + //! getFIFOSamples() - Get number of FIFO samples uint8_t getFIFOSamples();