目录
- Launch文件语法
- 实验
- 创建功能包
- 例子
- simple.launch
- turtlesim_parameter_config.launch
- start_tf_demo_c++.launch
- start_tf_demo_py.launch
- turtlesim_remap.launch
平台:华硕 Thinker Edge R 瑞芯微 RK3399Pro
固件版本:Tinker_Edge_R-Debian-Stretch-V1.0.4-20200615
记录自【古月居】古月·ROS入门21讲 | 一学就会的ROS机器人入门教程 —— 古月居GYH P19 19.launch启动文件的使用方法
Launch文件:通过XML文件实现多节点的配置和启动(可自动启动ROS Master)
Launch文件语法
<launch><launch><launch>
launch文件中的根元素采用<<<launch>>>标签定义
<node><node><node>
<node pkg="package-name" type="executable-name" name="node-name" />
pkg:节点所在的功能包名称
type:节点的可执行文件名称
name:节点运行时的名称
output, respawn, required, ns, args
参数设置
<param>/<rosparam><param>/<rosparam><param>/<rosparam>
设置ROS系统运行中的参数,存储在参数服务器中。
<param name="output_frame" value="odom" />
name:参数名
value:参数值
加载参数文件中的多个参数:
<rosparam file="params.yaml" command="load" ns= "params" />
<arg><arg><arg>
launch文件内部的局部变量,仅限于launch文件使用
<arg name="arg-name" default="arg-value" />
name:参数名
value:参数值
调用:
<param name="foo" value="$(arg arg-name)" />
<node name="node" pkg="package" type="type" args="$(arg arg-name)" />
<remap><remap><remap>
重映射ROS计算图资源的命名。
<remap from="/turtlebot/cmd_vel" to="/cmd_vel" />
from:原命名
to:映射之后的命名
<include><include><include>
包含其他launch文件,类似C语言中的头文件包含。
<include file="$(dirname)/other.launch" />
file:包含的其他launch文件路径
更多标签可参见:http://wiki.ros.org/roslaunch/XML
实验
创建功能包
cd ~/catkin_workspace/src
catkin_create_pkg learning_launch
cd learning_launch
mkdir launch
例子
simple.launch
nano ~/catkin_workspace/src/learning_launch/launch/simple.launch
<launch><node pkg="learning_topic" type="person_subscriber" name="talker" output="screen" /><node pkg="learning_topic" type="person_publisher" name="listener" output="screen" />
</launch>
编译并运行
cd ~/catkin_workspace
catkin_make# 新建一个终端
source ~/catkin_workspace/devel/setup.bash
roslaunch learning_launch simple.launch
turtlesim_parameter_config.launch
nano ~/catkin_workspace/src/learning_launch/launch/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>
mkdir ~/catkin_workspace/src/learning_launch/config
nano ~/catkin_workspace/src/learning_launch/config/param.yaml
A: 123
B: "hello"group:C: 456D: "hello"
编译并运行
cd ~/catkin_workspace
catkin_make# 新建一个终端
source ~/catkin_workspace/devel/setup.bash
roslaunch learning_launch turtlesim_parameter_config.launch
start_tf_demo_c++.launch
nano ~/catkin_workspace/src/learning_launch/launch/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>
编译并运行
cd ~/catkin_workspace
catkin_make# 新建一个终端
source ~/catkin_workspace/devel/setup.bash
roslaunch learning_launch start_tf_demo_c++.launch
start_tf_demo_py.launch
nano ~/catkin_workspace/src/learning_launch/launch/start_tf_demo_py.launch
<launch><!-- Turtlesim Node--><node pkg="turtlesim" type="turtlesim_node" name="sim"/><node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen"/><node name="turtle1_tf_broadcaster" pkg="learning_tf" type="turtle_tf_broadcaster.py"><param name="turtle" type="string" value="turtle1" /></node><node name="turtle2_tf_broadcaster" pkg="learning_tf" type="turtle_tf_broadcaster.py"><param name="turtle" type="string" value="turtle2" /> </node><node pkg="learning_tf" type="turtle_tf_listener.py" name="listener" /></launch>
编译并运行
cd ~/catkin_workspace
catkin_make# 新建一个终端
source ~/catkin_workspace/devel/setup.bash
roslaunch learning_launch start_tf_demo_py.launch
turtlesim_remap.launch
nano ~/catkin_workspace/src/learning_launch/launch/turtlesim_remap.launch
<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>
编译并运行
cd ~/catkin_workspace
catkin_make# 新建一个终端
source ~/catkin_workspace/devel/setup.bash
roslaunch learning_launch turtlesim_remap.launch
# 新建一个终端
source ~/catkin_workspace/devel/setup.bash
rqt_graph
rostopic list
rostopic pub /cmd_vel geometry_msgs/Twist "linear:x: 1.0y: 0.0z: 0.0
angular:x: 0.0y: 0.0z: 0.0"
# 新建一个终端
source ~/catkin_workspace/devel/setup.bash
rqt_graph