ROS 機器人技術 - 編寫一個 launch 啟動多個節點


1. 增加 source 到 bashrc 中

為了不用在小車的 Ubuntu 上每次都 source 自己的工作空間,我把自己的 workspace 加到 ~/.bashrc 文件末尾:

然后重啟 shell,之后就會自動 source 我得工作空間,可以使用 roscd 直接進入指定包中:

roscd pkg_name

2. 編寫啟動 launch

每次調試小車,都要分別啟動很多節點,比如融合、建圖、Loam、Rviz 等,所以我把這些節點全部配置在一個 launch 中啟動,直接一行命令啟動,這樣調試就方便多了,大大節省時間:

  • lidar_camera_fusion\launchlidar_camera_fusion.launch
  • octomap_server\rvizoctomap_debug.rviz
  • octomap_server\launchdlonng_octomap_test.launch
<launch>
  <!-- Start ZED! -->
  <include file = "$(find zed_cpu_ros)/launch/zed_cpu_ros.launch" />

  <!-- Start Robosense LIDAR! -->
  <include file = "$(find rslidar_pointcloud)/launch/rs_lidar_16.launch" />

  <!-- Start fusion node! -->
  <include file = "$(find lidar_camera_fusion)/launch/lidar_camera_fusion.launch" />

  <!-- Start Octomap node! -->
  <include file = "$(find octomap_server)/launch/octomap_server_start.launch" />

  <!-- Start octomap_debug.rviz -->
  <node pkg = "rviz" type = "rviz" name = "$(anon rviz)" respawn = "false" output = "screen" args = "-d $(find octomap_server)/rviz/octomap_debug.rviz"/>

  <!-- Start Lego Loam! -->
  <include file = "$(find lego_loam)/launch/demo.launch" />

  <!-- Only using in map build test! -->
  <node pkg = "tf2_ros" type = "static_transform_publisher" name = "dlonng_static_test_broadcaster" args = "0 0 0 0 0 0 base_link rslidar" />

</launch>

3. 補充一些小 Tips

如果不知道要啟動的包的 launch 文件叫啥,可以查找指定包的路徑,然后進入看看 launch 文件夾下面的啟動文件叫啥:

rospack list | grep "zed_cpu_ros"
rospack list | grep "rslidar_pointcloud"

之后我就可以從 octomap_server 中一鍵啟動所有我建圖要用的節點了:

roslaunch octomap_server dlonng_octomap_test.launch

但是啟動過程中遇到 rviz 節點名字重復的問題,我把雷達啟動的 RVIZ 關掉或者把啟動 RVIZ 的節點名稱改變下,防止重復。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM