Android acceleration direction -
after searching while did not find way isolate translation acceleration direction rotation.
im looking yo find way acceleration direction independently of how mobile phone rotated (and of course independently of how rotated).
basically allow me make difference among acceleration, deceleration , change of direction.
i tried compensate acceleration sensor angles ones obtained getorientation experimented getorientation angles (azimut, pitch, , roll) not same when device has translation movement (acceleration).
i need 1 of both: acceleration direction no matter how device rotating or orientation values no matter how device being accelerated.
is possible?
finally found it!
after android documentation can rotation matrix (getrotationmatrix) change coordinates system of mobile: rotation matrix r transforms vector device coordinate system world's coordinate system.
but in parameters documentation says (and here quiz):
gravity -is array of 3 floats containing gravity vector expressed in device's coordinate. can use values returned sensorevent of sensor of type type_accelerometer.
well if use documentation says accelerometer values paremeter on rotation matrix, of course acceleration afected while mobile translation , matrix useless.
instead of using accelerometer sensor values have use gravity sensor values (sensor of type type_gravity
as sensor not affected mobile translation rotation matrix can used while mobile being translated.
at end code works be:
float[] trueacceleration = new float[4]; float[] r = new float[16]; float[] rinv = new float[16]; sensormanager.getrotationmatrix(r, i, gravity, geomagnetic); matrix.invertm(rinv, 0, r, 0); matrix.multiplymv(trueacceleration, 0, rinv, 0, linearacceleration, 0); where
- gravity vector values type_gravity sensor,
- geomangetic vector values type_magnetic_field sensor, and
- linearacceleration vector values type_linear_acceleration sensor
then in trueacceleration vector have acceleration in mobile translation, no matter how mobile moves orientation.
Comments
Post a Comment