Author Topic: Derivation of formula for determening angle from accelerometer in NXP paper  (Read 3845 times)

0 Members and 1 Guest are viewing this topic.

Offline BurnedResistorTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: at
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 semiconductor http://www.nxp.com/assets/documents/data/en/application-notes/AN3461.pdf
which 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!
 

Offline lujji

  • Contributor
  • Posts: 29
  • Country: 00
It becomes very easy to derive the angles with some basic trigonometry if you simply draw the vectors on a piece of paper. I suggest this appnote by AD instead. Page 7 has formulas for calculating angle from accelerometer readings.
 

Offline BurnedResistorTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: at
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 :)
 

Offline jpittner

  • Contributor
  • Posts: 14
  • Country: cz
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 yields
sqrt(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.
« Last Edit: February 24, 2017, 01:32:03 pm by jpittner »
 
The following users thanked this post: BurnedResistor

Offline BurnedResistorTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: at
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 yields
sqrt(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.

Seeing I am in highschool right now, and have just started touching on trig, I am super thankfull for your help :)
 

Offline BurnedResistorTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: at
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 yields
sqrt(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.


I 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?
 

Offline kulky64

  • Regular Contributor
  • *
  • Posts: 61
  • Country: sk
\$ \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}} \$
« Last Edit: February 24, 2017, 06:34:58 pm by kulky64 »
 

Offline BurnedResistorTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: at
\$ \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}} \$

Thank you! All of you are bloody amazing :)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf