c++ - x 和 y 轴的陀螺仪数据相同,如何解决?
问题描述
我正在用arduino编程一个高度计。
我在高度变化的准确性方面遇到了一些问题,并且在火箭开始下落时弄清楚如何引爆火药。另外我对陀螺仪数据有疑问,它为我提供了相同的 x 和 y 轴数据。我还需要有人总体上查看我的代码。我的部分代码基于我在互联网上找到的代码。
这段代码用于我高中火箭的高度计,它将在空中飞行 56323 米,我的课程花了一年的时间完成,所以我决定是否只使用我编程设置的 arduino pyrocharges 或使用同温层记录器,只需将 arduino 用作数据记录器。
我正在使用 Arduino Geniuno Uno、MPU-6000(陀螺仪和加速度计)和 MS5611(气压计)。
//imports Library
#include <Wire.h>
//The variables for the gyroscope
float elapsedTime, time, timePrev; // these are time
int gyro_error =0;// used to calculate error
float Gyro_rawX, Gyro_rawY, Gyro_rawZ; //the raw angle data
float angleX, angleY;
float Gyro_raw_errorX, Gyro_raw_errorY;
float Total_angle_x, Total_angle_y;
void setup(){
//starting up the I2C device
Wire.begin();
Wire.beginTransmission(0x69);//This starts the transmission to the I2C device, while most things online will tell you that it's 0x68 it's not
Wire.write(0x6B);
Wire.write(0x00);//reset
Wire.endTransmission(true);//end Transmission
//Gyroscope configuration
Wire.beginTransmission(0x69);
Wire.write(0x1B);
Wire.write(0x10);//for the gyroscope use 0x10 for the accelerometer use 0x18
Wire.endTransmission(true);
Serial.begin(9600);//for this we are using a 9600 baud rate
time = millis();
//This gets the data for the gyroscope
if(gyro_error==0)
{
for(int i=0; i<200; i++)
{
Wire.beginTransmission(0x69); //begin, Send the slave adress (in this case 68)
Wire.write(0x43); //First adress of the Gyro data
Wire.endTransmission(false);
Wire.requestFrom(0x69,4,true); //We ask for just 4 registers
Gyro_rawX=Wire.read()<<8|Wire.read(); //Once again we shif and sum
Gyro_rawY=Wire.read()<<8|Wire.read();
/*---X---*/
Gyro_raw_errorX = Gyro_raw_errorX + (Gyro_rawX/32.8);
/*---Y---*/
Gyro_raw_errorY = Gyro_raw_errorY + (Gyro_rawY/32.8);
if(i==199)
{
Gyro_raw_errorX = Gyro_raw_errorX/200;
Gyro_raw_errorY = Gyro_raw_errorY/200;
gyro_error=1;
}
}
}
//beeper just to know if it's working
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
delay(400);
digitalWrite(LED, LOW);
delay(400);
}
void loop(){
timePrev =time;
time= millis();
elapsedTime = (time - timePrev)/1000;
//Gyroscope
Wire.beginTransmission(0x69);
Wire.write(0x43);
Wire.endTransmission(false);
Wire.requestFrom(0x69,6,true);
Gyro_rawX=Wire.read()<<8|Wire.read();
Gyro_rawY=Wire.read()<<8|Wire.read();
Gyro_rawX = (Gyro_rawX/32.8) - Gyro_raw_errorX;
Gyro_rawY = (Gyro_rawY/32.8) - Gyro_raw_errorY;
angleX = Gyro_rawX * elapsedTime;
angleY = Gyro_rawX * elapsedTime;
Total_angle_x = 0.98 *(Total_angle_x + angleX) + 0.02*Accel_angleX;
Total_angle_y = 0.98 *(Total_angle_y + angleY) + 0.02*Accel_angleY;
//This prints out rotation
Serial.print("X rotation");//in the x axis
Serial.println(Total_angle_x,4);
Serial.print("Y rotation");//in the y axis
Serial.println(Total_angle_y,4);
}
x=1.0302
在串行监视器中打印出的 x 和 y 轴数据与,完全相同y=1.0302
。另一个问题是,如果我改变角度并将其放回原位,它就不会回到零。
解决方案
推荐阅读
- javascript - 材质 ui cardmedia 高度作为纵横比还是使用 vh?
- python - 我正在尝试使用 sklearn 中的 Python MultinomialNB 对一些数据进行分类,但它返回一个值错误
- python - 我正在尝试在循环中使用 if 语句,但它不起作用
- python - lamdba aws 使用主机头中的域访问直接 IP
- python - 在 Python 3.8 中的 for 循环(或通过其他脚本)中迭代地命名数组
- javascript - 在 mongo 中将 $where 与异步函数一起使用
- gitlab - 在 GitLab 中通过多个 repos 共享文档
- javascript - 以角度选择选项时,下拉菜单不会折叠
- python - Matplotlib 中的堆积条形图
- csv - 带有空标头的 DatastaxBulk 加载程序问题