Nano 33, heading keeps on dropping while resting

I'm working on an update of the LSM9DS1 library to address the above issues. I guess this part of the forum would be the best place to post a beta?

What updates are you planning? It would be nice to be able to configure the gyro, accelerometer and magnometer as the adafruit LSM9DS1 library does.

What updates are you planning? It would be nice to be able to configure the gyro, accelerometer and magnometer as the adafruit LSM9DS1 library does.

In short
to set and get the sample rate frequency ,
to give it calibration zero offset and slope factors
to change the output unit
to change the internal full scale setting of the chip (IFS) giving it more accuracy at the expence of the range.

The project got a bit out of hand
What started as a few modified functions is now about 90% new code.

Writing the notes took a lot of time as well as modeling the chip error and deriving the best counter action.
Im still working on a few examples.
I'll start a new thread in this forum sensor section

Sounds good!

Please let me know when it is available.

femmeverbeek:
In short
to set and get the sample rate frequency ,
to give it calibration zero offset and slope factors
to change the output unit
to change the internal full scale setting of the chip (IFS) giving it more accuracy at the expence of the range.

The project got a bit out of hand
What started as a few modified functions is now about 90% new code.

Writing the notes took a lot of time as well as modeling the chip error and deriving the best counter action.
Im still working on a few examples.
I'll start a new thread in this forum sensor section

Can't wait to see more updates coming. Keep up the good work!

Thanks for the support in advance :slight_smile:

Thanks jremmington for your replies above. I was speaking carelessly when I said "rotate back", I did mean reflected by negating one of the axes to switch from right to left handed. Thanks again.

The LSM9DS1 beta is out

Hi, so I'm kind of struggling to get this madgwick filter to work. I changed the x and y axis on accelerometer and gyroscope, but how do I find the gyroscale? I think mine is at 245 dps, but the numbers I tried still give the yaw as ~180 and doesn't seem to change quick enough.

how do I find the gyroscale?

Read the sensor datasheet.

For the Madgwick and Mahony filters, the gyro output must be in radians per second.

Hi, so I'm kind of struggling to get this madgwick filter to work. I changed the x and y axis on accelerometer and gyroscope, but how do I find the gyroscale? I think mine is at 245 dps, but the numbers I tried still give the yaw as ~180 and doesn't seem to change quick enough.

If you are using my version of the LSM9DS1 library start your program with

IMU.gyroUnit = RADIANSPERSECOND;
IMU.setGyroODR(5); //Sample Rate Hz 0=off,1=10,2=50 3=119,4=238,5=476, 6:does not work 952Hz
IMU.setGyroFS(0); // (0= ±245 dps; 1= ±500 dps; 2= ±1000 dps; 3= ±2000 dps)

If you want to know the current setting of the scale IMU.getGyroFS();

ahh ok thanks for the quick reply!

Setting the unit changes the output of the read… procedure. You can’t do the conversion twice. If the Madgwick assumes the output to be in degrees, you must leave that setting as is.

The reason for drifting is very probably the lack of calibration. The gyro offset in my case was 3 deg/s. It does not sound like much, but it is a full circle misalignment in 2 min. I’m working on some DIY calibration program that explains what to do and produces the code lines that can be copy/pasted in a sketch, but I need a few more days for that.

The magnet reading is usually the slowest. The orginal was 20Hz. The version you are using probably 80 Hz.
I have a version ready that supports fastrate ODR @400Hz. Still must make the commit though.

I am not sure if the issue derekhui observed is a drift. I have had the same problem but not investigated further until now.

What happens is that if the board stands still there is no drift there is some minor fluctuations in the values of pitch, yaw and roll. However, if you turn the board to a new position, pitch, yaw and roll also start changing but very slowly. It takes several seconds in the position until a these values stabilize.

I will see if this will be fixed with calibration.

I did not have time to look into Madgwick. It was written for the original LSM9ds1 library, and probably contains a lot of tweaks like the slow response. My version may need other tweaks but at least the possibility is there.

if you turn the board to a new position, pitch, yaw and roll also start changing but very slowly. It takes several seconds in the position until a these values stabilize.

With either the Madgwick or Mahony filter, that behavior indicates that the gyro contribution is incorrectly scaled and too small, or the time integration of the gyro contributions fails.

I quickly tested jremington suspicion by multiplying the scale with another factor (e .g. 30). The lag would be gone! Though obviously this not a solution.

It is interesting as according to the datasheet 70e-3 is the correct factor for the 2000dps FS Range. I am wondering if the difference in sensor rate could be the problem.

After all there was a simple mistake in my sketch by applying the scale factor on the values supplied by the LSM9DS1 library. The library does already the scaling. In consequence this resulted in exactly what jremington suggested - an insignificant gyro contribution.
Kudos to jremington and femmeverbeek!

Next I will test calibration.

With either the Madgwick or Mahony filter, that behavior indicates that the gyro contribution is incorrectly scaled and too small, or the time integration of the gyro contributions fails.

I just updated my version of the LSM9DS1.

The getGyroODR(); function now produces the actual value of the sampling rate that was measured upon setting it's value with setgyroODR(..);
For some reason the fastest 952 Hz setting produced aproximately the same rate as the next 476Hz one. But it came with a lot more noise in the form of spikes. So it's not adviced to use this one.

It includes menu operated DIY calibration program. The time integration in one direction is what I used to find a slope factor for the Gyro.

In my case the offset was approximately 3 deg/s and the scale was off by 20%.

I have now tried how Gyroscope offset calibration (no slope yet). I have used the DIY calibration program putting a book on the NANO to have it stable.

Interestingly if I do this calibration there is now a drift.
Without calibration it was working nicely without drift.

The offset that I got is as following:

IMU.gyroOffset[0] = -1.367993;   IMU.gyroOffset[1] = -0.453931;   IMU.gyroOffset[2] = 0.121655;

@femmeverbeek you said your gyro was off by 3 deg/s. Did you mean on a specific access?