ios - Attitude change - angles and axis issue - quaternion math -


i have app records angles user walking around object, while pointing device (preferably) @ center of object. angle gets reset on user's command - reference attitude gets reset.

using euler angles produces gimbal lock, using quaternions , calculating angles way:

double anglefromlastposition = acos(fromlastpositionattitude.quaternion.w) * 2.0f; 

this gives off precision , works if device's pitch , yaw not change. in other words, angle shows 360 degrees end in same place start of circle.

problem 1: if device's yaw , pitch change (user not pointing directly @ center of object), anglefromlastposition. understand part, angle formula shows angle in between 2 device attitudes in 3d space.

scenario:

  • i mark start of rotation attitude , start moving in circle around object while pointing @ center
  • i stop at, say, 45 degrees , change pitch of device pointing higher or lower. angle changes accordingly.
  • what love see is: angle stays @ 45 degrees, if pitch or yaw changes.

question 1 is, how can calculate roll of device using quaternions, , disregard changes in other 2 axes (at least within reasonable number of degrees).

problem 2: if rotate bit , freeze device (on tripod there's no shaking @ all), anglefromlastposition drifts @ rate of 1 degree per 10-20 seconds, , appears not linear. in other words, drifts fast @ first, slows down considerably. no drift @ - angle rock-solid if device stationary. , makes me lost in understanding what's going on.

question 2, going on here, , how can take care of drift?

i went through quite few articles , tutorials, , quaternion math beyond me @ moment, hope able tip, link, or few lines of code.

i have tested , seems work according you're looking in question 1, andrei.

i set homeangle 0, , after first pass store angle returned walkaroundanglefromattitude:fromhomeangle: in homeangle, future use.

my testing included starting device updates using reference frame:

[_motionmanager  startdevicemotionupdatesusingreferenceframe:cmattitudereferenceframexarbitraryzvertical  toqueue:operationqueue  withhandler:handler]; 

and using following methods called within handler:

- (cmquaternion) multiplyquanternion:(cmquaternion)left withright:(cmquaternion)right {      cmquaternion newq;     newq.w = left.w*right.w - left.x*right.x - left.y*right.y - left.z*right.z;     newq.x = left.w*right.x + left.x*right.w + left.y*right.z - left.z*right.y;     newq.y = left.w*right.y + left.y*right.w + left.z*right.x - left.x*right.z;     newq.z = left.w*right.z + left.z*right.w + left.x*right.y - left.y*right.x;      return newq; }  -(float)walkaroundrawanglefromattitude:(cmattitude*)attitude {      cmquaternion e =  (cmquaternion){0,0,1,1};     cmquaternion quatconj = attitude.quaternion;     quatconj.x *= -1; quatconj.y *= -1; quatconj.z *= -1;     cmquaternion quat1 = attitude.quaternion;     cmquaternion quat2 = [self multiplyquanternion:quat1 withright:e];     cmquaternion quat3 = [self multiplyquanternion:quat2 withright:quatconj];      return atan2f(quat3.y, quat3.x); } -(float)walkaroundanglefromattitude:(cmattitude*)attitude fromhomeangle:(float)homeangle {      float rawangle = [self walkaroundrawanglefromattitude:attitude];     if (rawangle <0) rawangle += m_pi *2;     if (homeangle < 0) homeangle += m_pi *2;     float finalangle = rawangle - homeangle;     if (finalangle < 0) finalangle += m_pi *2;      return finalangle; } 

this using modified , extended code finding normal vector ios device

edit deal question 2 & problem 2:

this may not solvable. i've seen in other apps (360 pano example) , have read faulty readings in gyro , such. if tried compensate it, of course you'll end jittery experience when authentic rotational movement gets tossed compensation code. far i've been interpreting last few years, hardware-based issue.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -