3

I have been experimenting with the Coremotion APIS, with the goal of transforming the coordinates from the phone reference system to the "earth" reference system as the one that is stored in the CMAttitude object. What I tried till now is by getting the CMRotationMatrix

CMRotationMatrix r = motionManager.deviceMotion.attitude.rotationMatrix;

and do a matrix multiplication with

CMAcceleration a = motionManager.deviceMotion.gravity;

in the following way (typedef float vec3f[3])

vec3f accelerationInReferenceSystem;
accelerationInReferenceSystem[0] = a.x * r.m11 + a.y * r.m12 + a.z * r.m13;
accelerationInReferenceSystem[1] = a.x * r.m21 + a.y * r.m22 + a.z * r.m23;
accelerationInReferenceSystem[2] = a.x * r.m31 + a.y * r.m32 + a.z * r.m33;

But, no luck. I am not that keen in 3D graphics, and there's not much documentation on how to use the various CMRotationMatrix, quaternions, etc. Before going this way, I have tried to log the values of d.attitude.pitch, d.attitude.roll and d.attitude.yaw. For what I have read, it's not the way to go, but besides that, I have found that the value returned by d.attitude.pitch spans just PI radians so I would need to include the yaw in the computation of the pitch angle from 0 to 2PI in order to understand where the head of the phone is heading. It seemed to me that using the rotation matrix would be the good way to go. Also, I wonder if I need to use a matrix that is the inverse of the current rotation matrix in order to take the coordinates into the system identified by r.attitude, thank you if you can help!

Alex Darsonik
  • 597
  • 5
  • 18

1 Answers1

0

I'm not sure I understand what you want to do.. But if by the 'earth' reference system you mean a fixed reference system, and by 'coordinates' you mean x, y, z coordinates, then it's impossible to do what you're trying to do (or at least, impossible to do accurately). Because you could use these to calculate the displacement of the device, which is impossible to do satisfactorily - see this for example: How can I find distance traveled with a gyroscope and accelerometer?

Community
  • 1
  • 1
baris
  • 304
  • 2
  • 14