Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect walking with Android accelerometer

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;

        gravity[0] = (accelerometer_values[0] * kFilteringFactor) + (gravity[0] * (1.0f - kFilteringFactor));
        gravity[1] = (accelerometer_values[1] * kFilteringFactor) + (gravity[1] * (1.0f - kFilteringFactor));
        gravity[2] = (accelerometer_values[2] * kFilteringFactor) + (gravity[2] * (1.0f - kFilteringFactor));

        linear_acceleration[0] = (accelerometer_values[0] - gravity[0]);
        linear_acceleration[1] = (accelerometer_values[1] - gravity[1]);
        linear_acceleration[2] = (accelerometer_values[2] - gravity[2]);

        float magnitude = 0.0f;
        magnitude = (float)Math.sqrt(linear_acceleration[0]*linear_acceleration[0]+linear_acceleration[1]*linear_acceleration[1]+linear_acceleration[2]*linear_acceleration[2]);
        magnitude = Math.abs(magnitude);
if(magnitude>0.2)
  //walking

The array gravity[] is initialized with 0s.

I can detect when a user is walking or not (looking at the value of the magnitude of the acceleration vector), but my problem is that when a user is not walking and he moves the phones, it seems that he is walking.

Am I using the right filter?

Is it right to watch only the magnitude of the vector or have I to look at the single values ??

like image 947
havanakoda Avatar asked Feb 14 '11 15:02

havanakoda


People also ask

How do you detect walking?

Check whether the phone is "hidden", using proximity and light sensor (optional). This method is less accurate but easier. Controlling the continuity of the movement, if the phone is moving for more than... 10 seconds and the movement is not despicable, then you consider he is walking.

Which sensor is used to count steps in Android?

Use the step counter sensor The step counter sensor provides the number of steps taken by the user since the last reboot while the sensor was activated.

How accurate is the Android accelerometer?

The accelerometers read around -0.8 ms^-2 on both X and Y axes when stationary, so I used this as my offset.

What does accelerometer sensor detect in an app?

An accelerometer is an electronic sensor that measures the acceleration forces acting on an object, in order to determine the object's position in space and monitor the object's movement.


1 Answers

Google provides an API for this called DetectedActivity that can be obtained using the ActivityRecognitionApi. Those docs can be accessed here and here.

DetectedActivity has the method public int getType() to get the current activity of the user and also public int getConfidence() which returns a value from 0 to 100. The higher the value returned by getConfidence(), the more certain the API is that the user is performing the returned activity.

Here is a constant summary of what is returned by getType():

  • int IN_VEHICLE The device is in a vehicle, such as a car.
  • int ON_BICYCLE The device is on a bicycle.
  • int ON_FOOT The device is on a user who is walking or running.
  • int RUNNING The device is on a user who is running.
  • int STILL The device is still (not moving).
  • int TILTING The device angle relative to gravity changed significantly.
  • int UNKNOWN Unable to detect the current activity.
  • int WALKING The device is on a user who is walking.
like image 53
Dick Lucas Avatar answered Sep 29 '22 22:09

Dick Lucas