0

I am Currently working on pedometer Application for intel device with LSM9DS0 sensor. My requirement is to develop a pedometer with the application code intel published in the Native Application Guide

This code is available in the section 6.1.4 of below shared pdf

http://download.intel.com/support/edison/sb/edison_nag_331192003.pdf

As a matter of fact I found some similar code but android version

public StepDetector() {
    int h = 480; // TODO: remove this constant
    mYOffset = h * 0.5f;
    mScale[0] = - (h * 0.5f * (1.0f / (SensorManager.STANDARD_GRAVITY * 2)));
    mScale[1] = - (h * 0.5f * (1.0f / (SensorManager.MAGNETIC_FIELD_EARTH_MAX)));
}

public void setSensitivity(float sensitivity) {
    mLimit = sensitivity; // 1.97  2.96  4.44  6.66  10.00  15.00  22.50  33.75  50.62
}

public void addStepListener(StepListener sl) {
    mStepListeners.add(sl);
}

//public void onSensorChanged(int sensor, float[] values) {
public void onSensorChanged(SensorEvent event) {
    Sensor sensor = event.sensor; 
    synchronized (this) {
        if (sensor.getType() == Sensor.TYPE_ORIENTATION) {
        }
        else {
            int j = (sensor.getType() == Sensor.TYPE_ACCELEROMETER) ? 1 : 0;
            if (j == 1) {
                float vSum = 0;
                for (int i=0 ; i<3 ; i++) {
                    final float v = mYOffset + event.values[i] * mScale[j];
                    vSum += v;
                }
                int k = 0;
                float v = vSum / 3;

                float direction = (v > mLastValues[k] ? 1 : (v < mLastValues[k] ? -1 : 0));
                if (direction == - mLastDirections[k]) {
                    // Direction changed
                    int extType = (direction > 0 ? 0 : 1); // minumum or maximum?
                    mLastExtremes[extType][k] = mLastValues[k];
                    float diff = Math.abs(mLastExtremes[extType][k] - mLastExtremes[1 - extType][k]);

                    if (diff > mLimit) {

                        boolean isAlmostAsLargeAsPrevious = diff > (mLastDiff[k]*2/3);
                        boolean isPreviousLargeEnough = mLastDiff[k] > (diff/3);
                        boolean isNotContra = (mLastMatch != 1 - extType);

                        if (isAlmostAsLargeAsPrevious && isPreviousLargeEnough && isNotContra) {
                            Log.i(TAG, "step");
                            for (StepListener stepListener : mStepListeners) {
                                stepListener.onStep();
                            }
                            mLastMatch = extType;
                        }
                        else {
                            mLastMatch = -1;
                        }
                    }
                    mLastDiff[k] = diff;
                }
                mLastDirections[k] = direction;
                mLastValues[k] = v;
            }
        }
    }
}

Complete android source code available in Github

https://github.com/bagilevi/android-pedometer

My problem is that I am not able to make perfect design document using these codes. I need clarifications on

  1. How does Scale values are calculated? its look like a random constant from nowhere is used here

    int h = 480; // TODO: remove this constant
    mScale[0] = - (h * 0.5f * (1.0f / (SensorManager.STANDARD_GRAVITY * 2)));
    mScale[1] = - (h * 0.5f * (1.0f / (SensorManager.MAGNETIC_FIELD_EARTH_MAX)));
    
  2. How does these mLimit value calculated?

    if (diff > mLimit)

  3. Intel code saying

    v = vSum / 2300;

    ButAndroid code saying

    v = vSum / 3;

  4. The Calculation of vector Sum is similar in both the codes. Which equation actually followed here?

Please some one help me to get these things straight

4

1 回答 1

0

I found out that the mechanism is just trial and run algorithm

These constant values may subject to change based on the environment, device, device packing, sensitivity of the accelerometer etc.

于 2015-09-16T05:18:33.060 回答