IMU LSM9DS1 Library

Dependencies:   PinDetect mbed

Dependents:   IMU 4180Lab2Part1 segway-selfBalancingRobot test

Files at this revision

API Documentation at this revision

Comitter:
jmar7
Date:
Mon Oct 26 16:14:04 2015 +0000
Parent:
0:e8167f37725c
Commit message:
hello world for LSM9DS1

Changed in this revision

LSM9DS1.cpp Show annotated file Show diff for this revision Revisions of this file
LSM9DS1.h Show annotated file Show diff for this revision Revisions of this file
--- a/LSM9DS1.cpp	Mon Oct 26 14:55:43 2015 +0000
+++ b/LSM9DS1.cpp	Mon Oct 26 16:14:04 2015 +0000
@@ -43,7 +43,7 @@
 {
     init(IMU_MODE_I2C, xgAddr, mAddr); // dont know about 0xD6 or 0x3B
 }
-/* cw
+/*
 LSM9DS1::LSM9DS1()
 {
     init(IMU_MODE_I2C, LSM9DS1_AG_ADDR(1), LSM9DS1_M_ADDR(1));
@@ -1044,7 +1044,7 @@
 
 void LSM9DS1::initSPI()
 {
-    /* cw
+    /* 
     pinMode(_xgAddress, OUTPUT);
     digitalWrite(_xgAddress, HIGH);
     pinMode(_mAddress, OUTPUT);
@@ -1063,7 +1063,7 @@
 
 void LSM9DS1::SPIwriteByte(uint8_t csPin, uint8_t subAddress, uint8_t data)
 {
-    /*cw
+    /*
     digitalWrite(csPin, LOW); // Initiate communication
     
     // If write, bit 0 (MSB) should be 0
@@ -1094,7 +1094,7 @@
     if ((csPin == _mAddress) && count > 1)
         rAddress |= 0x40;
     
-    /* cw
+    /* 
     digitalWrite(csPin, LOW); // Initiate communication
     SPI.transfer(rAddress);
     for (int i=0; i<count; i++)
@@ -1107,7 +1107,7 @@
 
 void LSM9DS1::initI2C()
 {
-    /* cw
+    /* 
     Wire.begin();   // Initialize I2C library
     */
     
@@ -1117,7 +1117,7 @@
 // Wire.h read and write protocols
 void LSM9DS1::I2CwriteByte(uint8_t address, uint8_t subAddress, uint8_t data)
 {
-    /* cw
+    /* 
     Wire.beginTransmission(address);  // Initialize the Tx buffer
     Wire.write(subAddress);           // Put slave register address in Tx buffer
     Wire.write(data);                 // Put data in Tx buffer
@@ -1129,7 +1129,7 @@
 
 uint8_t LSM9DS1::I2CreadByte(uint8_t address, uint8_t subAddress)
 {
-    /* cw
+    /* 
     int timeout = LSM9DS1_COMMUNICATION_TIMEOUT;
     uint8_t data; // `data` will store the register data    
     
@@ -1160,7 +1160,7 @@
 
 uint8_t LSM9DS1::I2CreadBytes(uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count)
 {  
-    /* cw
+    /* 
     int timeout = LSM9DS1_COMMUNICATION_TIMEOUT;
     Wire.beginTransmission(address);   // Initialize the Tx buffer
     // Next send the register to be read. OR with 0x80 to indicate multi-read.
--- 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();