我正在使用具有UART协议的Arduino mega2560测量与Gy-25传感器的链接角度。我需要有俯仰角,根据它的数据表,角度范围是从-20到85,然后又开始减小。有什么办法可以在360度产生这种角度? 我不知道是否可以将这个欧拉角转换为四元数?如何? 传感器及其数据表: https://bsfrance.fr/modules-rc-drones/606-GY25-capteur-de-position-angulaire-MPU6050-MCU-tilt-angle-module-UART-GY-25.html
float Roll,Pitch,Yaw;
unsigned char Re_buf[8],counter=0;
void setup()
{
Serial.begin(115200);
Serial3.begin(115200);// SoftwareSerial can only support 9600 baud rate for GY 25 but Serial3 can support 115200 and 9600 both
delay(4000);
Serial3.write(0XA5);
Serial3.write(0X54);//correction mode
delay(4000);
Serial3.write(0XA5);
Serial3.write(0X51);//0X51:query mode, return directly to the angle value, to be sent each read, 0X52:Automatic mode,send a direct return angle, only initialization
}
void loop() {
serialEvent();
Serial.print("roll= ");
Serial.print(Roll);
Serial.print(" pitch= ");
Serial.print(Pitch);
Serial.print(" yaw= ");
Serial.print(Yaw);
}
void serialEvent() {
Serial3.write(0XA5);
Serial3.write(0X51);//send it for each read
while (Serial3.available()) {
Re_buf[counter]=(unsigned char)Serial3.read();
if(counter==0&&Re_buf[0]!=0xAA) return;
counter++;
if(counter==8)
{
counter=0;
if(Re_buf[0]==0xAA && Re_buf[7]==0x55) // data package is correct
{
Yaw=(int16_t)(Re_buf[1]<<8|Re_buf[2])/100.00;
Pitch=(int16_t)(Re_buf[3]<<8|Re_buf[4])/100.00;
Roll=(int16_t)(Re_buf[5]<<8|Re_buf[6])/100.00;
}
}
}
}