10 years, 9 months ago.  This question has been closed. Reason: Duplicate of forum post

Sparkfun LSM303DH Vector problem

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