我目前正在尝试在android上编写一个跌倒检测算法。我已成功检测到自由落体,但是当手机着陆时,结果向量总是大约1G,我无法创建上限阈值。这是我的方法代码:
if (mySensor.getType() == Sensor.TYPE_ACCELEROMETER) {
float x = sensorEvent.values[0];
float y = sensorEvent.values[1];
float z = sensorEvent.values[2];
double totalAccel = Math.sqrt(Math.pow(x,2) + Math.pow(y,2) + Math.pow(z,2));
if(totalAccel < FALL_THRESHOLD && !isFalling){
isFalling = true;
}
if(isFalling && totalAccel > FALL_THRESHOLD){
isFalling = false;
TextView view = (TextView) findViewById(R.id.values);
view.setText("" + totalAccel);
}