Go Down

### Topic: Paying Job: Arduino Tilt, Roll, and Heading (with adafruit sensors?) (Read 2481 times)previous topic - next topic

#### tgwms

##### Sep 02, 2013, 06:41 am
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

#### johnwasser

#1
##### Sep 02, 2013, 01:19 pm
The math doesn't look that bad:

I think this is how it looks after being translated to Arduino code:
Code: [Select]
`float My, Mx, Mz; // Values from magnetometerfloat 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 directionsconst float Mmaxx = ?????;  // Max X reading with magnetometer rotated in all directionsconst float Mminy = ?????;   // Min Y reading with magnetometer rotated in all directionsconst float Mmaxy = ?????;  // Max Y reading with magnetometer rotated in all directionsconst float Mminz = ?????;   // Min Z reading with magnetometer rotated in all directionsconst float Mmaxz = ?????;  // Max Z reading with magnetometer rotated in all directionsfloat NormalizedMx = (Mx-Mminx) / (Mmaxx-Mminx) * 2 - 1;  // Convert to -1:1 rangefloat 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)`
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

#### 1ChicagoDave

#2
##### Sep 04, 2013, 04:51 am

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?

#### tgwms

#3
##### Sep 08, 2013, 04:53 pm
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

Go Up