Go Down

Topic: tilt compensated magnetometer (Read 1 time) previous topic - next topic

cjdavies


You have to convert the ADC output to signed values where 0 represents zero acceleration - this is fundamental to all such sensors.

Normally sensors output V/2 for a zero value (if the sensor takes 3.3V then this is 1.65V, which will read as 338 on the analogRead() for a 5V Arduino.  So you should subtract 338 from each of your readings.

This is probably it. I asked the write of the library if I would have to do anything special, like scaling, because I was using an analogue accelerometer rather than an I2C one, but he assured me I could just bung in the raw values. I'll try this probably first thing on Monday & see what the difference is, but it sounds promising.

[QUOTE = VccDood]Are the mag and accl mounted horizontally (maximum rotation never carries it past vertical)?[/quote]
My testing has been with them both mounted horizontally, but in theory this library should allow for 360 degree tilt compensation of the magnetometer (at least according to the application note that the library is based on).

[QUOTE = VccDood]Has the mag been calibrated to account for the hardware you are using?[/quote]
The library has a hard iron offset solver. Hopefully once I've followed MarkT's advice the readings I get after applying the result of the hard iron offset solver will be good.

cjdavies

I actually ordered a MMA8452 accelerometer (the same model as the library author's example code is written for) because it was cheap & I hoped that it would alleviate my problems. It arrived this morning, I've connected it up, installed the library & corrected the axes so that both it & the magnetometer match the NED system.

The raw x/y/z readings from both the accelerometer & the magnetometer are correct (eg the accelerometer axes read 1g when the +ve direction is pointed down, -1g when +ve direction pointed up), the pitch & roll calculations from the library are correct (eg clockwise rotation about x & y produce +ve roll & pitch respectively, anticlockwise produce -ve). But the yaw calculation from the library is wrong - it produces -ve yaw when rotated clockwise around the +ve z axis & +ve yaw when rotated anticlockwise around +ve z axis.

Most irritating :(

MarkT



The raw x/y/z readings from both the accelerometer & the magnetometer are correct (eg the accelerometer axes read 1g when the +ve direction is pointed down, -1g when +ve direction pointed up),



That's definitely wrong, if +Z axis points up to the sky, the Z reading should be +1g.
[ I won't respond to messages, use the forum please ]

MarkT

I should clarify that rather bald statement since it may defy intuition at a first reading.

Imagine you are in a lift.  You can feel the push of the floor of the lift on your feet - if you are at rest (w.r.t. the building) then you'll feel your normal weight (i.e.  m * g ) as a push up against your feet.   (The floor feels it as a push down from your feet - action and reaction are equal and opposite)

Now I accelerate the lift towards the roof (that's in a +Z direction) - you'll feel your apparent weight increase during this acceleration, so you'll feel m * (g+a) as your weight where a is the acceleration upwards relative to the building.

Now suppose the cable fails - the lift now accelerates downwards (w.r.t. the building - i.e. that's an acceleration of -g).  You feel yourself weightless (i.e. m*(g-g) == 0)

Replace yourself by the test-mass inside the accelerometer and the lift by the accelerometer package and you'll see that it registers gravity as +g in an upwards direction if stationary (w.r.t the earth's surface).
[ I won't respond to messages, use the forum please ]

Go Up