我尝试使用加速计传感器计算设备掉落的高度,但没有成功。
我能够检测到设备跌落。
如果你们中有人尝试过同样的问题,请分享想法或解决方法。
下面是我尝试过的代码。
'private void handleSensorChanged(SensorEvent event) { if (event.sensor.getType()==Sensor.TYPE_ACCELEROMETER) {
double gvt=SensorManager.STANDARD_GRAVITY;
//int sensor=event.sensor.getType();
double xx=event.values[0];
double yy=event.values[1];
double zz=event.values[2];
double aaa=Math.round(Math.sqrt(Math.pow(xx, 2)
+Math.pow(yy, 2)
+Math.pow(zz, 2)));
if (aaa<=6.0) {
min=true;
mintime=System.currentTimeMillis();
minXx = zz;
Log.d(TAG,"Min: xx, yy, zz = "+xx+", "+yy+", "+zz);
}
if (min==true) {
acc+=aaa;
count++;
i++;
if(aaa>=13.5) {
max=true;
maxtime = System.currentTimeMillis();
maxXx = zz;
Log.d(TAG,"Max: xx, yy, zz = "+xx+", "+yy+", "+zz);
}
}
if (min==true && max==true) {
double time = (maxtime - mintime);
//double distance = (minXx-maxXx)* Math.pow(time,2)/1000;
double maxVelocity = (aaa/count)*time;
double avgVelocity = maxVelocity/2;
double distance = (avgVelocity * time)/1000;
String msg = "FALL DETECTED!!!!! Duration = "+time + " milli secs, distance = "+ distance +" cms mtrs";
Toast.makeText(this, msg,Toast.LENGTH_LONG).show();
Log.d(TAG, msg);
v.vibrate(75);
resetValues();
}
if (i>4) {
resetValues();
}
}
}'
提前致谢。
最佳答案
加速度计为您提供速度的变化。这可能包括秋天结束时的突然停止。有一些技术可以使用此类数据来计算遍历。这是一些阅读 Material :
https://en.wikipedia.org/wiki/Dead_reckoning https://en.wikipedia.org/wiki/Inertial_navigation_system
但是,为解释基本手势而设计的消费级设备不会准确,并且您会出现误报和漏报,因为很难将此类 Action 与设备上可能发生的其他事情区分开来。因此,请管理好您的期望。
关于java - Android:如何使用加速度计计算设备掉落的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37182509/