MPU-6050 仅移动一个轴时更改 X 和 Z 轴值

MPU-6050 changing X and Z axis values when only one axis is moved

我正在建造一架无人机并使用 Arduino Uno 来主要控制它。然而,当我倾斜无人机来测试它时,例如在 X 轴上,程序说它在 X 轴和 Z 轴上都倾斜了。我正在使用 MPU6050 陀螺仪。这是我使用的代码:

//Written by Ahmet Burkay KIRNIK
//Measurement of Angle with MPU-6050(GY-521)

#include<Wire.h>

const int MPU_addr=0x68; int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

int minVal=265; int maxVal=402;

double x; double y; double z;

void setup(){ Wire.begin(); Wire.beginTransmission(MPU_addr); Wire.write(0x6B); Wire.write(0); Wire.endTransmission(true); Serial.begin(9600); } void loop(){ Wire.beginTransmission(MPU_addr); Wire.write(0x3B); Wire.endTransmission(false); Wire.requestFrom(MPU_addr,14,true); AcX=Wire.read()<<8|Wire.read(); AcY=Wire.read()<<8|Wire.read(); AcZ=Wire.read()<<8|Wire.read(); int xAng = map(AcX,minVal,maxVal,-90,90); int yAng = map(AcY,minVal,maxVal,-90,90); int zAng = map(AcZ,minVal,maxVal,-90,90);

x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI); y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI); z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);

Serial.print("AngleX= "); Serial.println(x);

Serial.print("AngleY= "); Serial.println(y);

Serial.print("AngleZ= "); Serial.println(z); delay(400); }

没有人的运动对一个轴来说是完美的,你可能在另一个轴上移动。 如果我要确保我将 chip/board/drone 保持在 table 的边缘或类似的位置并将它倾斜一点,看看我是否只看到一个轴上的运动。 你应该只能看到微不足道的运动和另一个轴 如果它仍然显示出意想不到的重大运动 有可能你的芯片坏了 我曾经有一个便宜的中国飞行控制器,它使用板载 mpu6050 送给我坏了但对我来说问题是 没有 一个轴的移动 但我想这是可能的

陀螺仪坏了,但新的陀螺仪仍然关闭但可以使用。反正就是陀螺仪。