LSM303 mag + accel accuracy help

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
sekramer10
 
Posts: 185
Joined: Wed Oct 28, 2015 12:42 am

LSM303 mag + accel accuracy help

Post by sekramer10 »

I bought the LSM303 accelerometer + magnetometer board and I am disappointed with the performance as received. The heading calculated from atan2(event.magnetic.y, event.magnetic.x) is off by up to 40 degrees. It is also very sensitive to the levelness of the board, tilting it a few degrees causes large changes in the heading calculation. It is basically unusable as I have received it. I am using 8" wires and can't place the board any further away from the controlling nano board for this application. Can you help me with this please.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM303 mag + accel accuracy help

Post by adafruit_support_bill »

There are lots of things that can affect the accuracy of magnetometer heading calculations. For starters, it sounds like you are using non-tilt-compensated code. Pololu has a nice tilt-compensated function in their library here: https://github.com/pololu/lsm303-arduino

Magnetometers also are susceptible to zero offset errors, as well as hard and soft iron errors. These can be addressed with calibration. DIYDrones has a nice article on magnetometer calibration here: http://diydrones.com/profiles/blogs/adv ... or-dummies

User avatar
sekramer10
 
Posts: 185
Joined: Wed Oct 28, 2015 12:42 am

Re: LSM303 mag + accel accuracy help

Post by sekramer10 »

Thanks Bill. I have a large robot I want to control to move along a variable heading, what sensor would be best for providing the heading measurement?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM303 mag + accel accuracy help

Post by adafruit_support_bill »

A calibrated magnetometer is your best bet for an absolute heading. If your robot will be operating on an incline, you will want to have an accelerometer for tilt-correction. Gyros can be handy for estimating relative rotation in the short-term, but are subject to drift. There are a lot of reasonably priced 9DOF IMUs with 3 axis each of magnetometer, gyro and accelerometer. These are commonly used in navigation systems for drones and robots.

But robots can be a challenging environment for magnetometers to work in. There are hard-iron errors from permanent magnet motors - as well as any nearby wires carrying significant current. There are also likely soft-iron errors from any magnetically permeable materials in the robot chassis.

Try to locate your magnetometer as far away from motors, power supplies and motor wiring as is practical. Then calibrate it in-place in order to compensate for all the chassis-induced errors.

User avatar
sekramer10
 
Posts: 185
Joined: Wed Oct 28, 2015 12:42 am

Re: LSM303 mag + accel accuracy help

Post by sekramer10 »

Bill,

Thanks again. The tilt-compensation and calibration really helped, but what helped more is I found some metal parts nearby in my desk, which I was not aware of. HUGE difference!

User avatar
sekramer10
 
Posts: 185
Joined: Wed Oct 28, 2015 12:42 am

Re: LSM303 mag + accel accuracy help

Post by sekramer10 »

Bill, I only need sense relative heading, I can set the initial heading, and if the relative heading sensor is accurate it should operate well. Does your recommendation change if you only need a relative heading measurement?

Thanks

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM303 mag + accel accuracy help

Post by adafruit_support_bill »

The gyro can work with relative headings, but only for short periods as it is subject to drift. With careful coding, you may be able to complete 3 or 4 turns with good precision. Maybe less if you are traveling over rough terrain or colliding with other robots.

The long answer is: Each type of sensor has its strengths and weaknesses. And a successful navigation system will employ "data fusion" from multiple sensors to generate the most accurate estimate of position and/or orientation. All inertial sensors such as gyros and accelerometers are subject to drift. Magnetometers don't drift, but are subject to local magnetic field anomalies. None of them can give you an absolute position.

GPS can give you an absolute position - but only outdoors and only down to a few meters. Other types of sensors can be used to infer absolute positions relative to landmarks or beacons. Good robot navigation systems will use the absolute position data when they can get it, then use the inertial and magnetic sensors to estimate movements relative to those known locations.

User avatar
sekramer10
 
Posts: 185
Joined: Wed Oct 28, 2015 12:42 am

Re: LSM303 mag + accel accuracy help

Post by sekramer10 »

Thanks Bill. Does GPS give heading info accurately? I can do distance ok by odometry and EM distance sensors. Do you happen to know what makes a cell phone compass accurate?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM303 mag + accel accuracy help

Post by adafruit_support_bill »

GPS calculates heading based on your recent history of movement - not what direction you are pointing to now. Since the resolution is only down to a few meters, the calculation is not very accurate unless you are moving fairly fast. It works pretty well for a car driving on a highway. Not so much for typical robot speeds.
Do you happen to know what makes a cell phone compass accurate?
People often assume that if their magnetometer disagrees with their cell-phone compass that the magnetometer must be wrong. Cell phone compasses are subject to all the same errors and sometimes need to be re-calibrated also. Most phones have pretty good calibration routines built-in and many also do some auto-calibration. But sometimes you need to do the old 'figure-8' calibration routine to get it back in line.
http://android.stackexchange.com/questi ... n-my-phone

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”