Android: Accelerometer false detection

前端 未结 2 1542
情歌与酒
情歌与酒 2021-02-01 11:47

I have a code snippet to detect accelerometer movements. It works some times by properly detecting slight movements, but sometimes it detects movements when I kept my device idl

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-01 11:50

    I personally, in my augmented reality library, use a rolling average for the updates:

    float kFilteringFactor = (float)0.05;    
    rollingZ = (float) ((rawZValue * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor)));
    

    This tends to smooth out the data pretty well, and you can tweak the filtering factor to get the responsiveness you want.

    rawZValue is the raw value coming in from the accelerometer.

提交回复
热议问题