0

I'm developing a tool which receives motion sensor data and sends it to a machine learning algorithm, which ultimately will deduce different types of movement.

I read the Motion sensor guide and it seems like there is some redundancy in the data you can get from the sensors. For example: the accelrometer data contains gravity data and the linear acceleration data shows acceleration without acceleration due to gravity.

So my question is: do i really need all the sensors to get all forms of motion or can I give up some of them?

EDIT: (clarifying the question)

I want to collect the minimal data that will allow me to deduce the same things. What I'm looking for is user behavior: the angle which the user holds his phone, the way the user moves while using his phone, etc..

The answer I'm looking for should include the sets of sensors that have high correlation within them, such that only some of the sensors in this set are required to deduce the same type of motion\movement\rotation\acceleration\etc..

Tom
  • 1,203
  • 4
  • 21
  • 36

3 Answers3

3

The term "Motion" in the question have no precise meaning. So I answer more generally.

"The way one holds his phone" is nothing but the orientation of the phone.There are three sensors which individually tells the orientation of the phone.

  1. Accelerometer sensor
  2. Orientation sensor
  3. Rotation Vector sensor

Among them only the accelerometer is physical sensor and other two are virtual sensors (they don't have special piece of hardware, they use accelerometer data and report the orientation in different formats).

  1. The orientation sensor is deprecated so you can't use it.
  2. Rotation vector sensor tells the orientation encoded in a quaternion. If your code is based on quaternions then normalize the sensor output using SensorManager.getQuaternionFromVector() and continue. If your code is based on rotation matrix then obtain rotation matrix by calling SensorManager.getRotationMatrixFromVector() passing sensor output and continue. If you want the orientation alone get it by calling SensorManager.getOrientation() passing rotation matrix obtained previously.
  3. Using accelerometer sensor we can find the orientation, but the recommended approach is to combine it with magnetic field sensor output. Call SensorManager.getRotationMatrix() by passing the output of accelerometer output and magnetic field sensor output and get the rotation matrix. If your code is based on rotation matrix, just continue. If you want the orientation alone get it by calling SensorManager.getOrientation() passing rotation matrix obtained in previously. If your code is based on quaternion call SensorManager.getQuaternionFromVector() by passing rotation vector (orientation) obtained previously.

"The way one moves his phone" - Here I consider four motions.

  1. Change of position (Simple translation) and rate change of position (velocity) - No sensor to detect them.
  2. Rate of change of velocity (Simple acceleration) - Accelerometer detects it. But it also contains the gravity component. Normally we need acceleration without gravity component. This could be calculated simply as explained here. However there is another virtual sensor called Linear Acceleration which does the job for us.
  3. Change of orientation (Rotation) - Whenever the orientation changes the accelerometer, orientation and rotation vector sensors report us (gyroscope also reports, but is explained in next point). How to use this sensor to get the current orientation is explained in first part of the answer.
  4. Rate of change of orientation (Angular velocity) - Whenever the orientation changes the gyroscope sensor reports. The output is three numbers representing angular acceleration along x, y and z axes. The unit is radians per second.

Output of the gyroscope sensors is not accurate in long term and the output of accelerometer is not accurate in short term, so combine them to get steady output. For details see this question.

Now it is clear that the gyroscope and accelerometer is required in minimum. However using wide range of sensors minimizes our work.

Community
  • 1
  • 1
Durgadass S
  • 1,098
  • 6
  • 13
1

You can't decide what you get - each sensor's data is already defined, and you get all or nothing. If you see closely, there isn't a place in public API which would let you ask for specific things.

To back this up here's quote from Google's document explaining sensor types:

An accelerometer sensor reports the acceleration of the device along the 3 sensor axes. The measured acceleration includes both the physical acceleration (change of velocity) and the gravity. The measurement is reported in the x, y and z fields of sensors_event_t.acceleration.

If you see into android source, the structs here are strictly defined, and struct for acceleration contains specific fields. So even if you would get 0 in fields you don't like, you won't gain anything.

But what you're referring to are two things - base sensors, which are roughly equivalent to physical sensors on the device, and composite sensors, which combine readings from various physical sensors to get more useful data.

So while you can't decide what you get for a particular sensor (like "only gravity" or "only acceleration in Y axis"), composite sensors do give you data that you can compute by yourself using only base sensors. So linear acceleration is composition of data from accelerometer and gyroscope (or magnetic sensor), after some calculations. Similarly step detector "sensor" uses only accelerometer, but interpretes the data automatically to just give you an event that "yes, someone has made a step" with single value 1.

If you're feeding raw motion data to some algorithms, I would guess base sensors are what you're looking for. That said, I believe you can still safely register for all sensors (both base and composite ones) that combined give you all data that you need (and maybe more), without meaningful battery impact.

For more detailed information on each of the sensors refer to Sensor types on Android website, and if you're curious, you can read up short summary on sensors stack as well.

wasyl
  • 3,421
  • 3
  • 27
  • 36
  • good answer, though I'm looking for sensors i can give up. see edit. – Tom Sep 28 '15 at 12:21
  • I still don't get it, sadly. You want to detect user motion, right? Then you need accelerometer and gyroscope, these are two sensors what will give you both static and dynamic information about how the device is being moved and hold. – wasyl Sep 28 '15 at 13:11
  • That's true. But some sensors give you less raw and more domain-specific data such as linear acceleration, that publishes acceleration without gravity. For the purpose of detecting linear acceleration of the device i would rather use that sensor than the accelerometer. I'm looking for more examples that will encompass all the motion sensors in android. Another example is do I need to collect both gyroscope and rotational vectors in order to deduce rotation of the device. – Tom Sep 28 '15 at 13:19
  • Read the links I've included - you're mixing basic sensors and composite sensors. Accelerometer and gyroscope (and magnetic sensor, temperature, light and some others) are *raw* sensors, which just pass you data from the device. Composite sensors - like linear acceleration sensor, tilt sensor and some others, they give you already processed data, but underneath use only basic(raw) sensors. They don't (and can't) contain *more data* than the basic ones – wasyl Sep 28 '15 at 13:27
  • As for *I'm looking for more examples that will encompass all the motion sensors in android* - these are in the documentation, and copying it wouldn't make much sense. I can't tell you which sensors you should use to *deduce different types of movement*, this is just too broad of a usecase. If you will be using machine learning, I would say basic, raw sensors of accelerometer and gyroscope are enough. – wasyl Sep 28 '15 at 13:30
