i need to count no of steps while walking. so that i am using accelerometer. in the above coding i get accelerometer sensor's x,y,z values. this is i have done so far. my problems is by the x,y,z how to count steps while walking? i get the following code from the link
http://pedometer.googlecode.com/svn/trunk/src/name/bagi/levente/pedometer/Pedometer.java
my code:
import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.widget.TextView; import android.widget.Toast; public class Accelerometer extends Activity implements AccelerometerListener { private static Context CONTEXT; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); CONTEXT = this; } protected void onResume() { super.onResume(); if (AccelerometerManager.isSupported()) { AccelerometerManager.startListening(this); } } protected void onDestroy() { super.onDestroy(); if (AccelerometerManager.isListening()) { AccelerometerManager.stopListening(); } } public static Context getContext() { return CONTEXT; } /** * onShake callback */ public void onShake(float force) { Toast.makeText(this, "Phone shaked : " + force, 1000).show(); } /** * onAccelerationChanged callback */ public void onAccelerationChanged(float x, float y, float z) { ((TextView) findViewById(R.id.x)).setText(String.valueOf(x)); ((TextView) findViewById(R.id.y)).setText(String.valueOf(y)); ((TextView) findViewById(R.id.z)).setText(String.valueOf(z)); } }
please help me.
The accelerometer cannot measure exertion, such as weight lifting. It detects daily movement and calibrates for steps, but it can't convert steps from cycling, yoga, or any sitting physical activities.
We are going to count steps by using the accelerometer to count bounces up and down. Because the phone can rotate in any direction, we will use gravity to know which direction down is. A pedometer can count steps by counting the number of bounces in the direction of gravity.
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.
You will not find here a simple code to just count steps (it is just too complex). But there's info out there if you're interested:
There are good diagrams and step analyses here (in pdf).
You can find a more formal publication here: http://portal.acm.org/citation.cfm?id=1554235
And if you want to create a sensitive pedometer (proposed for the elderly), I suggest you to start from this paper: http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=4575030
You can estimate the gravity force on the phone using the x,y,z values...
float g = (x * x + y * y + z * z) / (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH);
...here a value of 1 = normal (1g is normal)
The a crude pedometer can be built fairly easily by just counting how many peaks above a specified g value over a given sample period (eg 6 seconds and multiple by 10 for paces per minute)
Say for example record the time in ms that a g of >2 is recorded... then the peak will continue going up.... and come back down below 2.. probably to 0.5 or something.. then it'll go up again >2... at this point stop the clock.
...then you have a complete cycle timed!
To stabilise the result it's better to count a few cycles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With