Przeglądaj źródła

更新串口读取imu模块代码

corvin 5 lat temu
rodzic
commit
dcffd0334e

+ 3 - 3
src/rasp_imu_hat_6dof/serial_imu_hat_6dof/CMakeLists.txt

@@ -116,7 +116,7 @@ catkin_package(
 ## Specify additional locations of header files
 ## Your package locations should be listed before other locations
 include_directories(
-# include
+  include
   ${catkin_INCLUDE_DIRS}
 )
 
@@ -128,12 +128,12 @@ include_directories(
 ## Add cmake target dependencies of the library
 ## as an example, code may need to be generated before libraries
 ## either from message generation or dynamic reconfigure
-# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
+add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
 
 ## Declare a C++ executable
 ## With catkin_make all packages are built within a single CMake context
 ## The recommended prefix ensures that target names across packages don't collide
-# add_executable(${PROJECT_NAME}_node src/serial_imu_hat_6dof_node.cpp)
+add_executable(${PROJECT_NAME}_node src/proc_serial_data.cpp src/serial_imu_node.cpp)
 
 ## Rename C++ executable without prefix
 ## The above recommended prefix causes long target names, the following renames the

+ 18 - 0
src/rasp_imu_hat_6dof/serial_imu_hat_6dof/cfg/param.yaml

@@ -0,0 +1,18 @@
+###############################################
+# Copyright: 2016-2020 www.corvin.cn ROS小课堂
+# Description:使用串口进行通信时的配置信息.
+# Author: corvin
+# History:
+#   20200402: init this file.
+###############################################
+imu_dev: /dev/ttyUSB0
+baud_rate: 9600
+data_bits: 8
+parity: N
+stop_bits: 1
+
+pub_data_topic: imu_data
+pub_temp_topic: imu_temp
+link_name: base_imu_link
+pub_hz: 10
+

+ 0 - 1
src/rasp_imu_hat_6dof/serial_imu_hat_6dof/include/imu_data.h

@@ -41,6 +41,5 @@ class myIMU
         unsigned char pitch[2];
         unsigned char yaw[2];
 };
-
 #endif
 

+ 14 - 0
src/rasp_imu_hat_6dof/serial_imu_hat_6dof/launch/serial_imu_hat.launch

@@ -0,0 +1,14 @@
+<!--
+  Copyright: 2016-2019 https://www.corvin.cn ROS小课堂
+  Description:使用串口来读取imu模块的数据,并在ros中发布使用话题发布出来.
+  Author: corvin
+  History:
+    20200401: init this file.
+-->
+<launch>
+  <arg name="imu_cfg_file" default="$(find serial_imu_hat_6dof/cfg/param.yaml)" />
+
+  <node pkg="serial_imu_hat_6dof" type="" name="" output="screen">
+    <rosparam file="$(arg imu_cfg_file)" command="load" />
+  </node>
+</launch>

+ 1 - 0
src/rasp_imu_hat_6dof/serial_imu_hat_6dof/src/proc_serial_data.cpp

@@ -261,6 +261,7 @@ int main(void)
     int port_fd = 0;
     char r_buf[512];
     bzero(r_buf, 512);
+    std::string imu_dev;
 
     port_fd = open_serialPort("/dev/ttyUSB0");
     if(port_fd < 0)

+ 6 - 0
src/rasp_imu_hat_6dof/serial_imu_hat_6dof/src/serial_imu_node.cpp

@@ -24,9 +24,15 @@ Eigen::Quaterniond euler2Quater(float roll, float yaw, float pitch)
 
 int main(int argc, char **argv)
 {
+    std::string imu_dev;
+    myImu my_imu;
+
     ros::init(argc, argv, "imu_data_pub_node");
     ros::NodeHandle handle;
 
+    imu_dev = handle.getParam("~imu_dev", "imu_dev");
+    rospy.loginfo("imu_dev:%s", imu_dev);
+
     ros::Publisher imu_pub = handle.advertise<sensor_msgs::Imu>("imu_data", 2);
     ros::Rate loop_rate(10);
     sensor_msgs::Imu imu_msg;