I'm recording the following sensor values from my tablet (given as constants of the Sensor class):
TYPE_ACCELEROMETER
TYPE_GRAVITY
TYPE_GYROSCOPE
TYPE_LIGHT
TYPE_LINEAR_ACCELERATION
TYPE_MAGNETIC_FIELD
TYPE_ROTATION_VECTOR
The problem is that I'm producing too much data. That's why I want to use less sensors. I think some sensors are redundant, i.e. can be computed from other sensor values. For example I think linear acceleration and gravity will give accelerometer and perhaps the rotation vector can be computed from linear acceleration and gyroscope (how?).
Which sensors are redundant? I'm guessing that accelerometer (or linear acceleration) as well as the rotation vector are redundant. Moreover, can the magnetic field be used for the computation of other measures (like the rotation vector)? I don't need the magnetic field value on its own, so perhaps I can also throw it out.
Edit: I think it holds that accelerometer = gravity + linear acceleration. Does this mean that gravity and linear acceleration correlates with the accelerometer? Correlated features would be useless as input to my machine learning pipeline.
I guess that rotation vector is computed with the help of the magnetic field but my magnetic field sensor has low accuracy (reported by Android), so I could drop magnetic field as well as rotation vector.
Related
I'm using both gyroscope and accelerometer in an Android. What I do is only displaying values from both sensors. I don't get why to track device acceleration, I have to use gyroscope and why the device orientation is given by accelerometer sensor.
I have test this code on 2 tablets, 3 phones and result are the same.
Listeners :
// gyroscope sensor
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_NORMAL);
// accelerometer sensor
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
And to get the result I implement SensorEventListener :
#Override
public void onSensorChanged(SensorEvent sensorEvent) {
switch (sensorEvent.sensor.getStringType()){
case Sensor.STRING_TYPE_ACCELEROMETER:
(TextView)findViewById(R.id.sensor_accel_data_textView)).setText(String.valueOf(sensorEvent.values[0]));
((TextView)findViewById(R.id.sensor_accel_data_textView2)).setText(String.valueOf(sensorEvent.values[1]));
((TextView)findViewById(R.id.sensor_accel_data_textView3)).setText(String.valueOf(sensorEvent.values[2]));
break;
case Sensor.STRING_TYPE_GYROSCOPE:
((TextView)findViewById(R.id.sensor_gyro_data_textView)).setText(String.valueOf(sensorEvent.values[0]));
((TextView)findViewById(R.id.sensor_gyro_data_textView2)).setText(String.valueOf(sensorEvent.values[1]));
((TextView)findViewById(R.id.sensor_gyro_data_textView3)).setText(String.valueOf(sensorEvent.values[2]));
break;
}
}
They are not inverted. Accelerometer gives you ax, ay, az which are accelerations in 3 directions. Gyroscope gives you gx, gy, gz which are rotation velocities around 3 directions.
Those two sensors can be used independently.
Accelerometer does not give you orientation. There is orientation sensor but it might be deprecated. I think sensor values are orientation dependent, but there are ways to make them orientation independent.
You can install some sensor app from play store and compare it with your values for testing purpose.
This question is almost a year old, but I just stumbled onto it and got the impression that the root of the question is a misunderstanding of what each sensor actually measures.
So, hopefully the following explanation clarifies a bit that the sensors are not switched, but that in fact accelerometers are used to detect orientation and that the (imho badly named) gyroscope does not provide an absolute orientation.
Accelerometer
You should imagine an accelerometer as a sample mass, which is held by some springs, because that is what an accelerometer is (you can search for MEMS accelerometer to find examples on how this is actually implemented on a micrometer scale). If you accelerate the device, the mass will push against the springs because of inertia and the tiny deflection of the mass is measured to detect the acceleration. However, the mass is not only deflected by an actual acceleration but also by gravitational pull. So, if your phone is resting on the table, the mass is still deflected towards the ground.
So, the "-10" to "10" you see is earth's acceleration at 9.81 m/s². From a physics perspective, this is confusing because the resting device is obviously not being accelerated while the sensor still shows 9.81 m/s², so we get the device acceleration plus earth's acceleration from the sensor. While this is the nightmare of any physics teacher, it is extremely helpful because it tells you where "down" is and hence gives you the orientation of the device (except for rotations around the axis of gravity).
Gyroscope
The sensor called "gyroscope" is another sample mass in your device, which is actively driven to vibrate. Because of the vibration movement it is subject to the Coriolis force (in its frame of reference) and gets deflected when rotating (searching for "MEMS gyroscope" yields even more astonishing devices, especially if you think about the fact that they can detect the Coriolis force on that scale).
However, the deflection does not allow you to determine an absolute angle (as an old-fashioned gyroscope would), but instead it is proportional to the angular velocity (rate of rotation). Therefore, you can expect a reading of zero on all axes for a resting device and will only see a reading for any axis as long as you are rotating the device about this axis.
Gyroscope vs Accelerometer:
Acceleromter measures how fast object is moving along axis. How fast it moves within X and Y and Z.
Gyroscope measures how fast object is rotating around axis. How was it rotates around X and Y and Z.
At the beginnig, your X or Y or Z will have Earth acceleration value measured in meter divided squared second, which is 9.81 m/s^2
I want to get the acceleration of three direction(North,South,Sky) with the data from TYPE_ACCELEROMETER and TYPE_ORIENTATION(or Compass). What should I do to calculate?
You can not get acceleration in World coordinate with TYPE_ACCELEROMETER and TYPE_ORIENTATION. You need TYPE_ACCELEROMETER and one of TYPE_GRAVITY or TYPE_MAGNETIC_FIELD or TYPE_ROTATION_VECTOR. I am pretty sure that the depreciated TYPE_ORIENTATION also use one of the three above.
Accoprding to this: http://developer.android.com/guide/topics/sensors/sensors_motion.html
In modern Android devices you can measure 1) acceleration (including gravity), 2) linear acceleration (excluding gravity), 3) gravitational acceleration, all along the X,Y,Z axes.
Is the linear acceleration reading simply the accelerometer reading - gravity reading? Or differently put, is the accelerometer equal to the linear acceleration + gravitational acceleration? I.e., there are 9 different data points being sensed, and I'm trying to figure out whether three are redundant.
As far as I remember, there is a single hardware sensor for acceleration (apart from gyroscope, which measures angular acceleration).
Gravity is a "fake" sensor, which value is extracted from the raw acceleration by a low-pass filter.
Linear acceleration is, indeed, just the difference.
As #mstrthealias pointed out, even if this is redundant, it might be more efficient to directly get the linear acceleration rather than compute the difference in Java, but I'm just speculating here.
What is the difference between gravity and acceleration sensors in Android? From my point of view the physical value is the same in both cases.
Which one measures the force acting on unit mass inside the device?
ADDITION
The question is: what physical quantity is measured by these sensors? According to equivalence principle the acceleration and gravity are indistinguishable and the only way to measure both is by usual (but 3d) spring balance.
Acceleration sensor gives you back the sum of all forces applied to your device, while Gravity sensor returns only the influence of gravity. If you want to exclude the gravity from acceleration, you may use a high-pass filter or just subtract the gravity sensor values from acceleration sensor values -- not sure which method gives better precision.
Another method could be using Sensor.TYPE_LINEAR_ACCELERATION, which gives exactly (acceleration - gravity), however you should check if it's available on the device. I've found a few devices, which have ACCELERATION sensor working, but no response from GRAVITY or LINEAR_ACCELERATION sensors.
This link might be helpful: http://www.sensorplatforms.com/which-sensors-in-android-gets-direct-input-what-are-virtual-sensors
The following excerpt summarize the answer for your question:
"The list... includes both physical sensors and sensor types with values derived from physical sensors, sometimes these are called virtual sensors... The virtual sensors types (gravity, linear acceleration, and rotation vector) provide values derived by combining the results from physical sensors intelligently... The rotation vector is a combination of the accelerometer, the magnetometer, and sometimes the gyroscope to determine the three-dimensional angle along which the Android device lays with respect to the Earth frame coordinates. By knowing the rotation vector of a device, accelerometer data can be separated into gravity and linear acceleration."
This link https://stackoverflow.com/a/8238389/604964 also says that the gravity values are computed using a Butterworth filter.
I want to know about the values of X,Y and Z axis for any position/movement of device so I can use these values for my further work. As I searched there are two methods, Orientation Sensor(gives value in degree,as azimuth,pitch and roll) and Accelerometer(gives values between 1 to 10 for x,y and z).
As per my understanding both are same for my requirement. I can't find difference between them. Please can any one clear me about them in detail w.r.t my aim. which sensor should I use?
There are differences between both:
Accelerometer detects acceleration in space. The reason why it will always detect an acceleration of 9.8m/s^2 downwards is because gravity is equivalent to acceleration in space.
Orientation detects if your device's axis are rotated from the real-world; it detects tilts and and degrees from the magnetic North. Please note that this sensor is deprecated and Google recommends you use the accelerometer and magnetometer to calculate orientation.
You'll need the accelerometer to detect movement. So you should use this one, since your aim is to know this movement.
The orientation sensor gives information about its position compared to a reference plane. So you could use this to see of the device is tilted, upside down or something like that.