ROS入门--launch启动文件
作者:互联网
古月老师ROS入门21讲笔记。
.launch启动文件:语法结构是XML,包含多种节点的配置和启动。可以自动启动ROS Master并且避免了多次不断打开终端,不断输入指令的麻烦。
语法
1.必须包含根元素< launch> 和 < /launch>,放在开头和结尾。
<launch>
<node pkg="turtlesim" name="sim1" type="turtlesim_node" />
<node pkg="turtlesim" name="sim2" type="turtlesim_node" />
</launch>
2.启动节点:< node>
<node pkg="package-name" type="executable-name" name="node-name" />
pkg: 节点所在的功能包名称
type: 节点的可执行文件名称
name: 节点运行时的名称,节点名字取代掉程序运行初始化的名字。
output 、respawn 、 required 、ns 、 args
3.储存在参数服务器中,参数设置 < param > / < rosparam>,设置ROS系统运行中的参数。
存储一个参数时:name: 参数名,value: 参数值
<param name="output_frame" value="odom" />
如果要加载参数文件中的多个参数:
<rosparam file="params.yaml" command="load" ns="params" />
4.存在launch文件内部的局部变量,仅限于launch文件的使用。也可以作为node的输入参数
<arg name="arg-name" default="arg-value" />
也可以作为node的输入参数,调用arg-name:
<param name="foo" value="$(arg arg-name)" />
<node name="node" pkg="package" type="type" args="$(arg arg-name)" />
5.重映射:重新命名ROS计算图资源 < remap>
from: 原命名
to: 映射之后的命名
<remap from="/turtlebot/cmd_vel" to="/cmd_vel" />
6.嵌套:包含其他launch文件,类似C语言的头文件包含。< include>
<include file="$(dirname)/other.launch" />
另外可以参考wiki:链接
launch示例
- simple.launch
在learning_topic功能包下运行Publisher&Subscriber,把日志信息打印到终端中。
<launch>
<node pkg="learning_topic" type="person_subscriber" name="talker" output="screen" />
<node pkg="learning_topic" type="person_publisher" name="listener" output="screen" />
</launch>
2.turtlesim_parameter_config.launch配置参数
<launch>
<param name="turtle_number" value="2"/>
<node pkg="turtlesim" type="turtlesim_node" name="turtlesim_node">
<param name="turtle_name1" value="Tom"/>
<param name="turtle_name2" value="Jerry"/>
<rosparam file="$(find learning_launch)/config/param.yaml" command="load"/>
</node>
<node pkg="turtlesim" type="turtle_teleop_key" name="turtle_teleop_key" output="screen"/>
</launch>
3.start_tf_demo_c++.launch,海龟跟随案例
<launch>
<!-- Turtlesim Node-->
<node pkg="turtlesim" type="turtlesim_node" name="sim"/>
<node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen"/>
<node pkg="learning_tf" type="turtle_tf_broadcaster" args="/turtle1" name="turtle1_tf_broadcaster" />
<node pkg="learning_tf" type="turtle_tf_broadcaster" args="/turtle2" name="turtle2_tf_broadcaster" />
<node pkg="learning_tf" type="turtle_tf_listener" name="listener" />
</launch>
4.turtlesim_remap.launch,remap&include案例。remap重命名指令,原命令资源消除。
<launch>
<include file="$(find learning_launch)/launch/simple.launch" />
<node pkg="turtlesim" type="turtlesim_node" name="turtlesim_node">
<remap from="/turtle1/cmd_vel" to="/cmd_vel"/>
</node>
</launch>
编译并运行
$ catkin_make
$ roslaunch learning_launch simple.launch
$ roslaunch learning_launch turtlesim_parameter_config.launch
$ roslaunch learning_launch start_tf_demo_c++.launch
$ roslaunch learning_launch turtlesim_remap.launch
ps: ros资源整合时,会用.launch在做搭积木的过程。
标签:remap,launch,--,参数,learning,ROS,节点 来源: https://blog.csdn.net/asforking/article/details/121300810