Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 4 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.
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
http://mbed.org/forum/helloworld/topic/4476/
posted by Stephen Paulger 19 Jul 2013