changed measuring datatype to quanternions and convert them to radials and degrees

This commit is contained in:
2024-05-08 15:12:49 +02:00
parent c7951c3d9f
commit 2c51596996
3 changed files with 28 additions and 15 deletions

View File

@@ -14,11 +14,21 @@ void setup() {
void loop() {
SensorManager::Rotation rotation = sensorManager.readLoop();
Serial.print(rotation.x);
// Convert quaternion to Euler angles in radians
float roll = atan2(2.0f * (rotation.w * rotation.i + rotation.j * rotation.k), 1.0f - 2.0f * (rotation.i * rotation.i + rotation.j * rotation.j));
float pitch = asin(2.0f * (rotation.w * rotation.j - rotation.k * rotation.i));
float yaw = atan2(2.0f * (rotation.w * rotation.k + rotation.i * rotation.j), 1.0f - 2.0f * (rotation.j * rotation.j + rotation.k * rotation.k));
// Convert to degrees
float rollDegrees = roll * 180.0f / PI;
float pitchDegrees = pitch * 180.0f / PI;
float yawDegrees = yaw * 180.0f / PI;
Serial.print(roll);
Serial.print(" ");
Serial.print(rotation.y);
Serial.print(pitch);
Serial.print(" ");
Serial.print(rotation.z);
Serial.print(yaw);
Serial.println();
}