Getting/Calibrating Data From lsm303dlhc Mag + Accel Combo

Hello! I was wondering how I would go about calibrating an lsm303dlhc sensor. In understand the concept of how calibration works, you just reset the limits to the highest and lowest value given, but i've hit a bit of a snag. To get the data in m/s^2 I used the library AdafruitLSM303DLHC (well, I just played around with the "accel" example) and all the examples ive seen of calibration, calibrate before converting into m/s^2, so could I calibrate the data coming out of the library in m/s^2 units, and how would I do that, or do I need to use the "raw" data, calibrate, and convert manually to m/s^2? (also where do I find the info for doing this on the chip's datasheet) This thing is hopefully going up in my schools HAB project so ill be logging this, and data from a geiger counter, pressure sensor, and a luminosity sensor.

The "low and high limit" method of calibrating an accelerometer doesn't work very well. My favorite method involves collecting a bunch of accelerometer or magnetometer data points with the device in different orientations, then using a program on a PC to convert the resulting 3-D ellipsoid into a sphere. Here is a great intro to the technique: Sailboat Instruments: Improved magnetometer calibration (Part 1)

The blog describes magnetometer calibration but the same procedure works just as well for the accelerometer, provided that the device is held still while each data point is recorded. Once calibrated, 1 "g" is 9.8 m/s^2 so the conversion factor for the accelerometer is trivial to calculate.

I do this too. I do the calibration using the raw "counts" from the device. Turn the sensor board around and around and collect all the data. The plot the data as a bunch of vectors, the points form a rough sphere. Then calculate the offset and scale factors for each axis to turn the rough sphere into the closest approximation of a real sphere. I do this on the PC with a fancy spreadsheet.

When you are turning the sensor board around, you don't want to jerk it abruptly. You want to be measuring the gravity reading in all the different directions, and not the acceleration of your hand.

Have you found this device to be convenient to work with ? I am thinking of buying some of them.

I use Pololu's breakout board with this combo and it is very easy to use.

Oh wow thanks! That sailboat instruments program worked really well!

jremington:
Sailboat Instruments: Improved magnetometer calibration (Part 1)

Im getting closer to -9.8 in the Z dimension now, but the X and Y are always a little (+- 0.1) off of zero, is this just due to the quality of the calibration? ie: If I shook the accelerometer a little bit while calibrating or didn't quite get a full sphere of test values.

michinyon:
Have you found this device to be convenient to work with ? I am thinking of buying some of them.

Yeah I like this chip quite a bit, all adafruit things i've found to be pretty nice to work with. Lots of libraries and such. The adafruit Geiger counter I'm using was a bit of a dickens to get data off but adafruit had lots of documentation and support for this kind of thing.

One last question, since this is going into a high altitude balloon, its going to be spinning a bit uncontrollably, so a vectorless overall magnetic field strength is probably a bit more interesting than any heading values (Although I might log both), how could I calculate that?

There is a certain amount of noise in both the magnetometer and accelerometer, so if possible you should be averaging a few readings for each axis. However, your success will depend on the model not moving much in the meantime!

Once calibrated, the overall magnetic field strength is just sqrt(magx^2 + magy^2 + magz^2).

Sounds like a fun project!

"but the X and Y are always a little (+- 0.1) off of zero,"

You basically have two choices. You can adjust the raw readings ( scale and offset ), so that the adjusted X and Y are actually zero , when the device is actually motionless on a level surface, or you can adjust the raw readings to give the closest approximation to a sphere or circle over the full range of positions, or motion.

It depends on what sort of movement you expect the device to have.

If the units are such that the accelerometer values are varying by +/- 0.1 m/s^2, then you are getting 1% accuracy. That is actually pretty damned good, and you can't hope to do much better with an inexpensive accelerometer.

jremington:
If the units are such that the accelerometer values are varying by +/- 0.1 m/s^2, then you are getting 1% accuracy.

Not too sure if thats how that math comes out... But your right that it really isn't too bad of an inaccuracy

michinyon:
"but the X and Y are always a little (+- 0.1) off of zero,"

You can adjust the raw readings ( scale and offset ), so that the adjusted X and Y are actually zero , when the device is actually motionless on a level surface

Its more of a jitter between random values around zero, so offsetting it would only make it jitter around the offset (I think thats how it would work...) But to be honest, I'm really not too bothered about it since there will be no time at which the balloon is at zero acceleration in all dimensions (It swings and spins a lot). The most interesting parts will be seeing Z acceleration change as it goes up, the acceleration at cutdown, the Z acceleration as the parachute slowly deploys and enters thicker atmosphere, and the acceleration when it hits the ground. But thank you for all of your replies and help! I'll post my results from the flight if we can retrieve the payload, and also probably a tutorial/conclusion of how I set up the arduino to log the data from (hopefully) 5 different sensors, including a geiger counter (I'm really proud of this one :D)

I'll bet you also see a fluctuation (standard deviation) of about 0.1 m/s^2 on the axis measuring 1 g, or 9.8 m/s^2. That is where the 1% accuracy comes from. However, if you consider the full scale setting to be 2 g, then the fluctuation is about 0.5%.

jremington:
If the units are such that the accelerometer values are varying by +/- 0.1 m/s^2, then you are getting 1% accuracy. That is actually pretty damned good, and you can't hope to do much better with an inexpensive accelerometer.

Thats actually a spurious comparison. It's only "1% accuracy" with respect to gravity. Which is fine, if that is all your are interested in. An error of 0.1 m/s/s in the acceleration of, say, an automobile, is actually quite a big error.

Thats actually a spurious comparison. It's only "1% accuracy" with respect to gravity. Which is fine, if that is all your are interested in. An error of 0.1 m/s/s in the acceleration of, say, an automobile, is actually quite a big error.

I disagree, although I should have used the term precision, which is strictly correct. The observed precision of the measurement, including the noise, is 0.5% of full scale. If I wanted to measure 0.1 m/s^2 acceleration with any precision at all, I wouldn't use a sensor with 20 m/s^2 full scale reading.

:)good