1

No, you don't need every sensor. Some of the sensors exist as a convenience to the user. Your example of the linear acceleration sensor is one- it tells you the results of the accelerometer with gravity taken out. You could do this yourself from the raw accelerometer data, but that takes a bit of math (you need to subtract the vector gravity over all 3 axes) and a bit of knowhow (did you remember to calibrate the sensor? It may not read 9.8 at rest. For that matter, 9.8 may not be your gravity if you're not at sea level). That's a lot of work that would need to be repeated by each app, so they created a software "sensor" that sits on top of the accelerometer and provides the computed data. It would be unusual for an app to use raw and linear accelerometers in the same app, generally its one or the other. The step counter is another example of this, it guesses at what a step is based on the accelerometer data. You also wouldn't want calibrated and uncalibrated gyroscope data.

As for what you do need- no clue, you don't say enough about what you're trying to do. One warning though- you said you're trying to detect motion. YOu can't do that. You can detect accelerations and rotation. You cannot detect motion at a constant speed. If you're developing any type of app using these it pays to use the correct terminology and think in terms of physics and how the physical accelerometer and gyroscope work, otherwise you're going to cause yourself bugs.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Thanks for your elaborate answer. Motion is maybe a bad translation from my first language. What I'm looking for is user behavior: the way one holds his phone, the way one moves his phone while using it, etc.. – Tom Sep 28 '15 at 12:26