4

When a user has a phone in their pocket, I want to be able to capture acceleration along XYZ in the users coordinate system. I say users coordinate system for 2 reasons:

  1. The orientation of the device in their pocket should not matter, and should give me the same XYZ acceleration values regardless of orientation
  2. Walking direction with respect to the world coordinate system should not matter, so walking west to east and walking east to west should give me the same numbers

My question, is what is the math required to convert from device based acceleration to user based?

I have seen one similar thread on this: Android Convert device coordinate system to "user" coordinate system, but there is no answer, and furthermore I'd like to achieve this without a calibration phase (which that other thread allows for)

I have also seen threads on converting from a device coordinate system to a world coordinate system: Acceleration from device's coordinate system into absolute coordinate system

I have implemented that with the following:

float[] accelerometerMatrix = new float[3];
float[] accelerometerWorldMatrix = new float[3];
float[] gravityMatrix = new float[3];
float[] magneticMatrix = new float[3];
float[] rotationMatrix = new float[9]; 

<code to get and store the sensor values into the respective matrices>

SensorManager.getRotationMatrix(rotationMatrix, null, gravityMatrix, magneticMatrix);

accelerometerWorldMatrix[0] = rotationMatrix[0] * accelerometerMatrix[0] + rotationMatrix[1] * accelerometerMatrix[1] + rotationMatrix[2] * accelerometerMatrix[2];
accelerometerWorldMatrix[1] = rotationMatrix[3] * accelerometerMatrix[0] + rotationMatrix[4] * accelerometerMatrix[1] + rotationMatrix[5] * accelerometerMatrix[2];
accelerometerWorldMatrix[2] = rotationMatrix[6] * accelerometerMatrix[0] + rotationMatrix[7] * accelerometerMatrix[1] + rotationMatrix[8] * accelerometerMatrix[2];

That code, while it works for what it does, puts the accelerometer XYZ values in a world space. Now I need to get from that to the user space.

Ultimately, when a user is walking forwards, I want to be able to get that acceleration value irrespective of 1) which direction they're walking in, and 2) how the device is orientated in their pocket. With the code above, when a user walks forward while facing NorthEast, the XYZ values will be different than if they walked SouthWest, when for my purposes they need to be the same because the user is still moving "forward"

Is there a way to achieve this? I will consider answers with a calibration phase, but ideally I'd like to skip any calibration phases entirely for this

Community
  • 1
  • 1
Simon
  • 9,762
  • 15
  • 62
  • 119
  • What is user coordinate system? – Hoan Nguyen Feb 15 '16 at 16:12
  • @HoanNguyen For example if the user walks forwards acceleration will always be in the +X regardless of phone orientation and world/compass heading theyre walking in. If theyre walking to the left, it will always be +Z for example. So everything is relative to the user, irrespective of how the phone is oriented, or what compass direction theyre going in – Simon Feb 15 '16 at 19:50
  • I does not make sense at all, to the left of what? the user always walks forward isn't it? – Hoan Nguyen Feb 15 '16 at 22:55
  • @HoanNguyen For example if they take a side step to the left. And even if the user is moving forwards, there can still be sideways sway in their hip as they walk – Simon Feb 15 '16 at 23:03
  • From an observer who just at that moment observe the user, the user is moving forward to him. I know what you are aiming at. TYPE_ACCELEROMETER alone won't do. – Hoan Nguyen Feb 15 '16 at 23:09
  • You will need to get the Rotation Matrix and the phone will jiggle in the pocket so only large left or right turn will be accurate. You will also need to assume the first step is moving forward. If this is OK I will write up an answer. – Hoan Nguyen Feb 15 '16 at 23:25
  • @HoanNguyen the most important axis for me is the vertical (whether the user is moving up or down - people tend to move up and down as they walk). As long as that information is accurate then thats OK – Simon Feb 15 '16 at 23:46
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/103548/discussion-between-hoan-nguyen-and-simon). – Hoan Nguyen Feb 15 '16 at 23:55

0 Answers0