sensor fusion - Measuring vertical movement of non-fixed Android device -
my goal make android mobile app (sdk16+) measures road quality while riding bike.
i have found sensor fusion demo android assume measurements me.
how can vertical movement when phone not fixed in orientation?
the problem
the problem here have 2 systems of coordinates, dx, dy, dz, of device , wx, wy, wz of world around you. relationship between 2 changes move device around.
another way formulate question say:
given sensor reading [dx, dy, dz], how find component of reading parallel wz?
a solution
luckily, orientation sensors (such android's own rotation_vector sensor) provide tools transformation between these 2 coordinate systems.
for example, output of rotation_vectorsensor comes in form of axis-angle representation of rotation device has "base" rotation fixed in world frame (see also: quaternions).
android provides method sensormanager#getrotationmatrixfromvector(float[] r, float[] rotationvector), takes axis-angle representation sensor , translates rotation matrix. rotation matrix used transform vector given in 1 frame of reference (in case [ world -> device ]).
now, want transform measurement in device frame world frame? no problem. 1 nifty characteristic of rotation matrices inverse of rotation matrix rotation matrix of opposite transformation ([device -> world] in our case). another, niftier thing inverse of rotation matrix it's transpose.
so, code follow lines of:
public void findverticalcomponentofsensorvalue() { float[] rotationvectoroutput = ... // latest value rotation_vector sensor float[] accelerometervalue = ... // latest value accelerometer sensor float[] rotationmatrix = new float[9]; // both 9 , 16 works, depending on you're doing sensormanager.getrotationmatrixfromvector(rotationmatrix, rotationvectoroutput); float[] accelerationinworldframe = matrixmult( matrixtranspose(rotationmatrix), accelerometervalue); // make own methods matrix operations or find existing library accelerationinworldframe[2] // vertical acceleration } now, i'm not saying best possible solution, should you're after.
disclaimer
strapping device uses sensor fusion including magnetometer metal frame may produce inconsistent results. since compass heading doesn't matter here, i'd suggest using sensor fusion method doesn't involve magnetometer.
Comments
Post a Comment