求助!! 关于JY-61模块的程序使用
arduino吧
全部回复
仅看楼主
level 1
JonahAbel 楼主
发现JY61例程里面如果加一个程序执行了几次的小计算就会导致串口的数据无法正常的输出,感觉是随机输出的,求大神指点,是因为缓存区的原因吗,以下是代码和结果
volatile int jishu = 0;//jishu
unsigned char Re_buf[11],counter=0;
unsigned char sign=0;
float a[3],w[3],angle[3],T;
void setup() {
// initialize serial:
Serial.begin(9600);
Serial2.begin(115200);
}
void loop() {
//if(flagZD == 1) checkSerial2();
Distance_angle();
}
void Distance_angle(){
jishu++;
Serial.print(jishu);Serial.print(" ");
if(sign)
{
sign=0;
if(Re_buf[0]==0x55) //检查帧头
{
switch(Re_buf [1])
{
case 0x51:
a[0] = (short(Re_buf [3]<<8| Re_buf [2]))/32768.0*16;
a[1] = (short(Re_buf [5]<<8| Re_buf [4]))/32768.0*16;
a[2] = (short(Re_buf [7]<<8| Re_buf [6]))/32768.0*16;
T = (short(Re_buf [9]<<8| Re_buf [8]))/340.0
+3
6.25;
break;
case 0x52:
w[0] = (short(Re_buf [3]<<8| Re_buf [2]))/32768.0*2000;
w[1] = (short(Re_buf [5]<<8| Re_buf [4]))/32768.0*2000;
w[2] = (short(Re_buf [7]<<8| Re_buf [6]))/32768.0*2000;
T = (short(Re_buf [9]<<8| Re_buf [8]))/340.0+36.25;
break;
case 0x53:
angle[0] = (short(Re_buf [3]<<8| Re_buf [2]))/32768.0*180;
angle[1] = (short(Re_buf [5]<<8| Re_buf [4]))/32768.0*180;
angle[2] = (short(Re_buf [7]<<8| Re_buf [6]))/32768.0*180;
T = (short(Re_buf [9]<<8| Re_buf [8]))/340.0+36.25;
/* Serial.print("a:");
Serial.print(a[0]);Serial.print(" ");
Serial.print(a[1]);Serial.print(" ");
Serial.print(a[2]);Serial.print(" ");
Serial.print("w:");
Serial.print(w[0]);Serial.print(" ");
Serial.print(w[1]);Serial.print(" ");
Serial.print(w[2]);Serial.print(" ");
Serial.print("angle:");
Serial.print(angle[0]);Serial.print(" ");
Serial.print(angle[1]);Serial.print(" ");*/
Serial.println(angle[2]); //Serial.print(" ");
delay(1000);
// Serial.print("T:");
// Serial.println(T);
break;
}
}
}
//flagZD=1;
while ( Serial2.available()) {
//char inChar = (char)Serial.read(); Serial.print(inChar); //Output Original Data, use this code
Re_buf[counter]=(unsigned char) Serial2.read();
//Serial.print("/"); Serial.print(counter);Serial.print(" "); Serial.print(Re_buf[counter]);Serial.print(" ");
if(counter==0&&Re_buf[0]!=0x55) return; //第0号数据不是帧头
counter++;
if(counter==11) //接收到11个数据
{
counter=0; //重新赋值,准备下一帧数据的接收
sign=1;
}
}
}
2019年05月08日 10点05分 1
level 1
JonahAbel 楼主
使用的是arduino mega 2560,真的有点困惑
2019年05月08日 10点05分 2
mpu6050和jy61测量偏航角时误差有多大
2019年05月09日 10点05分
level 1
问问解决了吗
2019年05月09日 10点05分 3
level 1
不要用这个代码,不知数据类型错了还是寄存器的问题我也搞了好久才解决,只能读取角度或着只能读取角速度,而且代码稍微改一下就全读不出来了。比如在loop外的子函数内读w和angle的数组就会都是0或者全是错乱的值
2019年07月26日 06点07分 4
请问您后来用的什么代码?
2020年05月01日 09点05分
level 1
请问后来怎么解决的?
2020年05月01日 10点05分 6
level 1
我毕设做无人机用了这个模块,我研究了两天才解决了[滑稽]
2020年06月23日 21点06分 8
level 6
推荐jy901
2020年06月27日 08点06分 9
1