ios - Normalizing mobile accelerometer X/Y/Z to earth co-ordinates in Javascript not working -


i using gryonorm log accelerometer , device orientation. goal ensure able acceleration in x/y/z (not combined, don't want sqrt (x^2 + y^2 + z^2) irrespective of how phone kept. use-case track sensor data while in car (to detect bad driving patterns)

i referred this thread (and this thread) , think i'm doing right, is,

  • get acc data,
  • get orientation,
  • get rotationmatrix & invert it,
  • multiply acc. data inverted rotation matrix earth acc.data

however, results not independent of phone orientation.

my device: iphone 7, ios 10.3.3

first code:

import {mat3} 'gl-matrix';  let gyronormargs = {     gravitynormalized:false, // tried true     orientationbase:gyronorm.world, // tried .game     frequency:1000,     screenadjusted:false,   } 

inside callback when acc. data , orientation data (gdata):

   let alpha = gdata.dm.alpha;    let beta = gdata.dm.beta;    let gamma = gdata.dm.gamma;    let rotatematrix = this.getrotationmatrix(alpha, beta, gamma);    let relativeacc = new array(3);    let earthacc = new array(3);    let inv = new array(9)    relativeacc[0] = gdata.dm.gx;    relativeacc[1] = gdata.dm.gy;    relativeacc[2] = gdata.dm.gy;    mat3.invert(inv,rotatematrix);    mat3.multiply(earthacc, inv, relativeacc);    let accearthx = earthacc[0];    let accearthy = earthacc[1];    let accearthz = earthacc[2];    console.log (`---raw data --- ` + json.stringify(gdata));    console.log (`*** earth data x=${accearthx}, y=${accearthy} z=${accearthz}`) 

the rotation matrix:

// credit:https://stackoverflow.com/a/36662093/1361529 getrotationmatrix(alpha, beta, gamma) {      let out = [];     let  _z = alpha;     let _x = beta;     let _y = gamma;      let cx = math.cos( _x );     let cy = math.cos( _y );     let cz = math.cos( _z );     let sx = math.sin( _x );     let sy = math.sin( _y );     let sz = math.sin( _z );      out[0] = cz * cy + sz * sx * sy,    // row 1, col 1     out[1] = cx * sz,                   // row 2, col 1     out[2] = - cz * sy + sz * sx * cy , // row 3, col 1      out[3] = - cy * sz + cz * sx * sy,  // row 1, col 2     out[4] = cz * cx,                   // row 2, col 2     out[5] = sz * sy + cz * cy * sx,    // row 3, col 2      out[6] = cx * sy,                   // row 1, col 3     out[7] = - sx,                      // row 2, col 3     out[8] = cx * cy                    // row 3, col 3    return out   }; 

and here output (phone face up, on table, testing in house):

2017-09-10 19:48:34.458837-0400 tripdata[6642:2247482] ---raw data --- {"do":{"alpha":242.09,"beta":0.4,"gamma":-0.8,"absolute":false},"dm":{"x":0,"y":0,"z":0.13,"gx":-0.13,"gy":-0.07,"gz":-9.67,"alpha":0.02,"beta":0.05,"gamma":0}} 2017-09-10 19:48:34.458906-0400 tripdata[6642:2247482] *** earth data x=-0.13144212418873122, y=-0.07079655168384706 z=-0.06641397637870017 2017-09-10 19:48:35.461572-0400 tripdata[6642:2247482] ---raw data --- {"do":{"alpha":242.1,"beta":0.4,"gamma":-0.8,"absolute":false},"dm":{"x":0,"y":0,"z":0.12,"gx":-0.13,"gy":-0.07,"gz":-9.69,"alpha":0.02,"beta":-0.07,"gamma":-0.06}} 2017-09-10 19:48:35.461715-0400 tripdata[6642:2247482] *** earth data x=-0.13524640367025567, y=-0.06279441851157147 z=-0.06682268550466884 

and here output (phone face down, on table, testing in house):

2017-09-10 19:49:32.592124-0400 tripdata[6642:2247482] ---raw data --- {"do":{"alpha":65.79,"beta":179.79,"gamma":-1,"absolute":false},"dm":{"x":0,"y":0.01,"z":0.1,"gx":-0.04,"gy":-0.16,"gz":9.9,"alpha":0.06,"beta":0.06,"gamma":-0.01}} 2017-09-10 19:49:32.592262-0400 tripdata[6642:2247482] *** earth data x=-0.05167393815904252, y=-0.16648286542066582 z=-0.14971058625381142 2017-09-10 19:49:33.598502-0400 tripdata[6642:2247482] ---raw data --- {"do":{"alpha":65.8,"beta":179.79,"gamma":-1,"absolute":false},"dm":{"x":-0.01,"y":0,"z":0.09,"gx":-0.05,"gy":-0.17,"gz":9.9,"alpha":-0.01,"beta":-0.06,"gamma":0.11}} 2017-09-10 19:49:33.598629-0400 tripdata[6642:2247482] *** earth data x=-0.02944164169071515, y=-0.1595350723662996 z=-0.18434139638083227 2017-09-10 19:49:34.594939-0400 tripdata[6642:2247482] ---raw data --- {"do":{"alpha":65.8,"beta":179.79,"gamma":-1,"absolute":false},"dm":{"x":-0.01,"y":0,"z":0.11,"gx":-0.04,"gy":-0.17,"gz":9.91,"alpha":-0.07,"beta":-0.06,"gamma":0.05}} 2017-09-10 19:49:34.595080-0400 tripdata[6642:2247482] *** earth data x=-0.020228116574781345, y=-0.16120266970200792 z=-0.18167146881330154 

and here output (phone face up, perpendicular table, testing in house):

2017-09-10 19:50:52.147809-0400 tripdata[6642:2247482] ---raw data --- {"do":{"alpha":221.25,"beta":83.19,"gamma":5.78,"absolute":false},"dm":{"x":-0.02,"y":0.02,"z":-0.04,"gx":0.1,"gy":-9.71,"gz":-1.19,"alpha":1.33,"beta":0.21,"gamma":-0.25}} 2017-09-10 19:50:52.147943-0400 tripdata[6642:2247482] *** earth data x=-11.682112584452096, y=-0.49477805209007863 z=-7.201502637877455 2017-09-10 19:50:53.147058-0400 tripdata[6642:2247482] ---raw data --- {"do":{"alpha":221.15,"beta":83.36,"gamma":5.9,"absolute":false},"dm":{"x":-0.03,"y":0.03,"z":0.02,"gx":0.09,"gy":-9.72,"gz":-1.11,"alpha":-0.69,"beta":0.39,"gamma":-0.11}} 2017-09-10 19:50:53.147192-0400 tripdata[6642:2247482] *** earth data x=7.309035050034833, y=-10.39162106453064 z=-5.249487431032232 2017-09-10 19:50:54.147017-0400 tripdata[6642:2247482] ---raw data --- {"do":{"alpha":221.87,"beta":83.48,"gamma":5.16,"absolute":false},"dm":{"x":0,"y":0.04,"z":-0.01,"gx":0.1,"gy":-9.7,"gz":-1.12,"alpha":0.47,"beta":-1.02,"gamma":0.42}} 2017-09-10 19:50:54.147151-0400 tripdata[6642:2247482] *** earth data x=4.71089937390668, y=0.3389442491438679 z=-12.879539738860931 2017-09-10 19:50:55.147900-0400 tripdata[6642:2247482] ---raw data --- {"do":{"alpha":221.78,"beta":83.58,"gamma":5.25,"absolute":false},"dm":{"x":-0.02,"y":0.01,"z":-0.01,"gx":0.08,"gy":-9.73,"gz":-1.1,"alpha":-1.12,"beta":0.39,"gamma":-0.29}} 2017-09-10 19:50:55.148033-0400 tripdata[6642:2247482] *** earth data x=10.120001205152024, y=-7.904409539460901 z=-4.945511645947363 2017-09-10 19:50:56.177822-0400 tripdata[6642:2247482] ---raw data --- {"do":{"alpha":231.77,"beta":83.98,"gamma":-2.92,"absolute":false},"dm":{"x":-0.02,"y":0.18,"z":0.11,"gx":-0.08,"gy":-9.58,"gz":-0.92,"alpha":-9.31,"beta":0.07,"gamma":0.38}} 

as see above, readings dependent on orientation , angle. missing? thank you.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -