LSM303DLH Axis Problem

19 Jul 2013

Hi, all I'm not sure who can help me with this problem, but i have a sparkfun tilt compensated compass or (acc/magnometer) and i have used the library by micheal at mbed here. i have calibrated the axis and all is so far working well. I have passed these offsets to the offset function and when i point at north i get north. but the heading change from my sensor is only giving me the vertical axis in degrees? i assume it's in the vector math in the vector.h or cpp file that calculates all the axis to the -y axis. when i hold it flat i wish to have a horizontal compass not a vertical one.

here is my calibrated axis on the left pic. There is a small lobe on the -y axis due to some wires interfering with the magnometer, but this just a testing procedure so no problem.

/media/uploads/Reski/calibrated.jpg

In this line of code:

float LSM303DLH::heading() { return heading((vector){0,-1,0}); }

is this where it gets it's -y from vector command? I'm sorry if this sounds simple, i'm just trying to understand the command. This function (below) is called inside the heading function and everything seems to be working, except it reads from horizon north 0 degrees in the vertical over my head to 180 and back underneath to 360-0 degrees. How can i make it read on the horizontal plane?

float LSM303DLH::heading(vector from) { vector a, m;

this->read(a, m);

// compute heading //

vector temp_a = a; normalize vector_normalize(&temp_a); vector_normalize(&m);

compute E and N vector E; vector N; vector_cross(&m,&temp_a,&E); vector_normalize(&E); vector_cross(&temp_a,&E,&N);

compute heading float heading = atan2(vector_dot(&E,&from), vector_dot(&N,&from)) * 180/M_PI; if (heading < 0) heading += 360;

return heading; }

I appreciate anyone's help who has good experience with this sensor, or at least this library. Thx

19 Jul 2013

/media/uploads/Reski/calibrated.jpg

19 Jul 2013

Putting code between code tags: <<code>> and <</code>> makes it more readable. Also linking the library you use helps ;).

I am not 100% sure I understand your question, but did you have a look at the libraries documentation? http://mbed.org/users/shimniok/code/LSM303DLH/docs/aea5caec809c/classLSM303DLH.html. That function returns the heading with respect to the specified axis, so {0,-1,0} is -y axis. If you want x-axis, it will be {1,0,0}. (I assume it uses the standard x, y, z order).

19 Jul 2013

Hi erik sry, this is my first post here. trying to make it as clear as possible.

"That function returns the heading with respect to the specified axis, so {0,-1,0} is -y axis" - this part is working fine, but the degree axis is from in front of me pointing north, then you tilt the board in the verticle up facing the sky and continue over your head in a circle back to horizion. so this axis is not helping when i want to hold the board flat and turn from left to right (as in using a compass). Left to right it read 0 degrees (as it should in respect to the verticle axis). When i change the reference as you said "If you want x-axis, it will be {1,0,0}. (I assume it uses the standard x, y, z order)" this does not work. The angles are completely wrong, and dont move in any rational manner, so i will assume that changing that part of the code is incorrect.

I cannot find any documentation realating to this adjustment and how to implement it to this library.

Below is the library im using.

19 Jul 2013

Import libraryLSM303DLH

Interface library for STMicro LSM303DLH 3-axis magnetometer w/ 3-axis acceleromter. Computes magnetic heading.

19 Jul 2013

This is my main program with my calibrated values added into the offsets, and the library i'm using is the one above. I have it functioning but just in the verticle bearing not along the horizontal. if i turn toward west it will maintain 0 degrees to horizion. any help would be greatly appreciated, i'm still working at it but am little stuck right now. Would it help if i was to change the Vectors in the vector.cpp file to calculate from a different axis? i not sure.

#include "mbed.h"
#include "LSM303DLH.h"

Serial debug(USBTX,USBRX);
LSM303DLH compass(p9, p10);

int main() {
     float x = 16.1;
     float y = -31.05;
     float z = 17.45;
     float hdg;
     debug.format(8,Serial::None,1);
     debug.baud(9600);
     debug.printf("LSM303DLH Test\x0d\x0a");
     compass.setOffset(x,y,z);
     compass.setScale(1.00, 1.00, 1.00);   
     while(1) {
       hdg = compass.heading();
       debug.printf("Magnetic Bearing: %.1f\n\r", hdg);
       
       wait(0.1);
     }
}
19 Jul 2013

Looking at the description it should really work by giving it {1,0,0}, but did you also try other values? Like {-1,0,0}, or {0,0,1}.