Pages: [1]   Go Down
Author Topic: Paying Job: Arduino Tilt, Roll, and Heading (with adafruit sensors?)  (Read 1775 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I hate this to be my first post, but this is my need. Sorry if this is not the right place to post this...

I want to sense tilt, roll, and heading (tilt compensated) with an Arduino. I am new on programming, and finding the software side of the matter too challenging for my amount of free time. Currently I am using an Adafruit LSM303DLHC accelerometer + magnetometer, but I am open to using any other hardware so long as it is common, affordable, and available long-term.

So here it is: It is worth cash if you can supply the ability to return tilt, roll, and heading with rights released to me for any use. Name your price.

Hope this finds the forum well.

Write me here, or directly at t@tgwms.com

Thank-ya-much

Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8821
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The math doesn't look that bad:
http://www.solutions-cubed.com/content/Downloads/Breakout%20Modules/DATASHEET_BM004.pdf

I think this is how it looks after being translated to Arduino code:
Code:
float My, Mx, Mz; // Values from magnetometer
float Ax, Ay, Az; //  Values from accelerometer

// Pitch and Roll:
float Axn = Ax / sqrt(Ax*Ax + Ay*Ay + Az*Az);
float Ayn = Ay / sqrt(Ax*Ax + Ay*Ay + Az*Az);
float Pitch = asin(-Axn);
float Roll = asin(Ayn/cos(Pitch));

// Normalize the magnetometer readings:
const float Mminx = ?????;   // Min X reading with magnetometer rotated in all directions
const float Mmaxx = ?????;  // Max X reading with magnetometer rotated in all directions
const float Mminy = ?????;   // Min Y reading with magnetometer rotated in all directions
const float Mmaxy = ?????;  // Max Y reading with magnetometer rotated in all directions
const float Mminz = ?????;   // Min Z reading with magnetometer rotated in all directions
const float Mmaxz = ?????;  // Max Z reading with magnetometer rotated in all directions

float NormalizedMx = (Mx-Mminx) / (Mmaxx-Mminx) * 2 - 1;  // Convert to -1:1 range
float NormalizedMy = (My-Mminy) / (Mmaxy-Mminy)  * 2 - 1;
float NormalizedMz = (Mz-Mminz) / (Mmaxz-Mminz)  * 2 - 1;


// Tilt Compensated Heading:
float Mxh = NormalizedMx * cos(Pitch) + NormalizedMz * sin(Pitch);
float Myh = NormalizedMx * sin(Roll) * sin(Pitch) + NormalizedMy * cos(Roll) - NormalizedMz * sin(Roll) * cos(Pitch);
float CompensatedHeading = atan(Myh/Mxh);  // Heading in radians (multiply by 180.0/pi to get degrees)
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Chicago
Offline Offline
Sr. Member
****
Karma: 5
Posts: 456
With every answer comes more questions.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That looks about right.

Also, to calculate heading in terms of "True North" vs magnetic north, you can apply your declination angle. This can be found here - http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-documents/Magnetic__Literature_Application_notes-documents/AN203_Compass_Heading_Using_Magnetometers.pdf

....assuming you're in North America somewhere.

Are you able to figure this out using the Adafruit libraries & example code? Or, do you need a finished sketch?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Guys thank you... John seriously that was above and beyond! I really appreciate it.

But I am not looking to figure it out, or to get close. I am looking for someone to supply functional code that returns an accurate value for those 3 variables, and I supply money. I know it may sound strange, but I just don't have the time to tinker.

As an added detail to the project, the sensor will be 'stood up' to for its entire usage. So "Y" or "X" will be within 45 degrees of 'up', and "Z" will be horizontal. That changes the pan/tilt relevance and I think it changes the heading compensation calculations.

Thank you again! Feel free to write me direct here t@tgwms.com
Logged

Pages: [1]   Go Up
Jump to: