1

I'm making an AR app similar to Google Sky Map, and need my roll value to go from -90 degrees when the handset is laying flat, to 0 degrees when the user is holding the handset perpendicular to the ground, and to +90 degrees when pointing the back of the handset (ie, the camera directly up into the sky.

My problem is that the accelerometer sensor returns values from -90 to +90, but +90 is when the handset is perpendicular to the ground. I can't simply subtract 90 from the value, because the values start to decrease as the handset starts to tilt back. So basically, I need a way of knowing when the handset has gone beyond +90?

Sorry if I haven't explained this very well, it's quite hard to get across in words.

edit: 12/03/12

I used this: http://www.mail-archive.com/android-beginners@googlegroups.com/msg23415.html

Undo
  • 25,519
  • 37
  • 106
  • 129
sgccarey
  • 492
  • 2
  • 6
  • 16
  • What do you want to do with the roll later? Anyway, I would not use [Euler angles](http://stackoverflow.com/a/5578867/341970) such as roll. You can do anything with rotation matrices that you can do with the Euler angles. – Ali Mar 10 '12 at 22:16
  • By the way, I think you mean "pitch", not "roll" – Edward Falk Jun 07 '13 at 22:01

3 Answers3

0

In general, you should never use the ORIENTATION sensor, and you should avoid using getOrientation() as well. Instead, you should be using ACCELEROMETER or GRAVITY combined with MAGNETOMETER with getRotationMatrix() and using 3-d transforms for your app.

You can also use the ROTATION sensor which returns a Quaternion, which is easy enough to convert to a transformation matrix.

The only time you want to use ORIENTATION is when you're displaying numeric values in human-friendly terms.

See https://stackoverflow.com/a/11550241/338479 and https://stackoverflow.com/a/13895376/338479 for much more detailed answers and sample code.

Community
  • 1
  • 1
Edward Falk
  • 9,991
  • 11
  • 77
  • 112
0

Use Accelerometer sensor instead of Orientation sensor. And dont confuse, dont mix theirs.

Silver
  • 12,437
  • 2
  • 14
  • 11
0

Value of roll will go beyond the value of +90 when the acceleration across z axis is negative. So you can use this fact and calibrate your phone accordingly.

aps109
  • 167
  • 1
  • 3
  • 15