0

I need to make an app to find the orientation of the phone. Some use case which I want to test are

  • how much of the time the phone is used in reading position (held flat)
  • how much of the time it is used for making calls (vertical).
  • How much of the time it is held in pocket.

I assume I should be able to get all this from orientation sensors. I need to mention here that I have recently started andriod development so I would prefer that the solution assumes raw data from sensors such that it can be processed in Matlab later. Infact a colleague is helping me in andriod development.

I used the standard way of doing it. Method :1

if (SensorManager.getRotationMatrix(rotationMatrix, null, accelerationValues, geoMagnetValues)) {

            SensorManager.getOrientation(rotationMatrix, orientation);

Roll and azimuth were OK in the range -pi to pi but as pointed in Android Compass that can Compensate for Tilt and Pitch pitch was in the range -pi/2 to pi/2 and I was having problem handling this. So I bumped into the code at Android Compass that can Compensate for Tilt and Pitch. I have just used it without the screen rotation adjustment. I have a few queries. Pitch as defined in Android Compass that can Compensate for Tilt and Pitch is different than what I get by method:1 in that when I tilt the phone right-wards the pitch value changes whereas it should not change. In fact it corresponds to roll value of method 1. However when I turn my phone left the pitch by the method in Android Compass that can Compensate for Tilt and Pitch gives roll value but with a different sign. Azimuth is OK. Finally m_pitch_axis_radians I could totally not comprehend. I know I am having some problem in interpreting this different coordinate system but if I could get a hint as to how the pitch , roll and azimuth in Method :1 relate to the method in Android Compass that can Compensate for Tilt and Pitch I shall be thankful

Community
  • 1
  • 1
RajaKashif
  • 1
  • 1
  • 3

1 Answers1

2

If you think of an airplane, the pitch is the angle by which the nose of the airplane is above or below horizontal. So looking at the image below, depending on whether you're in portrait or landscape depends on whether the "nose" is the long edge or the short edge. Hence depending on the orientation of the device (i.e. portrait vs landscape), the definition of pitch and roll can switch.

phone with axes labelled

Regarding m_pitch_axis_radians, the code in Android Compass that can Compensate for Tilt and Pitch is using a coordinate system which is defined by azimuth, pitch and pitch axis, rather than the standard azimuth, pitch and roll. I suggest that you study the corresponding maths article What's the best 3D angular co-ordinate system for working with smartphone apps.

Community
  • 1
  • 1
Stochastically
  • 7,616
  • 5
  • 30
  • 58
  • Thanks @Stochastically for pointing to that. I will try to see if the code in http://stackoverflow.com/questions/16317599/android-compass-that-can-compensate-for-tilt-and-pitch really covers the use cases I mentioned in the start. Any prehand thoughts or link to any other thread which covers the use cases I mention ? – RajaKashif Jul 16 '14 at 12:45
  • To work out reading position vs making calls vs in pocket I think you will need to collect a lot of data on the orientation of the device, and then devise a clever algorithm to distinguish the different cases. Not easy. Good luck. – Stochastically Jul 16 '14 at 12:53
  • I quickly went through the maths of the coordinate system defined by you. I will now try the code to figure out whether the three outputs azimuth, pitch and pitch axis can help me cover the use cases. Can you point out the range of these three outputs just for confirmation. for e.g with the traditional method azimth and roll are in the range of [-pi,+pi] while pitch is in the range of [-pi/2, pi/2]. How is it in this new coordinate system. Also on the pitch axis, will it be an output representing angle. If so why is axis in the name. – RajaKashif Jul 16 '14 at 14:59
  • @RajaKashif I haven't look at this for a while, but from memory, the pitch axis is the axis about which the pitch rotation occurs. – Stochastically Jul 21 '14 at 14:03