Lsm303 accelerometer data

Hi everyone…
I have a quick question regarding the MinIMU-9 v2 Gyro, accelerometer and gyro readings. I am able to get data but does not seem to be very stable. When the board is stationary with x,y on horizontal plane my data for are as shown below.
My CTRL_REG4_A is 0XB0 +/- 2g. If i increase it, the fluctuations are more.

x y z
-4 0 -88
0 0 -84
0 0 -88
0 0 -84
0 -4 -88
-4 0 -90
0 0 -88
4 0 -88
These was sampled in about 1 second.
with my board orientation i should be getting 0,0 on the X and Y axis. My concern is when i see the -4 fluctuation and such it is not going to work very well with tilt compensation that i plan on doing since i will be getting two different readings of the accelerometer for the same orientation. For the majority of the data its at 0 but with fluctuations.
This behavior also happens to my gyroscope readings except that its worse.
X ranges from -28 to -20
Y ranges from -7 to -12 and
Z from -299 to -290 . when the board is held like described above.
Is this normal behavior or do i need to do something to correct for this?
Thank You.

This is normal noise behavior. You need to make several readings of each sensor and average them. Accelerometers and magnetometers also, in general, need to be properly calibrated so that you can determine the transformations necessary to remove scaling and offset errors.

I did a calibration for the magnometer and it seems pretty okay. I am not sure what kind of calibration you are suggesting for the accelerometer. As for the gyro I have done some offsetting and my gyro reading has become a bit stable. Example of what i did on the Z data for gyro
Z_g=((float)(Z_g-75)*0.07)+25;
Z_g=raw reading.

The 0.07 is from datasheet (70mdps/digit) and the 75 is from digital zero rate level, since I set my FS to 11. The 25 is the offset i got after doing the above calculations.With this my Z axis gyro is ranges from 0 and -1 when stationary, and when i rotate it i see some readings.
Is this the proper way to have gone about this ?
When you say i need to calibrate the accelerometer and gyro, do you mean just taking the average values of the readings or what is the best way to calibrate the gyro ? Thank you ?

I didn’t say anything about calibrating the gyro. Here is a link to some pages describing state of the art procedures for calibrating magnetometers. The procedure also works well for accelerometers providing that the accelerometer is held still for each measurement.

sailboatinstruments.blogspot.com … ation.html

Hello.

I checked the LSM303DLHC datasheet and it looks like a value of 0xB0 would be 0b10110000 which means FS0=1 and FS1=1, which means the full-scale is 16G. You should be able to get a better resolution on your measurement if you set the full scale to 8G. Please try setting the CTRL_REG4_A register to 0x20, like we do in our example MinIMU-9 v2 code.

You could also try setting the full scale to 2G, which might be event better. In that case, CTRL_REG4_A should be 0x00.

–David

Thanks DavidEGrayson

My mistake i meant to say +/- 16g.

I have it set at +/-2g. For some reason there seem to be a lot of noise though. Another thing is, with this setting and the board Z axis vertical my Z output is about 1050. I understand that i have to multiply by mg/LSB in order to get my values to g, with that 1050* 0.001 =1.05g. If anything i would expect to get a reading less than or equal to 1 g when i lay my board flat as described with no motion absolutely. If my Z output max 1000 that would make sense.
Another silly question, what exactly does +/-2g mean? is that the tolerance of the device ? i.e. it could be off up to + or - 2 g ? coz of so, isnt that kind of a big tolerance…+/-19.6 m/s^2.

Also i have some concerns about the gyroscope, after doing my offsets and all so i could have 0 readings in all axis when the device is stationary, i observed inconsistent output when i revolve my device in opposite directions. Here is a better explanation.
My board orientation is such that my X-Y plane is horizontal and my Z axis vertical. I have my FS set to +/-2000 dps. My readings are in a vector GR={X_g,Y_g,Z_g}
Then i multiply each vector component by =0.07 to get my values in degrees/sec. After doing this and the board is stationary my GR = {-5,0,-20}, so i decided to add 5 to X and 20 to Z so all my readings could be zero.
Z_g =(Z_g0.07)+20;
Then wrote a simple program to integrate my angular velocity on the Z axis with respect to time THEN turn my robot clockwise WHILE sums of angles are <=90, then turn it anti-clockwise WHILE the sum >=0.
ANGLE = ANGLE + Z_g_new
(t2-t1); my initial ANGLE IS 0 and my clock is very precise. (t2-t1) ~=0.01

