|
@@ -4,6 +4,8 @@
|
|
|
* Author: corvin
|
|
|
* History:
|
|
|
* 20200401:init this file.
|
|
|
+ * 20200702:将读取到的各数据的高低自己合成后要转换为short类型,
|
|
|
+ * 这样才能进行/32768.0*16.0运算.
|
|
|
******************************************************************/
|
|
|
#include<ros/ros.h>
|
|
|
#include<stdio.h>
|
|
@@ -15,6 +17,7 @@
|
|
|
#include<sys/time.h>
|
|
|
#include<sys/types.h>
|
|
|
|
|
|
+
|
|
|
char r_buf[512];
|
|
|
int port_fd = 0;
|
|
|
float acce[3],angular[3],angle[3],quater[4];
|
|
@@ -218,28 +221,28 @@ void parse_serialData(char chr)
|
|
|
switch(chrBuf[1])
|
|
|
{
|
|
|
case 0x51: //x,y,z轴 加速度输出
|
|
|
- acce[0] = (((short)chrBuf[3]<<8)|chrBuf[2])/32768.0*16.0;
|
|
|
- acce[1] = (((short)chrBuf[5]<<8)|chrBuf[4])/32768.0*16.0;
|
|
|
- acce[2] = (((short)chrBuf[7]<<8)|chrBuf[6])/32768.0*16.0;
|
|
|
+ acce[0] = ((short)(((short)chrBuf[3]<<8)|chrBuf[2]))/32768.0*16.0;
|
|
|
+ acce[1] = ((short)(((short)chrBuf[5]<<8)|chrBuf[4]))/32768.0*16.0;
|
|
|
+ acce[2] = ((short)(((short)chrBuf[7]<<8)|chrBuf[6]))/32768.0*16.0;
|
|
|
break;
|
|
|
|
|
|
case 0x52: //角速度输出
|
|
|
- angular[0] = (((short)chrBuf[3]<<8)|chrBuf[2])/32768.0*2000.0;
|
|
|
- angular[1] = (((short)chrBuf[5]<<8)|chrBuf[4])/32768.0*2000.0;
|
|
|
- angular[2] = (((short)chrBuf[7]<<8)|chrBuf[6])/32768.0*2000.0;
|
|
|
+ angular[0] = ((short)(((short)chrBuf[3]<<8)|chrBuf[2]))/32768.0*2000.0;
|
|
|
+ angular[1] = ((short)(((short)chrBuf[5]<<8)|chrBuf[4]))/32768.0*2000.0;
|
|
|
+ angular[2] = ((short)(((short)chrBuf[7]<<8)|chrBuf[6]))/32768.0*2000.0;
|
|
|
break;
|
|
|
|
|
|
case 0x53: //欧拉角度输出, roll, pitch, yaw
|
|
|
- angle[0] = (((short)chrBuf[3]<<8)|chrBuf[2])/32768.0*180.0;
|
|
|
- angle[1] = (((short)chrBuf[5]<<8)|chrBuf[4])/32768.0*180.0;
|
|
|
- angle[2] = (((short)chrBuf[7]<<8)|chrBuf[6])/32768.0*180.0;
|
|
|
+ angle[0] = ((short)(((short)chrBuf[3]<<8)|chrBuf[2]))/32768.0*180.0;
|
|
|
+ angle[1] = ((short)(((short)chrBuf[5]<<8)|chrBuf[4]))/32768.0*180.0;
|
|
|
+ angle[2] = ((short)(((short)chrBuf[7]<<8)|chrBuf[6]))/32768.0*180.0;
|
|
|
break;
|
|
|
|
|
|
case 0x59: //四元素输出
|
|
|
- quater[0] = (((short)chrBuf[3]<<8)|chrBuf[2])/32768.0;
|
|
|
- quater[1] = (((short)chrBuf[5]<<8)|chrBuf[4])/32768.0;
|
|
|
- quater[2] = (((short)chrBuf[7]<<8)|chrBuf[6])/32768.0;
|
|
|
- quater[3] = (((short)chrBuf[9]<<8)|chrBuf[8])/32768.0;
|
|
|
+ quater[0] = ((short)(((short)chrBuf[3]<<8)|chrBuf[2]))/32768.0;
|
|
|
+ quater[1] = ((short)(((short)chrBuf[5]<<8)|chrBuf[4]))/32768.0;
|
|
|
+ quater[2] = ((short)(((short)chrBuf[7]<<8)|chrBuf[6]))/32768.0;
|
|
|
+ quater[3] = ((short)(((short)chrBuf[9]<<8)|chrBuf[8]))/32768.0;
|
|
|
break;
|
|
|
}
|
|
|
chrCnt = 0;
|