„Vektor“ wurde in diesem Bereich nicht deklariert (MPU6050)
Posted: 16 Jan 2025, 10:39
Auf meinem anderen PC lief genau dieser Code schon einmal ohne Probleme. Als ich jedoch versuchte, es auf diesem PC auszuführen, traten viele Probleme auf. Ich habe versucht, die gleichen Bibliotheken nach besten Kräften zu installieren. Dennoch habe ich anscheinend immer noch Probleme ... Ich weiß, dass viele Variationen dieser Frage gestellt wurden, aber ich kann sie immer noch nicht lösen.
Ich erhalte diese Fehlermeldung:
Können Sie bitte helfen? Was raten Sie außerdem zur Ausführung desselben Codes auf mehreren PCs für zukünftige Fälle?
Vielen Dank
Code: Select all
#include
#include
#include "I2Cdev.h"
MPU6050 mpu;
void setup() {
Serial.begin(115200);
Wire.begin();
mpu.initialize(); // Initialize the sensor
if (!mpu.testConnection()) {
Serial.println("MPU6050 connection failed");
while (1); // Halt if connection fails
}
Serial.println("MPU6050 connection successful");
}
void loop() {
// Read normalized accelerometer data
Vector normAccel = mpu.readNormalizeAccel();
// Calculate pitch and roll
float pitch_rad = -(atan2(normAccel.XAxis, sqrt(normAccel.YAxis * normAccel.YAxis + normAccel.ZAxis * normAccel.ZAxis))) +0.01745;
float roll_rad = (atan2(normAccel.YAxis, normAccel.ZAxis)) + 1.5708;
int pitch = pitch_rad * 180.0 / M_PI;
int roll = roll_rad * 180.0 / M_PI;
Serial.print(" Pitch: ");
Serial.print(pitch);
Serial.print(" Roll: ");
Serial.println(roll);
}
Code: Select all
error: 'normAccel' was not declared in this scope
float pitch_rad = -(atan2(normAccel.XAxis, sqrt(normAccel.YAxis * normAccel.YAxis + normAccel.ZAxis * normAccel.ZAxis))) +0.01745;
^~~~~~~~~
exit status 1
Compilation error: 'Vector' was not declared in this scope
Vielen Dank