Android SensorManager-Gyroskop zu absoluter Lage

  • Antworten:1
bruce
  • Forum-Beiträge: 3

10.09.2013, 21:41:31 via Website

Guten Abend,

Ich hab ein Problem.
Ich will das Gyroskop verwenden zur Bestimmung der aktuelle Ausrichtung meines Smartphones.
Da ich Störquellen habe (Elektromotoren usw) kann ich NICHT das Magnetfeld verwenden. Dementsprechend muss ich mich alleinig auf das Gyro und evtl Accel. verlassen. Es geht mir dabei nur um die Lage der Drehung um die Z-Achse (So wie die Z-Achse von Android beschrieben ist, das Handy liegt flach aufm Tisch und ich dreh es wie nen Kreisel).

Ich hab schon einiges durchgeschaut, doch zum teil versteh ich es einfach nicht ich verwende aktuell diesen Code wie er bei
...developer.android.com/guide/topics/sensors/sensors_motion.html#sensors-motion-gyro (darf keine links benutzen)
beschrieben ist.

1// Create a constant to convert nanoseconds to seconds.
2private static final float NS2S = 1.0f / 1000000000.0f;
3private final float[] deltaRotationVector = new float[4]();
4private float timestamp;
5
6public void onSensorChanged(SensorEvent event) {
7 // This timestep's delta rotation to be multiplied by the current rotation
8 // after computing it from the gyro sample data.
9 if (timestamp != 0) {
10 final float dT = (event.timestamp - timestamp) * NS2S;
11 // Axis of the rotation sample, not normalized yet.
12 float axisX = event.values[0];
13 float axisY = event.values[1];
14 float axisZ = event.values[2];
15
16 // Calculate the angular speed of the sample
17 float omegaMagnitude = sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);
18
19 // Normalize the rotation vector if it's big enough to get the axis
20 // (that is, EPSILON should represent your maximum allowable margin of error)
21 if (omegaMagnitude > EPSILON) {
22 axisX /= omegaMagnitude;
23 axisY /= omegaMagnitude;
24 axisZ /= omegaMagnitude;
25 }
26
27 // Integrate around this axis with the angular speed by the timestep
28 // in order to get a delta rotation from this sample over the timestep
29 // We will convert this axis-angle representation of the delta rotation
30 // into a quaternion before turning it into the rotation matrix.
31 float thetaOverTwo = omegaMagnitude * dT / 2.0f;
32 float sinThetaOverTwo = sin(thetaOverTwo);
33 float cosThetaOverTwo = cos(thetaOverTwo);
34 deltaRotationVector[0] = sinThetaOverTwo * axisX;
35 deltaRotationVector[1] = sinThetaOverTwo * axisY;
36 deltaRotationVector[2] = sinThetaOverTwo * axisZ;
37 deltaRotationVector[3] = cosThetaOverTwo;
38 }
39 timestamp = event.timestamp;
40 float[] deltaRotationMatrix = new float[9];
41 SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector);
42 // User code should concatenate the delta rotation we computed with the current rotation
43 // in order to get the updated rotation.
44 // rotationCurrent = rotationCurrent * deltaRotationMatrix;
45 }
46}

Zum größten teil verstehe ich was geschieht, nur leider hab ich keine Ahnung wie ich am Schluss, auf meine Grad komme.
Ich hätte gern das wenn das handy bei 0 Grad ist, ich es um 180 Grad nach links drehe und nachher um 180 Grad nach rechts drehe, es wieder bei 0 steht.
Genau genommen weiß ich nicht woher ich überhaupt die aktuelle Position bekommen, ich weiß das ich rad/s zurück bekomme und wandle es auf Grad, doch was genau fange ich mit der deltaRotationMatrix an, wie bekomme ich mit ihr meine Position. Besonders verwirrend finde ich die letzte Zeile "rotationCurrent = rotationCurrent * deltaRotationMatrix"???
rotationCurrent ist genau das was ich suche doch woher nehmen?
Zudem brauch ich doch für eine Achse nicht die ganze Matrizen-Rechnerei.
Kann mir jemand helfen und erklären wie ich da jetzt am besten drauf komm?
vielen Dank im Voraus,
Gruß Bruce

— geändert am 10.09.2013, 22:10:30

Antworten
Andy N.
  • Forum-Beiträge: 22.375

10.09.2013, 21:51:35 via App

Hallo,

bitte bearbeite doch nochmal etwas deinen Threadtitel, damit andere User besser erkennen können, worum es hier geht. Hierfür einfach unter deinem ersten Beitrag auf "Bearbeiten" drücken, dann kannst du oben noch mal den Titel bearbeiten.

Viele Grüße,
Andy


OnePlus 3 (Resurrection Remix 5.8.2)
LG G Watch

Regeln | unsere Mods & Admins

Antworten