Detect Movement Accurately using Accelerometer in Android

后端 未结 3 2086
小蘑菇
小蘑菇 2021-02-03 13:10

I am implementing a demo TIMER, with Vibration ( at a particular condition ), When I press start my timer starts running.. and when I stop it using stop button, it simply stops.

3条回答
  •  你的背包
    2021-02-03 13:24

    To find linear acceleration in a particular direction you can use this code too:

        @Override
    public void onSensorChanged(SensorEvent event) {
    // alpha is calculated as t / (t + dT)
    // with t, the low-pass filter's time-constant
    // and dT, the event delivery rate
    
    final float alpha = 0.8f;
    
    gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
    gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
    gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
    
    linear_acceleration[0] = event.values[0] - gravity[0];
    linear_acceleration[1] = event.values[1] - gravity[1];
    linear_acceleration[2] = event.values[2] - gravity[2];
    }  
    

    after calculating the linear acceleration you can simply use an 'if' statement to check whether you jerk was powerful or not! [Higher value= more powerful jerk]

提交回复
热议问题