Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid sensor: getRotationMatrix() returns wrong values, why?
    primarykey
    data
    text
    <p>It's past several days since I started using this function and have not yet succeeded in obtaining valid results.</p> <p>What i want is <strong>basically convert acceleration vector from device's coordinates system, to real world coordinates</strong>. I' know that is possible because i have acceleration in relative coordinates and i know the orientation of the device in real world system.</p> <p><a href="http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix%28float%5B%5D,%20float%5B%5D,%20float%5B%5D,%20float%5B%5D%29" rel="nofollow noreferrer">Reading Android developers</a> seems that using getRotationMatrix() i get R = rotation matrix.</p> <p>So if i want A (acceleration vector in world system) from A' (acceleration vector in phone system) i must do simply:</p> <pre><code> A=R*A' </code></pre> <p>But i cant'n understand why the <strong>vector A has ALWAYS the first and the second component zero</strong> (example: +0,00;-0,00;+6,43)</p> <p>My current code is similar to this:</p> <pre><code> public void onSensorChanged(SensorEvent event) { synchronized (this) { switch(event.sensor.getType()){ case Sensor.TYPE_ACCELEROMETER: accelerometervalues = event.values.clone(); break; case Sensor.TYPE_MAGNETIC_FIELD: geomagneticmatrix =event.values.clone(); break; } if (geomagneticmatrix != null &amp;&amp; accelerometervalues != null) { float[] Rs = new float[16]; float[] I = new float[16]; SensorManager.getRotationMatrix(Rs, I, accelerometervalues, geomagneticmatrix); float resultVec[] = new float[4]; float relativacc[]=new float [4]; relativacc[0]=accelerationvalues[0]; relativacc[1]=accelerationvalues[1]; relativacc[2]=accelerationvalues[2]; relativacc[3]=0; Matrix.multiplyMV(resultVec, 0, Rs, 0, relativacc, 0); //resultVec[] is the vector acceleration relative to world coordinates system..but doesn't WORK!!!!! } } } </code></pre> <p>This question is very similar to this one <a href="https://stackoverflow.com/questions/5464847/transforming-accelerometers-data-from-devices-coordinates-to-real-world-coordi">Transforming accelerometer&#39;s data from device&#39;s coordinates to real world coordinates</a> but there i can't find the solution...i had tried all the ways..</p> <p>Please help me, i need help!!!</p> <p>UPDATE:</p> <p>Now my code is below, i had tried to explain matrix product, but nothing change:</p> <pre><code> float[] Rs = new float[9]; float[] I = new float[9]; SensorManager.getRotationMatrix(Rs, I, accelerationvalues, geomagneticmatrix); float resultVec[] = new float[4]; resultVec[0]=Rs[0]*accelerationvalues[0]+Rs[1]*accelerationvalues[1]+Rs[2]*accelerationvalues[2]; resultVec[1]=Rs[3]*accelerationvalues[0]+Rs[4]*accelerationvalues[1]+Rs[5]*accelerationvalues[2]; resultVec[2]=Rs[6]*accelerationvalues[0]+Rs[7]*accelerationvalues[1]+Rs[8]*accelerationvalues[2]; </code></pre> <p>Here some example of data read and result: </p> <pre><code>Rs separated by " " Rs[0] Rs[1]....Rs[8] Av separated by " " accelerationvalues[0] ...accelerationvalues[2] rV separated by " " resultVec[0] ...resultVec[2] </code></pre> <p><img src="https://i.stack.imgur.com/CVhdD.jpg" alt="Data from CAT manager"></p> <p>As you can notice the component on x and y axes in real world are zero (around) even if you move speddy the phone. Instead the relative acceleration vector detect correctly each movement!!!</p> <p><strong>SOLUTION</strong> The errors in the numberrs are relative to float vars multiplication that is not the same as a double multyplication. This sums to the fact that <strong>rotation matrix isn't costant if the phone</strong>, even if with the same orientation, <strong>is accelerating.</strong> So is impossible translate acceleration vector to absolute coordinates during motion... It's hard but it's the reality.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload