Ich habe versucht, Höhe zu berechnen, von der Gerät mit Beschleunigungssensor fällt, aber kein Glück.Android: Wie berechnet man die Höhe, von der Gerät mit Beschleunigungssensor herunterfällt?
konnte ich das Gerät fallen zu erkennen.
Bitte teilen Gedanken oder Workaround für die Frage, wenn einer von Ihnen das gleiche versucht.
Unten ist Code, den ich versuchte.
‚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();
}
}
}'
Vielen Dank im Voraus.
Bitte geben Sie an, was Sie bereits versucht haben, und skizzieren Sie, was nicht wie gewünscht funktioniert. – dharms
@dharms, ich habe den Code hinzugefügt, bitte helfen Sie mir, wenn Sie wissen. – Pampapathi