So, möchte ich nochmal nachreichen, wie aktuell gerade aussieht,
1 | // Neutralwerte, ACCX & ACCY (Waagerecht auf dem Tisch)
|
2 | Neutralwert = 2121;
|
3 |
|
4 | accx = (float)((messwert_y - Neutralwert));
|
5 | accy = (float)((messwert_x - Neutralwert));
|
6 | accz = (float)((messwert_z - Neutralwert));
|
7 |
|
8 | totalforce = (float)(sqrt((accx * accx)
|
9 | + (accy * accy)
|
10 | + (accz * accz)));
|
11 | accx /= totalforce;
|
12 | accy /= totalforce;
|
13 | accz /= totalforce;
|
14 |
|
15 | tilt_x = atan2(accx, accz) * (180 / pi());
|
16 | tilt_y = atan2(accy, accz) * (180 / pi());
|
17 |
|
18 | printf("%d;%d\r", tilt_x, tilt_y);
|
ob totalforce funktioniert, weiß ich nicht genau, sieht mit
und ohne 1 zu 1 aus. Zumindest auf den Winkel gerundet, hmmm....
Interessant wäre es noch die Winkel zu normalisieren,
das heiß, Überschläge zuzulassen.
Wild gestöbert im Internet.... und das hier gefunden,
aus einem etwas anderen Zusammenhang
1 | // Normalize values:
|
2 |
|
3 | // Restrict pitch value to -90 to +90
|
4 | if (tilt_x < -90) {
|
5 | tilt_x = -180 - tilt_x;
|
6 | accz += 180;
|
7 | tilt_y += 180;
|
8 | } else if (tilt_x > 90) {
|
9 | tilt_x = 180 - tilt_x;
|
10 | accz += 180;
|
11 | tilt_y += 180;
|
12 | }
|
13 |
|
14 | // roll from -180 to + 180
|
15 | if (tilt_y >= 180) {
|
16 | tilt_y -= 360;
|
17 | }
|
18 |
|
19 | // yaw from 0 to 360
|
20 | if (accz < 0) {
|
21 | accz = accz + 360;
|
22 | }
|
23 | if (accz >= 360) {
|
24 | accz -= 360;
|
25 | }
|
Abgesehen davon, das bei mir noch accz unbehandelt ist (??? auch mit
atan2?) harmoniert ein Überschlag mit der atan2 funktion?
Mir fehlen hier leider die mathmatischen Hintergründe,... wieso
ist zu Bsp. für X,Y und Z ein Abstufung von 360, 180 und 90 Grad
vorgesehen?
Weiß hier jemand etwas?
Danke & Viele Grüße
Bernd