Android Fall detection

蹲街弑〆低调 提交于 2019-12-31 02:09:12

问题


I am implementing the fall detection using accelerometer sensor, and create below code.

  public void onSensorChanged(SensorEvent foEvent) {


        if (foEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            double loX = foEvent.values[0];
            double loY = foEvent.values[1];
            double loZ = foEvent.values[2];

            double loAccelerationReader = Math.sqrt(Math.pow(loX, 2)
                    + Math.pow(loY, 2)
                    + Math.pow(loZ, 2));
            mlPreviousTime = System.currentTimeMillis();
            Log.i(TAG, "loX : " + loX + " loY : " + loY + " loZ : " + loZ);
            if (loAccelerationReader <= 6.0) {
                moIsMin = true;
                Log.i(TAG, "min");
            }

            if (moIsMin) {
                i++;
                Log.i(TAG, " loAcceleration : " + loAccelerationReader);
                if (loAccelerationReader >= 30) {
                    long llCurrentTime = System.currentTimeMillis();
                    long llTimeDiff = llCurrentTime - mlPreviousTime;
                    Log.i(TAG, "loTime :" + llTimeDiff);
                    if (llTimeDiff >= 10) {
                        moIsMax = true;
                        Log.i(TAG, "max");
                    }
                }

            }

            if (moIsMin && moIsMax) {
                Log.i(TAG, "loX : " + loX + " loY : " + loY + " loZ : " + loZ);
                Log.i(TAG, "FALL DETECTED!!!!!");
                Toast.makeText(this, "FALL DETECTED!!!!!", Toast.LENGTH_LONG).show();
                i = 0;
                moIsMin = false;
                moIsMax = false;
            }

            if (i > 5) {
                i = 0;
                moIsMin = false;
                moIsMax = false;
            }
        }        
}

its give me fall detected, but if i am riding or running it will also give me fall alert.

if i throw device from 6 inch, alert shown.

I also see the sensitivity is device specific.

when i test moto e and mi 4 with same height

Moto e return maximum 32 value for loAccelerationReader

and in mi 4 it will return 60 value for loAccelerationReader

can any one help me out for the correct way.


回答1:


I got some solution not sure its work for all or not, but i am using below code and its working for me.

if (foEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {

        double loX = foEvent.values[0];
        double loY = foEvent.values[1];
        double loZ = foEvent.values[2];

        double loAccelerationReader = Math.sqrt(Math.pow(loX, 2)
                + Math.pow(loY, 2)
                + Math.pow(loZ, 2));

        DecimalFormat precision = new DecimalFormat("0.00");
        double ldAccRound = Double.parseDouble(precision.format(loAccelerationReader));

        if (ldAccRound > 0.3d && ldAccRound < 0.5d) {
           //Do your stuff
        }
   }



回答2:


You are on the right track. It can detect fall! But it also detect other non-fall events. My suggestion is instead of single point thresholding (e.g. magnitude > 30), get a time interval of accelerometer readings (e.g. 1 second). I am sure that that the readings for fall, running, and driving will be very different statistically (e.g. mean, variance). I hope this can serve as a starting point for your next iteration of detection algorithm.

It is very likely that the readings will be different from machine to machine since the accelerometers they use are different and may have different sensitivity.



来源:https://stackoverflow.com/questions/44518729/android-fall-detection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!