Android跌倒检测 [英] Android Fall detection

查看:27
本文介绍了Android跌倒检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用加速度计传感器实现跌倒检测,并创建以下代码.

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.

如果我从 6 英寸处扔出设备,则会显示警报.

if i throw device from 6 inch, alert shown.

我还看到灵敏度是特定于设备的.

I also see the sensitivity is device specific.

当我用相同的高度测试moto e和mi 4时

when i test moto e and mi 4 with same height

Moto e 为 loAccelerationReader

并且在 mi 4 中,它将为 loAccelerationReader

and in mi 4 it will return 60 value for loAccelerationReader

谁能帮我找到正确的方法.

can any one help me out for the correct way.

推荐答案

我得到了一些解决方案,不确定它是否适用于所有人,但我正在使用下面的代码并且它对我有用.

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
        }
   }

这篇关于Android跌倒检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