Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on what you want to do with the collected data and what ways the user will go with that recording iPhone in her/his pocket. The reason is that Euler angles are no safe and especially no unique way to express a rotation. Consider a situation where the user puts the phone upright into his jeans' back pocket and then turns left around 90°. Because CMAttitude is related to a device lying flat on the table, you have two subsequent rotations for (pitch=x, roll=y, yaw=z) according to this <a href="http://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MotionEvents/MotionEvents.html#//apple_ref/doc/uid/TP40009541-CH4-SW22" rel="noreferrer">picture</a>:</p> <ul> <li>pitch +90° for getting the phone upright => (90, 0, 0)</li> <li>roll +90° for turning left => (90, 90, 0)</li> </ul> <p>But you can get the same position by:</p> <ul> <li>yaw +90° for turning the phone left (0, 0, 90)</li> <li>pitch -90° for making the phone upright (-90, 0, 90)</li> </ul> <p>You see two different representations (90, 90, 0) and (-90, 0, 90) for getting to the same rotation and there are more of them. So you press Start button, do some fancy rotations to put the phone into the pocket and you are in trouble because you can't rely on Euler Angles when doing more complex motions (s. <a href="http://en.wikipedia.org/wiki/Gimbal_lock" rel="noreferrer">gimbal lock</a> for more headaches on this ;-)</p> <p>Now the good news: you are right linear algebra will do the job. What you can do is force your users to put the phone in always the same position e.g. fixed upright in the right back pocket and calculate the angle(s) relative to the ground by building the <a href="http://en.wikipedia.org/wiki/Dot_product#Geometric_interpretation" rel="noreferrer">dot product</a> of gravity vector from <a href="http://developer.apple.com/library/ios/documentation/CoreMotion/Reference/CMDeviceMotion_Class/Reference/Reference.html#//apple_ref/occ/instp/CMDeviceMotion/gravity" rel="noreferrer">CMDeviceMotion</a> <strong>g = (x, y, z)</strong> and the postion vector p which is the -Y axis (0, -1, 0) in upright position:</p> <p>g • x = x*0 + y*(-1) + z*0 = -y = ||g||*1*cos (alpha)</p> <p>=> <strong>alpha = arccos (-y/9.81)</strong> as total angle. Note that gravitational acceleration g is constantly about 9.81</p> <p>To get the left-right lean angle and forward-back angle we use the tangens:</p> <p><strong>alphaLR = arctan (x/y)</strong></p> <p><strong>alphaFB = arctan (z/y)</strong></p> <hr> <p><strong>[UPDATE:]</strong></p> <p>If you can't rely on having the phone at a predefined postion like (0, -1, 0) in the equations above, you can only calculate the total angle but not the specific ones alphaLR and alphaFB. The reason is that you only have one axis of the new coordinate system where you need two of them. The new Y axis <strong>y'</strong> will then be defined as average gravity vector but you don't know your new X axis because every vector perpedicular to y' will be valid.</p> <p>So you have to provide further information like let the users walk a longer distance into one direction without deviating and use GPS and magnetometer data to get the 2nd axis z'. Sounds pretty error prone in practise.</p> <p>The total angle is no problem as we can replace (0, -1, 0) with the average gravity vector (pX, pY, pZ):</p> <p>g•p = x<em>pX + y</em>pY + z<em>pZ = ||g||</em>||p||*cos(alpha) = ||g||^2*cos(alpha)</p> <p>alpha = arccos ((x<em>pX + y</em>pY + z*pZ) / 9.81^2)</p> <hr> <p>Two more things to bear in mind:</p> <ul> <li>Different persons wear different trowsers with different pockets. So the gravity vector will be different even for the same person wearing other clothes and you might need some kind of normalisation</li> <li>CMMotionManager does not work in the background i.e. the users must not push the standby button</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload