重点: gazebo、tf坐标变换、ros::launch
1.Launch启动文件
上一讲,我们讲的都是使用rosrun命令实现节点的创建,rostopic话题消息的发布,rosservice服务的搭建等等。但是,复杂又乱七八糟的shell窗口必然成了心腹大患,每次运行一个节点都要新开一个命令窗口,气的抠掉“Ctrl+Alt+T”。
那么,这一讲我们就来学习新的组件launch,挽救大家的键盘。
Launch文件: 通过XML文件实现多节点的配置和启动(可自动启动ROS Master,省下每次另开一个终端运行roscore)。
先来段吓人的代码~
<launch>
<!-- local machine already has a definition by default.
This tag overrides the default definition with
specific ROS_ROOT and ROS_PACKAGE_PATH values -->
<machine name="local_alt" address="localhost" default="true" ros-root="/u/user/ros/ros/" ros-package-path="/u/user/ros/ros-pkg" />
<!-- a basic listener node -->
<node name="listener-1" pkg="rospy_tutorials" type="listener" />
<!-- pass args to the listener node -->
<node name="listener-2" pkg="rospy_tutorials" type="listener" args="-foo arg2" />
<!-- a respawn-able listener node -->
<node name="listener-3" pkg="rospy_tutorials" type="listener" respawn="true" />
<!-- start listener node in the 'wg1' namespace -->
<node ns="wg1" name="listener-wg1" pkg="rospy_tutorials" type="listener" respawn="true" />
<!-- start a group of nodes in the 'wg2' namespace -->
<group ns="wg2">
<!-- remap applies to all future statements in this scope. -->
<remap from="chatter" to="hello" />
<node pkg="rospy_tutorials" type="listener" name="listener" args="--test" respawn="true" />
<node pkg="rospy_tutorials" type="talker" name="talker" />
<!-- set a private parameter for the mode -->
<param name="talker_1_param" value="a value" />
<!-- nodes can have their own remap args -->
<remap from="chatter" to="hello-1" />
<!-- you can set environment variables for a node -->
<env name="ENV_EXAMPLE" value="some value" />
</node>
</group>
</launch>
- <launch>
- launch文件中的根目录用<launch>标签定义。
- 意味着所有语法都要写在<launch>和</launch>中间
- <node>
- 启动节点
<node pkg="package-name" type="executable-name" name="node-name" />
- 参数:
- pkg:节点所在的功能包名称
- type:节点的可执行文件名称
- name:节点运行时的名称
- 也就是ros::init那个名字,这个name可以覆盖executable里面init的节点名,也就是可以重命名,当然也可以使用原来的
- output(日志是否要输出到终端中
output="screen"
)、respawn(如果节点运行失败,会重新启动)、required(表明这个节点是必须的,如果这个节点运行失败,其他节点就不能运行)、ns(设置一个命名空间)、args(就是rosrun后跟的参数[argc和argv]用来传递给接受者)
- <param>/<rosparam>
- 设置ROS系统运行中的参数,存储到参数服务器中(ROS Master的一块区域)
- param一次只能传一个参数,rosparam一次可以传多个参数
- name:参数名
- value:参数值
<param name="output_frame" value="odom" />
- 加载参数文件的多个参数(将多个参数存入params.yaml内[在config文件夹],通过load命令加载进去,ns设置了一个名为params的命名空间):
<rosparam file="params.yaml" command="load" ns="params" />
- <arg>
- launch文件内部的局部变量,仅限于launch文件使用
- name:参数名
- value:参数值
- launch文件内部的局部变量,仅限于launch文件使用
<arg name="arg-name" default="arg-value" />
- 调用:
<param name="foo" value="$(arg arg-name)" />
<node name="node" pkg="package" type="type" args="$(arg arg-name)" />
- <remap>
- 重映射计算图资源的命名
- from:原命名
- to:映射之后的命名
- 重映射计算图资源的命名
<remap from="/turtlebot/cmd_vel" to="/cmd_vel" />
- <include>
- 包含其他launch文件,类似C语言中的头文件包含
- file:包含的其他launch文件路径
- 包含其他launch文件,类似C语言中的头文件包含
<include file="$(dirname)/other.launch" />
更多标签可见:http://wiki.ros.org/roslaunch/XML
Tips:
rosnode list
在终端打印出当前运行中的节点名rosservice list
在终端打印出当前运行中的所有服务名rostopic list
在终端打印出当前运行中的所有话题名rosparam list
在终端中打印出当前运行中ROS Master内的所有参数rosparam get
在终端中打印出选定参数的值
(1)例一
1)turtlesim_parameter_config.launch
<launch>
<!--set turtle_number=2 in ROS master-->
<param name="/turtle_number" value="2" />
<!--temporary value only can use in this launch-->
<arg name="TurtleName1" default="Tom" />
<arg name="TurtleName2" default=