Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate Foot step using Pedometer [closed]

Tags:

android

i develop application for calculation of calories burn by walking for that i use SensorEventListener (ACCELEROMETER) i get three value from that X,Y,Z. my question is how to calculate foot step using that three X,Y,Z. this is my code for getting X,Y,Z value. i use GPS also. but i required count step using Pedometer in Android guyzz PLZ help me.

package com.mxicoders.prashant;

import android.app.ActivityGroup;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Chronometer;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class MyWorkout extends ActivityGroup implements SensorEventListener {

    ImageButton btnfacebook, btnstartwalk, btnstopwalk;
    Chronometer mchoronometer;
    Intent getintent;
    String _getname, _getage, _gethight, _getwidth;
    TextView txtx, txty, txtz;
    private SensorManager sensorManager;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_workout);

        txtx = (TextView) findViewById(R.id.txtview_steps_myworkout);
        txty = (TextView) findViewById(R.id.txtview_distance_myworkout);
        txtz = (TextView) findViewById(R.id.txtview_calary_myworkout);
        btnfacebook = (ImageButton) findViewById(R.id.imgview_facebook_myworkout);

        btnfacebook.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent inn = new Intent(getParent(), MyworkoutFacbook.class);
                WorkoutTabGroupActivity parantActivity = (WorkoutTabGroupActivity) getParent();
                parantActivity.startChildActivity("MyworkoutFacbook", inn);

            }
        });
        btnstartwalk = (ImageButton) findViewById(R.id.imgbtn_start_myworkout);
        btnstartwalk.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

                sensorManager.registerListener(MyWorkout.this, sensorManager
                        .getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                        SensorManager.SENSOR_DELAY_NORMAL);
                Toast.makeText(getApplicationContext(), "Start",
                        Toast.LENGTH_LONG).show();


            }
        });

        btnstopwalk = (ImageButton) findViewById(R.id.imgbtn_stop_myworkout);
        btnstopwalk.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub


            }
        });

    }

    public void onAccuracyChanged(Sensor sensor, int accuracy) {
        // TODO Auto-generated method stub

    }

    public void onSensorChanged(SensorEvent event) {
        // TODO Auto-generated method stub
        if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            float x = event.values[0];
            float y = event.values[1];
            float z = event.values[2];
            txtx.setText("X: " + x);
            txty.setText("X: " + y);
            txtz.setText("X: " + z);
        }

    }
}
like image 417
Prashant09 Avatar asked Sep 18 '12 11:09

Prashant09


1 Answers

My suggestion is that you should track variations in Global Z axis (your body up/down movement). You cannot guarentee that the user will hold the mobile in a specific orientation, so you will have to rely on experimenting. Also, you may need to monitor the speed of movement (so as not to translate car movement to foot steps for e.g.).

What I would do is:

1- Create a text file on the Mobile and record the values of X, Y & Z (in addition to GPS speed) while I am walking, with the mobile in different orientations (in my pocket, in a belt pouch, ...etc). Also, keep track of the number of steps I performed.

2- Based on this data in step one, form a formula to convert this data to number of foot steps.

like image 112
Mohamed_AbdAllah Avatar answered Sep 22 '22 06:09

Mohamed_AbdAllah