Quellcode durchsuchen

修改发布的线加速度数据正负,因为ROS中规定IMU坐标系为ENU,IMU静止时z轴线加速度为G是正值

corvin vor 3 Jahren
Ursprung
Commit
f8d2820b9e

+ 16 - 16
rviz_display_6dof_imu/cfg/6dof_imu_display.rviz

@@ -5,9 +5,8 @@ Panels:
     Property Tree Widget:
       Expanded:
         - /Global Options1
-        - /Grid1/Offset1
       Splitter Ratio: 0.6222222447395325
-    Tree Height: 344
+    Tree Height: 488
   - Class: rviz/Selection
     Name: Selection
   - Class: rviz/Tool Properties
@@ -35,7 +34,7 @@ Visualization Manager:
   Class: ""
   Displays:
     - Alpha: 0.699999988079071
-      Cell Size: 1
+      Cell Size: 0.5
       Class: rviz/Grid
       Color: 50; 115; 54
       Enabled: true
@@ -53,9 +52,9 @@ Visualization Manager:
       Reference Frame: <Fixed Frame>
       Value: true
     - Acceleration properties:
-        Acc. vector alpha: 0.800000011920929
+        Acc. vector alpha: 0.5
         Acc. vector color: 179; 200; 255
-        Acc. vector scale: 0.05000000074505806
+        Acc. vector scale: 0.029999999329447746
         Derotate acceleration: false
         Enable acceleration: false
       Axes properties:
@@ -71,6 +70,7 @@ Visualization Manager:
       Class: rviz_imu_plugin/Imu
       Enabled: true
       Name: Imu
+      Queue Size: 10
       Topic: /imu_data
       Unreliable: false
       Value: true
@@ -103,33 +103,33 @@ Visualization Manager:
   Views:
     Current:
       Class: rviz/Orbit
-      Distance: 0.9545544385910034
+      Distance: 0.6284882426261902
       Enable Stereo Rendering:
         Stereo Eye Separation: 0.05999999865889549
         Stereo Focal Distance: 1
         Swap Stereo Eyes: false
         Value: false
+      Field of View: 0.7853981852531433
       Focal Point:
-        X: 0.026923831552267075
-        Y: 0.048061929643154144
-        Z: 0.06090698018670082
+        X: -0.0479598194360733
+        Y: 0.03407154977321625
+        Z: 0.04338056966662407
       Focal Shape Fixed Size: true
       Focal Shape Size: 0.05000000074505806
       Invert Z Axis: false
       Name: Current View
       Near Clip Distance: 0.009999999776482582
-      Pitch: 0.4303995668888092
+      Pitch: 0.7647970914840698
       Target Frame: <Fixed Frame>
-      Value: Orbit (rviz)
-      Yaw: 1.730486273765564
+      Yaw: 1.6754865646362305
     Saved: ~
 Window Geometry:
   Displays:
     collapsed: true
-  Height: 714
+  Height: 836
   Hide Left Dock: true
   Hide Right Dock: true
-  QMainWindow State: 000000ff00000000fd00000004000000000000016a0000021bfc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006500fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c00610079007300000000440000021b000000de00fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f000002e2fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a005600690065007700730000000028000002e2000000b900fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e100000197000000030000040000000044fc0100000002fb0000000800540069006d00650100000000000004000000028000fffffffb0000000800540069006d00650100000000000004500000000000000000000004000000021b00000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
+  QMainWindow State: 000000ff00000000fd000000040000000000000156000002a0fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073000000003d000002a0000000c900fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f000002e2fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a005600690065007700730000000028000002e2000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e100000197000000030000064000000044fc0100000002fb0000000800540069006d0065010000000000000640000002eb00fffffffb0000000800540069006d0065010000000000000450000000000000000000000640000002a000000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
   Selection:
     collapsed: false
   Time:
@@ -138,6 +138,6 @@ Window Geometry:
     collapsed: false
   Views:
     collapsed: true
-  Width: 1024
+  Width: 1600
   X: 0
-  Y: 96
+  Y: 27

+ 10 - 13
serial_6dof_imu/src/proc_serial_data.cpp

@@ -15,7 +15,7 @@
 #include<sys/time.h>
 #include<sys/types.h>
 
-#define  BYTE_CNT      55  //每次从串口中读取的字节数
+#define  BYTE_CNT      55            //每次从串口中读取的字节数
 #define  ACCE_CONST    0.000488281   //用于计算加速度的常量16.0/32768.0
 #define  ANGULAR_CONST 0.061035156   //用于计算角速度的常量2000.0/32768.0
 #define  ANGLE_CONST   0.005493164   //用于计算欧拉角的常量180.0/32768.0
@@ -164,7 +164,6 @@ static void parse_serialData(unsigned char chr)
             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;
-            //printf("%f %f %f %f\n", quater[0], quater[1], quater[2], quater[3]);
             break;
         default:
             ROS_ERROR("parse imu data frame type error !");
@@ -193,10 +192,10 @@ int makeYawZero(void)
     return 0;
 }
 
