Browse Source

修改串口读取imu扩展板数据问题,需要将读取出字节数整体转换为short类型

corvin 4 years ago
parent
commit
7e4eab9900

+ 1 - 1
src/CMakeLists.txt

@@ -1 +1 @@
-/opt/ros/melodic/share/catkin/cmake/toplevel.cmake
+/opt/ros/kinetic/catkin/cmake/toplevel.cmake

+ 16 - 13
src/rasp_imu_hat_6dof/serial_imu_hat_6dof/src/proc_serial_data.cpp

@@ -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;

+ 3 - 2
src/ros_arduino_bridge/ros_arduino_python/config/my_arduino_params.yaml

@@ -15,7 +15,8 @@ is_use_serial: True
 serial_port: /dev/ttyACM0
 serial_baud: 57600
 
-i2c_smbus_num: 1   #raspberryPi:1, huawei altals 200DK: 2
+#raspberryPi:1, huawei altals 200DK: 2
+i2c_smbus_num: 1   
 i2c_slave_addr: 0x08  #Get arduino due i2c slave addr
 
 timeout: 0.5
@@ -35,7 +36,7 @@ odom_name: odom
 wheel_diameter: 0.058
 wheel_track: 0.109     #L value
 encoder_resolution: 11 #12V DC motors
-gear_reduction: 46     #empty payload rpm 130 r/m
+gear_reduction: 103     #empty payload rpm 130 r/m
 linear_scale_correction: 1.028
 angular_scale_correction: 1.00