• LSM9DS1 4 Dec 2016
    Some progress on the calibration functions has been made. There are some problems that need to be addressed.
    The first item is the word calibration itself. The functions only address part of a full calibration, the zero point. The scale is not calibrated, but simply uses the advertised values from the data sheet.
    The second item is the method used to determine the zero point. For this chip there are two different calibration functions. One calibrates the accelerometer/gyro and the other calibrates the magnetometer. Addressing the accelerometer/gyro function first.
    The accelerometer/gyro calibration function for the LSM9DS1 chip makes use of the FIFO hardware. The function sets up the FIFO to read 32 samples each from the accelerometer and gyro, then it averages these values to find the zero offset. The accelerometer makes the assumption that the x-y plane is parallel to a level surface, and that the z-axis is on a plumb line. It doesn’t actually find a zero offset for the z-axis.
    This can be corrected by doing the x-y calibration, reposition the chip so that either the x-z or y-z plane is level and finding the zero for the z-axis.
    Of note is Figure 1 in the LSM9DS1 datasheet. Notice the dot on the chip is positioned differently for the magnetometer illustration. Also as drawn the axis directions are a left-hand coordinate system.
    http://www.st.com/content/ccc/resource/t­echnical/document/datasheet/1e/3f/2a/d6/­25/eb/48/46/DM00103319.pdf/files/DM00103­319.pdf/jcr:content/translations/en.DM00­103319.pdf
    A bug was found in the previous code that froze the gyro readings. The gyro sample rate has been added to fix the bug.

    this.gyro_scale = 245;
    this.gyro_sampleRate = 6;
    this.gyro_bandwidth = 0;
    

    Once calibrated using calls to the read accelerometer and read gyro functions with the FIFO produce an unreasonable variation in the at rest gyro readings. This variation is greatly reduced by using the FIFO in continuous mode, even limiting the FIFO to 2 samples. My hypothesis is that without the FIFO the values returned contain incomplete samples. To use the FIFO in continuous mode:

    // fifoMode
    // FIFO_OFF = 0, FIFO_THS = 1,	FIFO_CONT_TRIGGER = 3, 
    //FIFO_OFF_TRIGGER = 4, FIFO_CONT = 5
    W.enableFIFO(true);
     W.setFIFO(5,10); // ( fifoMode ,length<32)
    

    The magnetometer calibration function acquires 128 readings and for each axis determines the maximum and minimum reading, and then averages these two values to produce the zero offset value for each axis. These values are stored on the chip using a call to the magOffset function.
    I’m not sure if this method is of any value. I can imagine placing the chip inside a pair of A.C Helmholtz coils as one method. I finally performed a zero offset calibration manually.
    I attached the chip to a cube. I placed the cube on a level non-magnetic surface (wood) with a wooden fence (think table saw) oriented North South. I zeroed the chip offsets using a call to the magOffset function. Then I collected six sets of data.

    1. X-axis level and pointing North
    2. X-axis level and pointing South
    3. Y-axis level and pointing North
    4. Y-axis level and pointing South
    5. Z-axis level and pointing North
    6. Z-axis level and pointing South
      Then I used a spreadsheet to find the maximum and minimum values in pairs of data sets and averaged them. For the X offset use sets 1 and 2, for Y sets 2 and 3 and finally for Z sets 5 and 6.
      These offsets are then sent to the chip after initialization using the magOffset function.
      If the chip is powered down the offset values are lost (volatile).
      This procedure finally produced reasonable compass heading values when the x-y plane of the chip is level. Yet to address is the heading in 0 to 360 degrees instead of -180 to 180 degrees in the wrong direction. Also I hope to add the necessary rotation matrix math that gives the compass heading in any chip orientation.

    Attached is the code as of today. I hope to incorporate changes that will reflect the issues discussed.

About