How to detect walking with Android accelerometer

前端 未结 5 1406
悲&欢浪女
悲&欢浪女 2020-12-13 04:53

I\'m writing an application and my aim is to detect when a user is walking. I\'m using a Kalman filter like this:

float kFilteringFactor=0.6f;

        gravi         


        
5条回答
  •  孤街浪徒
    2020-12-13 05:42

    For walking detection I use the derivative applied to the smoothed signal from accelerometer. When the derivative is greater than threshold value I can suggest that it was a step. But I guess that it's not best practise, furthermore it only works when the phone is placed in a pants pocket.

    The following code was used in this app https://play.google.com/store/apps/details?id=com.tartakynov.robotnoise

        @Override
        public void onSensorChanged(SensorEvent event) {
            if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER){
                return;
            }
            final float z = smooth(event.values[2]); // scalar kalman filter                               
            if (Math.abs(z - mLastZ) > LEG_THRSHOLD_AMPLITUDE)
            {
                mInactivityCount = 0;
                int currentActivity = (z > mLastZ) ? LEG_MOVEMENT_FORWARD : LEG_MOVEMENT_BACKWARD;                  
                if (currentActivity != mLastActivity){
                    mLastActivity = currentActivity;
                    notifyListeners(currentActivity);
                }                   
            } else {
                if (mInactivityCount > LEG_THRSHOLD_INACTIVITY) {
                    if (mLastActivity != LEG_MOVEMENT_NONE){
                        mLastActivity = LEG_MOVEMENT_NONE;
                        notifyListeners(LEG_MOVEMENT_NONE);                                 
                    }
                } else {
                    mInactivityCount++;
                }
            }
            mLastZ = z;
        }
    

提交回复
热议问题