1

I have a very basic question about Sensors:

Do magnetic sensors return readings w.r.t the phone's initial orientation or w.r.t the world coordinates?

What about accelerometers? Do they return values w.r.t their previous readings or is each value an independent acceleration relative to the world coordinate system?

I know that gyros return readings relative to the phone's initial orientation. So, how do I convert the yaw, pitch and roll readings from a gyro into the azimuth, pitch and roll readings from a magnetic sensor of a smartphone (I'm using HTC hero)

Thanks!

Imelza
  • 301
  • 1
  • 7
  • 19
  • when you say initial phone orientation, which would that be ? the orientation when the phone was boot up ? when he was first boot up ever ? every boot ? when you first started using the sensor ? if it's one of the latter then you can easily check it, just make a tester that shows up the pitch and roll and test it with your device: put i on a table, boot it, see if the app shows 0,0 then move it so it wont be 0,0, reset again anc check... – codeScriber Dec 05 '10 at 19:17
  • I mean when the app is started. Each time I start sensing with my orientation sensor, it returns the same values so I guess its absolute readings – Imelza Dec 06 '10 at 06:37
  • But for my accelerometer, even when I hold it still or tilt it ever so slightly the values are of the order of 4m/s^2, 7m/s^2 etc. I understand gravity is also a part of this vector, which is especially confusing when I tilt my phone so gravity is 'component-ed' along the different axes but I don't know if the values are relative to the previous readings or they are independent of each other – Imelza Dec 06 '10 at 06:40
  • I thought I could convert gyro readings to compass readings using the initial position. i.e compass(t) = gyro(t) + compass(0),does it make sense to translate from relative to world coordinates this way? thanks – Imelza Dec 06 '10 at 06:40
  • i'm not sure regrding that, i never used the gyro, just motions sensors that gave me exact shifting of the phone on feature phones (accelerometer gives you acceleration in certain vector). it sounds you got more of mathmatics issue more the programatic one :-) – codeScriber Dec 06 '10 at 19:24

2 Answers2

0

As mentioned, the gyroscope measures the angular velocity. The third value returned (values[2]) is the angular velocity regarding the z axis. You can use this value together with the initial value from the magnetometer to calculate current heading: Theta(i+1) = Theta(i) + Wgyro*deltaT

You can receive initial heading orientation from 'Orientation' measurement (values[0]) This measurement is dependent only on the magnetometer. (you can put a magnet or a second phone close to the Smartphone and watch the output going crazy)

The second and third values of the 'Orientation' are dependent on the readings of the Accelerometer. Since the Accelerometer measures gravity, it is possible to calculate the pitch and roll angles from the Accelerometer readings in Axis Y and X.

Hope this helps

Ariel

Ariel
  • 206
  • 1
  • 4
  • 10
0

Android Sensors (upto FroYo) provide the application with "raw" data.
There is bare minimum of "cooking" (ie processing) involved.

The accel & compass device provide absolute accel & magnetic data respectively.
The gyroscope provides relative angular velocity.

Gyroscopes do NOT provide relative data wrt any specific state/position.
What you need to understand is that gyroscopic data is angular-velocity.
Angular velocity is simply, how fast the phone is rotating (in degrees-per-second).
So once you hold it still, gyro says (0,0,0) &
as you rotate, you get how fast it is rotating.
This continues until u again hold it back still
when the gyro reading again becomes (0,0,0).

Theoretically the gyro can be used in "callibrate" the compass.
But to do so would require a lot of experimentation on your part.
The ideal place to fiddle around would be the sensor-HAL.

NOTE: You would need to turn-ON all the sensor h/w even if
ONLY compass data is reqd. As you will be cross-referencing
the gyro/accel data for that. This will mean larger power consumption &
extremely poor battery life. All the sensors turned on continuously can
drain the battery of a standard Android phone in 4-5hrs.

You can read more Android Sensors here.

TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130