-/******************************************************************
+/*******************************************************************
  * Description:更新IMU模块的IIC地址,这里通过发送串口命令方式来更新IIC地址,
  *   完整的控制命令为:0xFF 0xAA 0x1A 0x** 0x00,更新的IIC地址为第4个字节.
- *****************************************************************/
+ ******************************************************************/
 int updateIICAddr(std::string input)
 {
     int ret = 0;
@@ -231,7 +230,7 @@ int updateIICAddr(std::string input)
 
 /*****************************************************************
  * Description:根据串口配置信息来连接IMU串口,准备进行数据通信,
- *   两个输入参数的意义如下:
+ *   输入参数的意义如下:
  *   const char* path:IMU设备的挂载地址;
  ****************************************************************/
 int initSerialPort(const char* path)
@@ -284,10 +283,9 @@ int initSerialPort(const char* path)
     return 0;
 }
 
-/*****************************************
- * Description:得到三轴加速度信息,输入
- *  参数可以为0,1,2分别代表x,y,z轴的
- *  加速度信息.
+/******************************************
+ * Description:得到三轴加速度信息,输入参数可以
+ *  为0,1,2分别代表x,y,z轴的加速度信息.
  *****************************************/
 float getAcc(int flag)
 {
@@ -295,9 +293,8 @@ float getAcc(int flag)
 }
 
 /******************************************
- * Description:得到角速度信息,输入参数可
- *  以为0,1,2,分别代表x,y,z三轴的角速度
- *   信息.
+ * Description:得到角速度信息,输入参数可以是
+ *  0,1,2,分别代表x,y,z三轴的角速度信息.
  *****************************************/
 float getAngular(int flag)
 {
@@ -325,7 +322,7 @@ float getQuat(int flag)
 }
 
 /********************************************
- * Description:返回温度值.
+ * Description:返回IMU芯片内部实时温度值.
  ********************************************/
 float getTemp(void)
 {

+ 17 - 15
serial_6dof_imu/src/serial_imu_node.cpp

@@ -1,12 +1,15 @@
-/*****************************************************************
+/******************************************************************
  * Copyright:2016-2021 www.corvin.cn ROS小课堂
  * Description:使用串口来读取IMU的数据,并通过ROS话题topic将数据发布出来.
  *   芯片中默认读取出来的加速度数据单位是g,需要将其转换为ROS中加速度规定的
- *   m/s2才能发布.
+ *   m/s2才能发布.ROS中使用的坐标系为ENU东北天坐标系,x轴指向东,y轴指向北,
+ *   z轴指向天空.
  * Author: corvin
  * History:
- *   20211122: init this file.
-*****************************************************************/
+ *   20211122:init this file.
+ *   20220220:ROS中IMU的坐标系为ENU东北天坐标系,所以需要修改线加速度的
+ *       数据正方向,与XYZ三轴正方向都相反,此时Z轴加速度G为正值.
+******************************************************************/
 #include <ros/ros.h>
 #include <tf/tf.h>
 #include <sensor_msgs/Imu.h>
@@ -20,8 +23,8 @@
 static float g_yawData;  //全局变量,存储当前yaw值,可以通过服务来得到该值
 
 /**********************************************************
- * Description:将yaw角度归零的话题回调函数,只要往话题中
- *   发布一条Empty消息,即可将yaw角度归零.
+ * Description:将yaw角度归零的话题回调函数,只要往话题中发布一条
+ *   std_msgs::Empty类型消息,即可将yaw角度归零.
  *********************************************************/
 void yawZeroCallback(const std_msgs::Empty::ConstPtr& msg)
 {
@@ -82,13 +85,13 @@ int main(int argc, char **argv)
     std::string set_iic_addr_service;
 
     int pub_topic_hz = 0;  //话题发布imu数据的频率
-    float degree2Rad = 3.1415926/180.0;
-    float acc_factor = 9.806;
+    const float degree2Rad = 0.017453292;  //3.1415926/180.0,将角度转换为弧度的系数
+    const float acc_factor = 9.806; //重力加速度常量
 
     ros::init(argc, argv, "imu_data_pub_node");
     ros::NodeHandle handle;
 
-    //launch文件中加载yaml配置文件,然后从yaml配置文件中读取参数
+    //launch文件中加载yaml配置文件,然后从yaml配置文件中读取参数
     ros::param::get("~imu_dev",          imu_dev);
     ros::param::get("~imu_link_name",    imu_link_name);
     ros::param::get("~pub_topic_hz",     pub_topic_hz);
@@ -168,11 +171,10 @@ int main(int argc, char **argv)
         imu_msg.angular_velocity_covariance = {0, 0, 0,
                                                0, 0, 0,
                                                0, 0, 0};
-        //三轴线加速度
-        //ROS_INFO("acc_x:%f acc_y:%f acc_z:%f",getAcc(0), getAcc(1), getAcc(2));
-        imu_msg.linear_acceleration.x = -getAcc(0)*acc_factor;
-        imu_msg.linear_acceleration.y = -getAcc(1)*acc_factor;
-        imu_msg.linear_acceleration.z = -getAcc(2)*acc_factor;
+        //三轴线加速度,这里规定xyz三轴线加速度坐标系为ENU
+        imu_msg.linear_acceleration.x = getAcc(0)*acc_factor;
+        imu_msg.linear_acceleration.y = getAcc(1)*acc_factor;
+        imu_msg.linear_acceleration.z = getAcc(2)*acc_factor;
         imu_msg.linear_acceleration_covariance = {0, 0, 0,
                                                   0, 0, 0,
                                                   0, 0, 0};
@@ -184,4 +186,4 @@ int main(int argc, char **argv)
 
     closeSerialPort(); //关闭与IMU模块的串口连接
     return 0;
-}
+}