on the clockwise turns, My robot did very well. Stopped at exactly 90 degree turn approximately BUT the counter clockwise it had to turn about 130 degrees before it stopped. I tried tilting the device with my hand while monitoring the output of the ANGLES on terminal window and i noticed that i have to turn my board about 120 degrees counter-clock before i get a reading of -90, starting from zero. I did this carefully and noticed that my counter clockwise growth rate is less that my clockwise…The only logical explanation for this that i could have was the offset value above (20)…Z_g =(Z_g*0.07)+20; But without the offset my angles will build up without motion. Would someone please help with this ?
Thank you

How much noise is there in terms of g? Could you post some of your raw readings?

It sounds like your accelerometer is off from what you would expect by 5%. That sounds reasonable for this type of accelerometer. I see that on Table 3 of the LSM303DLHC it lists the “Linear acceleration typical Zero-g level offset” as plus or minus 0.06 g (60 mg), so that offset alone could explain the error of 0.05 you are getting.

After you multiply the raw readings by 0.07, are you storing the result in an integer? That would result in a lot of rounding errors, so I wouldn’t recommend it. I think that could actually explain the problems you are seeing when you try to integrate the gyro readings. Instead, I would recommend that the conversion to degrees should happen as late as possible.

Twenty degrees per second seems like a pretty big gyro offset. I would recommend double-checking all your calculations to make sure that is right. The raw gyro readings from my MinIMU-9 v2 while the device was stationary and full scale was set to +/- 2000 dps were all within about -60 to 60.

–David

I have attached a data file for the accele at +/- 2g and +/-8g . I have also included the RAW and ADJUSTED gyro readings at +/-2000dps.

Plus one thing i dont understad is that the gyro Z axis seems to have a huge value compared to the x and y.

am to understand that individual axis were fluctuating by that much while stationary ? if so wont that build up huge error ? Am i missing something?
data.txt (3.66 KB)

That does not look like a lot of noise to me.

Thanks for sending your raw gyro readings at 2000 dps full scale. It looks to me like your Z axis does indeed have a -290 (-20.3 dps) offset, but you should still be able to work with it because it has a standard deviation of only 5.56. I checked the L3GD20 datasheet to see if that offset is normal, and apparently it is. See Table 3, DVoff.

No. The raw gyro readings from my MinIMU-9 v2 that I was talking about are from this page, 2000 dps full scale:

-50      14       9
-49      20      18
-51      15       8
-50      21      17
-51      22      11
-56      20      14

–David

by a lot of noise i meant more than the other settings of over +/-2g, i am less familiar with accelerometers so i i was not expecting such kind of noise.

I tried adding the offset so the reading is 0 when stationary, but when i do the integration of dps with respect to time for a complete 90 degree clockwise, i get different result from when i do it counter-clockwise.
E.g My integral sum on the clockwise rotation will be right around 90 degrees but the anticlockwise is about -70 to-80 degrees. I tried rotating my gyro slowly in both to see if i can pick up readings from 0 to -19 but they do not exist, so i thought its not really an offset but a skip, meaning on clockwise turns i get values from 0 to n and counter clockwise from -20 to -n. With that i set my program to if(gryo<-20){gyro +=20;} so it can only adjust the counter clock turns and not the clockwise turns but i did not have much luck with that method either.

how will i be able to do that? thank you

When I said “you should still be able to work with it” I just meant that you can get good numbers by subtracting an offset value, as you are already doing.

If you gave me more details about how you are doing the gyro integration experiment, including complete code, I might be able to help with that. I think you can probably get better results than what you are seeing now.

–David