Git Product home page Git Product logo

lsm9ds1-ahrs's Introduction

LSM9DS1-AHRS

Mahony AHRS and Tilt Compensated Compass for Arduino and the LSM9DS1 sensor, written and tested for the Adafruit LSM9DS1 breakout board, using I2C connection on an Arduino Pro Mini.

UPDATE October 2023: Python code for calibrating magnetometer and accelerometer added, which optionally replaces Magneto. The results are identical with the two methods.

 references :
    -  https://teslabs.com/articles/magnetometer-calibration/      
    -  https://github.com/nliaudat/magnetometer_calibration/blob/main/calibrate.py

UPDATE March 2021: a new Mahony filter is implemented, which uses as reference directions Up and West (acceleration vector cross magnetic field vector), instead of using the unmodified direction of the Earth's magnetic field. It appears to converge more rapidly than the conventional Mahony approach (as coded by SOH Madgwick), presumably because the reference vectors are orthogonal. See MahonyUW_AHRS.ino.

Standard sensor orientation for Mahony fusion filter (Tait-Bryan angles) is X North (yaw=0) Y West and Z Up (NWU system).

Standard orientation for the tilt-compensated compass: marked Y axis points True North. Correction for the local magnetic declination is included in the code and must be changed to the user's location. One can also change the "North" or Yaw=0 definition by changing the facing vector p in the code.

Note that in both cases above, the X-axis is reflected as required to form a right handed coordinate system. For the 3D fusion filter, North is OPPOSITE to the direction of the "X arrow" on the Adafruit breakout board.

The Sparkfun LSM9DS1 Arduino library is required. Only the default settings and raw sensor data are used.

The currently implemented AHRS algorithm is the standard Madgwick/Mahony scheme found in other repositories. However, new features have been added, such as code to simplify accurate calibration of the accelerometer, magnetometer and gyro. The magnetometer and accelerometer axes are realigned so that the output orientation is meaningful, and to simplify overall operation.

SENSOR CALIBRATION

Gyro, magnetometer and accelerometer calibration is required, for each sensor individually. The Arduino program LSM9DS1_cal_data.ino collects gyro data and calculates the gyro offset (while the sensor is held still), then collects about 300 accelerometer and magnetometer data points, while the user slowly and carefully rotates the sensor in 3D.

You need to cut/paste/copy the output data on the serial monitor, then create two separate comma separated value (.csv) file, one each for the magnetometer and accelerometer x,y,z values, and use them for the final calibration steps.

General magnetometer calibration approaches are described in this excellent blog article:

http://sailboatinstruments.blogspot.com/2011/08/improved-magnetometer-calibration.html

I also strongly recommend this blog post as a general guide to magnetometer/accelerometer calibration

https://thecavepearlproject.org/2015/05/22/calibrating-any-compass-or-accelerometer-for-arduino/

Magneto is a fair sized C program that runs on a PC or a Mac (suggest to use Code::Blocks IDE on Windows). For convenience, I’ve collected all of the basic parts of magneto, described in the sailboatinstruments link, into one file that can be compiled and run on a desktop.

The magneto approach fits an ellipsoid to the data, avoiding statistical problems associated with the min/max approach, rotates the ellipsoid to align with the coordinate axes, scales the axial dimensions to a sphere, and rotates back. The result is a set of offsets and a nine element matrix correction that must be applied to the raw data.

The magneto program was modified to add measurement rejection criteria and to publish data initialization statements that can be incorporated directly into the AHRS code.

A detailed example of using the above procedures in a particularly difficult case, with severe "hard iron" distortion can be found at

https://forum.pololu.com/t/correcting-the-balboa-magnetometer/14315

lsm9ds1-ahrs's People

Contributors

jremington avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lsm9ds1-ahrs's Issues

applying sensor sensitivity

Hi jremington,

Thank you for your code! I have a question regarding the application of sensor sensitivity. In the code you apply the gyro sensitivity of 8.75 mdps/LSB when converting from deg/s to rad/s. However, you do not apply the sensitivities to the accelerometer or magnetometer data. Does this imply that the readgyro() function in the library reads the raw gyro data while the readaccel() function reads the raw data AND converts to g's and the readmag() function reads the raw mag data AND converts to micro Teslas?

Thank you!
coryjonsmith

Trouble with deltat while performing other op on arduino nano

Hello jremington,
Thanks for the code, it is really interessting and it's working directly, which is nice :)
I'm experiencing some issue with yaw calculation as soon as I try to perform other task with arduino (calculate average yaw, doing other stuff).
I think the problem comes from the using of deltat for the quaternion.
For exemple, if I print yaw with nothing else: works fine, yaw value is constant
If I add delay(500), the yaw value is just not stable and shows large variations.
Have you experienced such an issue?
Do you think there is a simple way to deal with this?
Thanks
Best regards
Mix

LSM9DS1 Successors & Icebergs

Hi @jremington,

Following along a similar vein to #6, I would be interested to get your thoughts on the current (2024) selection of IMUs available from Adafruit.

In my application, I am deploying tracking beacons on icebergs in the Canadian Arctic and using the IMUs to determine the iceberg's rotation (and orientation of the instrument): https://github.com/cryologger/ice-tracking-beacon

In the past, I've had very good success with the LSM303 (DLHC/D). When the LSM303 was discontinued, I switched to the LSM6DS33+LIS3MDL and using your LSM9DS1 calibration methods and tilt-compensated code, also achieved good results.

When the LSM6DS33 was discontinued, I switched to the LSM303AGR and again adapted your LSM9DS1 code. However, this time, the results were poor. Despite a seemingly successful calibration, the tilt-compensated heading measurements from deployed instruments were very limited in range (see include figure for example dataset) for icebergs that were confirmed to be making full 360° rotations. I suspect this was likely due to inadequate calibration and/or the magnetometer being less suitable for this application. I would happy for any additional ideas.

As the LSM303AGR doesn't appear to be the best choice of sensor, I'm in the market for a suitable drop-in replacement. Adafruit's offerings are not currently overly plentiful, but I'd be keen to get your thoughts of the most suitable sensor for my application. The LSM6DSOX + LIS3MDL looks like it could be a good option. I intend to continue using your tilt-compensated heading code.

Cheers,
Adam

imu

Code works perfectly but ...

Hey,
First of all thanks a lot for your great code its awesome but i cant figure it out how to use the sensor with other Madgwick because of NED or NWU or ...
Can you please explain how to figure out the NED system to be able to use the sensor with other filters as well as yours.
thanks agian.

Best AHRS / Tilte compensated compass

Hi James! Hope you don't mind contacting you here as I could not find an email or anything like it.

I can see that you have developed code for a range of different 3/6/9 DOF modules so I thought you might be the right person to ask:

- Which is the best module today?

I am after a tilt compensated compass for my boat autopilot project that has been running an LSM303 for a long time, but it seems to be obsolete today. Instead of chasing down an EoL chip, maybe there is better alternatives today?

Thanks in advance!

PS. My autopilot in action with LSM303:
https://www.youtube.com/watch?v=bEQQ-wsNISU

Tilt compensation for model rocket

I am looking to utilize an AHRS algorithm like this in a model rocket. The orientation of the IMU will be such that the x axis will be pointing into the sky perpendicular to the ground. If the x-axis was parallel with the ground the magnetometer would contribute to the yaw calculation relative to north. However, in my configuration it seems that the magnetometer would contribute to the roll calculation relative to north. Is this something that is taken into account in your tilt compensated compass code?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.