ROS回顾与整理《五、launch文件的启动、管理》

发布时间 2023-09-27 16:09:46作者: FeiYull

  launch文件中语法类似于XML文件,里面就是一堆脚本。

  注:下面的参数

name:是指运行时节点名称,可以取代代码中 ros::init中设置的节点名。

output:是否将节点信息打印到终端。

respawn:如果节点挂了,控制该节点是否重启。

required:是否要求某个节点一定要启动。

ns:namespace,表示命名空间,避免命名冲突。

args:节点的命令行参数。

 

 

   

 

 

 

 

 实践一下:

一、多节点启动

1、在之前的msg_demo8项目中创建一个功能包

catkin_create_pkg learning_launch

2、在目录:learning_launch下创建一个launch文件夹,用于管理功能包资源(工作空间有两个功能包了:sry、learning_launch)

接下来我们在clion中创建、编辑launch文件(安装了ROS插件,会有自动提示关键词)。

clion中项目设置(多BB一句):

CMAKE选项: add -DCATKIN_DEVEL_PREFIX:PATH=/home/ros_proj/launch_demo1/devel
构建目录:  /home/ros_proj/launch_demo1/build

  在launch文件夹下,创建simple.launch文件:

<launch>
<node pkg="sry" type="person_subscriber" name="talker" output = "screen" />
<node pkg="sry" type="person_publisher" name="listener" output = "screen" />
</launch>

  运行:

source devel/setup.bash
roslaunch learning_launch simple.launch

  这样就通过一个launch文件,启动了两个节点。

 二、(略)

三、还是多节点启动(还贵那个demo)

  去另外一个工程tf_demo1搞乌龟demo,

catkin_create_pkg learning_launch

  在learning_launch文件夹下创建launch文件夹,在luanch文件下创建start_tf_demo.launch文件:

 1 <launch>
 2     <!-- 原来注释格式这个B样-->
 3     <node pkg="turtlesim" type="turtlesim_node" name="sim"/>
 4     <node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen"/>
 5 
 6     <node pkg="learning_tf" type="turtle_tf_broadcaster" args="/turtle1" name="turtle1_tf_broadcaster"/>
 7     <node pkg="learning_tf" type="turtle_tf_broadcaster" args="/turtle2" name="turtle2_tf_broadcaster"/>
 8 
 9     <node pkg="learning_tf" type="turtle_tf_listener" name="listener"/>
10 
11 </launch>

  强烈建议你去对比上一讲中,启动海龟相关节点的命令行参数,例如:name。

上一将:https://www.cnblogs.com/winslam/p/15046058.html

catkin_make
source devel/setup.bash
roslaunch learning_launch start_tf_demo.launch

  从此实现一个launch文件启动多个节点。

  

参考:https://www.bilibili.com/video/BV1zt411G7Vn?p=19&spm_id_from=pageDriver