ROS学习笔记(week1)
1.What is ROS?
ROS = Robot Operating System
2.ROS Philosophy
- Peer to peer(点对点):Individual programs communicate over defined API (ROS messages, services, etc.).
- Distributed(分布式):Programs can be run on multiple computers and communicate over the network.
- Multi-lingual(多语言):ROS modules can be written in any language for which a client library exists (C++, Python,MATLAB, Java, etc.).
- Light-weight(轻量级):Stand-alone libraries are wrapped around with a thin ROS layer.
- Free and open-source(免费并且开源):Most ROS software is open-source and free to use.
3.ROS Master
- 管理节点(进程)之间的通信
- 在启动时每个节点都需要与ROS master进行注册
使用如下命令启动ROS master:
roscore
4.ROS Nodes
- 实现单一功能的可执行程序,可以独立编译,执行和管理,并且通过packages进行组织
如何启动一个节点:
rosrun package_name node_name
如何查看已经激活的节点:
rosnode list
如何查看某个节点发出的信息:
rosnode info node_name
5.ROS Topics
- 节点之间通过话题进行通信
- 一个节点既可以发布话题也可以订阅话题
- 通常是一个发布者对应多个订阅者
- 话题就是一个信息流的名称
如何查看已经激活的话题:
rostopic list
如何订阅并且打印一个话题的内容:
rostopic echo /topic
如何显示一个话题的详细信息:
rostopic info /topic
6.ROS Messages
- 消息就是定义一个话题类型的数据结构
- 由整型,浮点型,布尔型,字符串类型,数组类型组成的嵌套结构
- 定义在*.msg文件中
如何查看一个话题的类型:
rostopic type /topic
如何向一个话题发布消息:
rostopic pub /topic type data
7.只学不练假把式,下面用一个小例子进行练习
- Starting a roscore
roscore
- Starting a talker node
rosrun roscpp_tutorials talker
- Analyze talker node
See the list of active nodes
rosnode list
Show information about the talker node
rosnode info /talker
See information about the chatter topic
rostopic info /chatter
- Analyze chatter topic
Check the type of the chatter topic
rostopic type /chatter
Show the message contents of the topic
rostopic echo /chatter
Analyze the frequency
rostopic hz /chatter
- Starting a listener node
Run a listener demo node with
rosrun roscpp_tutorials listener
- Analyze
See the new listener node with
rosnode list
Show the connection of the nodes over the chatter topic with
rostopic info /chatter
- Publish Message from Console
Publish your own message with
rostopic pub /chatter std_msgs/String "data: 'ETH Zurich ROS Course'"
8.ROS Workspace Environment
- 加载ROS默认的工作空间
source /opt/ros/kinetic/setup.bash
- 将你自己建立的工作空间添加到环境变量
cd ~/catkin_ws
source devel/setup.bash
- 检查你自己的工作空间是否被添加到了环境变量中
echo $ROS_PACKAGE_PATH
9.catkin Build System
- catkin是ROS的编译系统,用来生成可执行文件,库和接口
- 建议使用catkin_build而不是catkin_make
如何编译一个package
cd ~/catkin_ws
source devel/setup.bash
catkin build package_name
如何检查catkin workspace工作区的设置
catkin config
10.光说不练假把式,再来一个小例子
- 在home目录下新建一个git文件夹,并cd到git文件夹下:
mkdir git
cd ~/git
- 从github上下载源码:
git clone https://github.com/leggedrobotics/ros_best_practices.git
注意:这里为了避免使用多个工作空间,我们建立了一个git公共文件夹专门用来存放从github上下载的源码,然后我们再使用软连接将源码链接到工作空间中
- 将下载的源码链接到工作空间:
ln -s ~/git/ros_best_practices/ ~/catkin_ws/src/
- 编译并运行:
cd ~/catkin_ws
catkin build ros_package_template
source devel/setup.bash
roslaunch ros_package_template ros_package_template.launch
11.ROS Launch
- launch的主要作用是同时启动多个节点,避免运行一个程序有多个节点时需要一个一个节点的启动
- launch文件使用XML进行书写,并保存在以*.launch结尾的文件中
- 如果在运行launch文件前,没有启动roscore,launch文件会自动启动一个roscore节点
启动launch文件的两种方式:
(1)浏览文件夹,找到launch文件的位置,直接使用如下命令进行启动:
roslaunch file_name.launch
(2)通过包名启动一个launch文件:
roslaunch package_name file_name.launch
例如:
roslaunch roscpp_tutorials talker_listener.launch
重点:launch文件的书写格式
launch文件书写这一部分PPT中介绍的非常详细,可以自行查看