dorukeker / gyronorm.js

JavaScript project for accessing and normalizing the accelerometer and gyroscope data on mobile devices
MIT License
641 stars 65 forks source link

Acceleration is not consistent between iOS and Android #54

Closed zcfan closed 6 years ago

zcfan commented 6 years ago

I found iOS and Android acceleration value has different sign, and it seems gravityNormalized option only correct accelerationWithGravity(gm.gx/gm.gy/gm.gz) but not acceleration(gm.x/gm.y/gm.z).

I made a plot for this situation to clarify my idea:

img_175f121d5bfc-1

Those two green box shows that the gm.y and gm.z in iOS and Android are negative to each other.

Change line 350 - 355 to following could give consistent value, but I'm not sure I understand this library completely. I would like to make this a PR if you this's a correct fix.

// Normalize gravity
if (_gravityNormalized) {
  snapShot.dm.gx *= _gravityCoefficient;
  snapShot.dm.gy *= _gravityCoefficient;
  snapShot.dm.gz *= _gravityCoefficient;
}
// Change above to:
if (_gravityNormalized) {
  snapShot.dm.gx *= _gravityCoefficient;
  snapShot.dm.gy *= _gravityCoefficient;
  snapShot.dm.gz *= _gravityCoefficient;
  snapShot.dm.x *= _gravityCoefficient;
  snapShot.dm.y *= _gravityCoefficient;
  snapShot.dm.z *= _gravityCoefficient;
}
dorukeker commented 6 years ago

Yep! you are correct please make the PR and I will merge. Thanks! D.

zcfan commented 6 years ago

@dorukeker Actually I found that gravityNormalized option can't be set by user at all, it's always true. Will make a PR later 😂

dorukeker commented 6 years ago

Thanks! I merged the PRs