Derivation of formula for determening angle from accelerometer in NXP paper - Page 1
Forum section: electronics / general

author: BurnedResistor
author_rank: Regular Contributor
timestamp: February 23, 2017, 08:47:59 pm
content: In studying the development of firmware for calculating the angle of an object given the readings of an accelerometer, I came across the following application note by NXP semiconductorhttp://www.nxp.com/assets/documents/data/en/application-notes/AN3461.pdfwhich poses the following:While I fully understand what the application note describes, I am not able, myself, to manipulate equation 24 to solve for pitch and roll as is done to yield eqn. 25 and 26 in the note. I just feel like I am missing something crucial:Is anybody able to solve eq. 24 for pitch and roll to yield the given results? if so, how?I apologies if this is the incorrect sub forum!

author: lujji
author_rank: Contributor
timestamp: February 23, 2017, 11:33:29 pm
content: It becomes very easy to derive the angles with some basic trigonometry if you simply draw the vectors on a piece of paper. I suggestthisappnote by AD instead. Page 7 has formulas for calculating angle from accelerometer readings.

author: BurnedResistor
author_rank: Regular Contributor
timestamp: February 24, 2017, 07:02:53 am
content: Oh wow, thanks!still, out of curiosity, any idea on how the above equation could be solved? I am somewhat determined to find an awnser now

author: jpittner
author_rank: Contributor
timestamp: February 24, 2017, 01:29:27 pm
content: Hi,it's a high school trigonometry:Write eq. 24 separately for x,y,z components, the resulting eqs denote (1), (2), (3) respectively.Divide (2) by (3) lhs by lhs, rhs by rhs, using tan x = sin x / cos x you get eq. 25.Add square of (2) and square of (3) and take a square root of it, this yieldssqrt(Gpy^2+Gpz^2)/Gp = cos theta, using the identity (sin x)^2 + (cos x)^2=1; denote this (4).Now divide eq. (1) by (4) and reverse the sign -> you get eq. 26.

author: BurnedResistor
author_rank: Regular Contributor
timestamp: February 24, 2017, 03:12:07 pm
content: Quote from: jpittner on February 24, 2017, 01:29:27 pmSeeing I am in highschool right now, and have just started touching on trig, I am super thankfull for your help

author: BurnedResistor
author_rank: Regular Contributor
timestamp: February 24, 2017, 03:45:02 pm
content: Quote from: jpittner on February 24, 2017, 01:29:27 pmI have just tried to fully walk thru the steps you described to make sure I have a good grasp on the thing. I was able to get eq25, but am a little confused as to how you solve for eqn26. Do you mind giving a little more detail/showing me?

author: kulky64
author_rank: Regular Contributor
timestamp: February 24, 2017, 06:05:54 pm
content: \$ \tan\theta=\frac{\sin\theta}{\cos\theta}=\frac{-Gpx}{\cos\theta\sqrt{Gpx^2+Gpy^2+Gpz^2}} \$We know that vector \$ \begin{bmatrix}-\sin\theta\\\cos\theta\sin\phi\\\cos\theta\cos\phi\end{bmatrix} \$ is a unity vector and therefore:\$ (-\sin\theta)^2+(\cos\theta\sin\phi)^2+(\cos\theta\cos\phi)^2=1 \$\$ (-\sin\theta)^2+\frac{Gpy^2}{Gpx^2+Gpy^2+Gpz^2}+\frac{Gpz^2}{Gpx^2+Gpy^2+Gpz^2}=1 \$using \$ \sin^2\theta+\cos^2\theta=1 \$\$ \frac{Gpy^2+Gpz^2}{Gpx^2+Gpy^2+Gpz^2}=1-\sin^2\theta =\cos^2\theta \$\$ \cos\theta=\frac{\sqrt{Gpy^2+Gpz^2}}{\sqrt{Gpx^2+Gpy^2+Gpz^2}} \$Now if we substitute last expression for \$ \cos\theta \$ into first equation we get:\$ \tan\theta=\frac{\sin\theta}{\cos\theta}=\frac{-Gpx}{\sqrt{Gpy^2+Gpz^2}} \$

author: BurnedResistor
author_rank: Regular Contributor
timestamp: February 25, 2017, 08:24:07 am
content: Quote from: kulky64 on February 24, 2017, 06:05:54 pmThank you! All of you are bloody amazing