Open sverdlovsk opened 9 years ago
Yes I wrote and have used this code and it works as intended. The LSM9DS1 has embedded within it two sensors, one is a magnetometer and one is a combination gyro/accelerometer. The gyro and accelerometer have a single FIFO buffer available that stores up to 32 16-bit gyro and accel data, so in principle, I could just run the FIFO once and then read the gyro and accel data to do the averaging. I do it twice here since I am copying another similar routine (from the LSM9DS0) where the gyro and accel are located in separate sensor devices embedded within one package and have separate FIFO buffers. It was just easier to keep the format of the coding even though the operations are redundant.
Well, how you are separating the data from the fifo then? How do you know who is who?
You read the data from the corresponding gyro or accel data registers, which are different. The normal data registers point to the FIFO buffer.
Are you sure about the magnetometer orientation?
// Sensors x, y, and z axes of the accelerometer and gyro are aligned. The magnetometer
// the magnetometer z-axis (+ up) is aligned with the z-axis (+ up) of accelerometer and gyro, but the magnetometer
// x-axis is aligned with the -y axis of the gyro and the magnetometer y axis is aligned with the -x axis of the gyro!
// We have to make some allowance for this orientation mismatch in feeding the output to the quaternion filter.
...
MadgwickQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f, -my, -mx, mz);
// MahonyQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f, -my, -mx, mz);
ST datasheet (DocID 025715 Rev 1) Fig 1. (p.10) seems to indicate only
mx = -mx
is needed. Note that image has the "orientation dot" in different corner of the device package for the magnetometer!
Is there any reason you are not using the invSqrt(float x) from original Madgwick code to normalize quaternions? It seems to work for me on Cortex M3 just fine.
Yes, I think you are right, I didn't notice the orientation dot difference before. I'll change it but I have to wonder, why did ST change the dot orientation and, maybe it is a typo on their part?
Do you find it makes any difference?
I think I just use sqrt and then take the inverse separately. If you want to use the combined function I see no problem with doing so.
I think I'll ask confirmation from ST. Odd for a datasheet to not use a common coordinate system within a single diagram. For some reason, I get significantly different X- and Y-biases during magnetometer calibration, even if I orient the sensor different way each time to compensate for any external fields. My sensor is on custom PCB so could be something in the HW. Negating just the sign of mx, instead of swapping and negating mx and my, seem to mostly remove systematic drift (i.e. my euler angles after filter/conversion did not converge for a stationary device), but I might have some other error source in my system as well.
I didn't see datasheets worse then ST very often...
I was going to ask ST for confirmation but I'll wait to see what answer they provide you juniskane. ST makes so many derivative products that they often just cut and paste to make their data sheets. But I have found them to be pretty responsive to questions, so I expect we will get a quick and straight answer from them on this issue. Thanks for the heads up!
ST comfirmed that the image in datasheet, including the mixed orientation of the dot is correct.
I hope you don't mind that we have re-used some snippets of your code, of this repository, for our ThingSee One device: http://www.thingsee.com/
It has the new LSM9DS1 sensor, and we have plans to open-source at least the base layer of software. We'll buy you a beer, if meet at a same venue!
Hi, thanks for the update re: ST's figure. I will have to change a couple of things since I was looking at other ST diagrams and they also pull the rotated dot trick. Yes, the code is open-source meaning you may use it as you like. Acknowledgment and beer are gratefully accepted! I'll be at CES in January.
@kriswiner does this commit https://github.com/kriswiner/LSM9DS1/commit/b78206d10598aa88034d3fda7c1e1ccc11079c55 refer to the changes you are talking about?
The question says it all. I'm looking at
and have many questions... Just one, for example:
I can see that you're indeed, enabling the fifo, but why is it gyro? You just enabled above all axes for both G and XL Then you do:
Sorry, I don't see where the difference is and how is it now XL and not G? What am I missing?
Thanks.