Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand your question, I think you are interested in getting the <em>attitude</em> of your device. You can do this using the <code>attitude</code> property of the <code>CMDeviceMotion</code> object that you get from the <code>deviceMotion</code> property of the <code>CMMotionManager</code> object. </p> <p>There are two different angles that you might be interested in the <code>CMAttitude</code> class: <em>roll</em> and <em>pitch</em>. If you imagine your device as an airplane with the propeller at the top (where the headphone jack is), pitch is the angle the plane/device would make with the ground if the plane were in a climb or dive. Meanwhile, roll is the angle that the "wings" would make with the ground if the plane were to be banking or in mid barrel roll.</p> <p>(BTW, there is a third angle called <em>yaw</em> that I think is not relevant for your question.)</p> <p>The angles will be given in radians, but it's easy enough to convert them to degrees if that's what you want (by multiplying by 180 and then dividing by <code>pi</code>).</p> <p>Assuming I understand what you want, the good news is that you may not need to understand any linear algebra to capture and use these angles. (If I'm missing something, please clarify and I'd be happy to help further.)</p> <p><strong>UPDATE</strong> (based on comments):</p> <p>The attitude values in the <code>CMAttitude</code> object are relative to the ground (i.e., the default reference frame has the Z-axis as vertical, that is pointing in the opposite direction as gravity), so you don't have to worry about cancelling out gravity. So, for example, if you lie your device on a flat table top, and then roll it up onto its side, the <code>roll</code> property of the CMAttitude object will change from 0 to plus or minus 90 degrees (+- .5pi radians), depending on which side you roll it onto. Meanwhile, if you start it lying flat and then gradually stand it up on its end, the same will happen to the <code>pitch</code> property. </p> <p>While you can use the pitch, roll, and yaw angles directly if you want, you can also set a different reference frame (e.g., a different direction for "up"). To do this, just capture the attitude in that orientation during a "calibration" step and then use CMAttitude's <code>multiplyByInverseOfAttitude:</code> method to transform your attitude data to the new reference frame.</p> <p>Even though your question only mentioned capturing the "lean <em>angle</em>" (with the ground), you will probably want to capture at least 2 of the 3 attitude angles (e.g., pitch and either roll or yaw, depending on what they are doing), potentially all three, if the device is going to be in a person's pocket. (The device could rotate in the pocket in various ways if the pocket is baggy, for example.) For the most part, though, I think you will probably be able to rely on just two of the three (unless you see radical shifts in yaw throughout the course of a recording session). So for example, in my jeans pocket, the phone is usually nearly vertical. Thus, for me, pitch would vary a whole bunch as I, say, walk, sit or run. Roll would vary whenever I change the direction I'm facing. Meanwhile, yaw would not vary much at all (unless I do kart-wheels, which I can't!). So yaw can probably be ignored for me.</p> <p>To summarize the main point: to use these attitude angles, you don't need to do any linear algebra, nor worry about gravity (although you may want to use this for other purposes, of course).</p> <p><strong>UPDATE 2</strong> (based on Kay's new post):</p> <p>Kay just replied and showed how to use gravity and linear algebra to make sure your angles are <em>unique</em>. (And, btw, I think you should give the bounty to that post, fwiw.)</p> <p>Depending on what you want to do, you may want to use this math. You would want to use the linear algebra and gravity <em>if</em> you need a standardized way of "talking about" and/or <em>comparing</em> attitudes over the course of your recording session. If you just want to visualize them, you can probably still get away with not using the increased complexity. (For example, visualizing (pitch=90, roll=0, yaw=0) should be the same as visualizing (pitch=0, roll=90, yaw=90).) In my approach above, while you could have multiple ways of referring to the "same" attitude, none of them is actually <em>wrong</em>, per se. They will still give you the angles relative to the ground.</p> <p>But the fact that the gyroscope can switch from one valid description of an attitude to another means that what I wrote above about getting away with only 2 of the 3 components needs to be corrected: because of this, you will need to capture all three components, no matter what. Sorry. </p>
    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. 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.
 

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