[ROS-Beginner]5.理解ROS节点Node
1. 安装轻量化模拟器
$ sudo apt-get install ros-<distro>-ros-tutorials
2. 理解Graph的概念
-
Nodes: A node is an executable that uses ROS to communicate with other nodes.
-
Messages: ROS data type used when subscribing or publishing to a topic.
-
Topics: Nodes can publish messages to a topic as well as subscribe to a topic to receive messages.
-
Master: Name service for ROS (i.e. helps nodes find each other)
-
rosout: ROS equivalent of stdout/stderr
-
roscore: Master + rosout + parameter server (parameter server will be introduced later)
3. 节点Nodes
节点其实就是一个ROS package中的可执行文件,它使用client library与其他Node通信。nodes可以publish或者subscribe一个Topic,还可以提供或者使用Service。
4. 客户端库 Cilent Libraries
rospy = python cilent library
roscpp = c++ cilent library
5. roscore : 使用ROS时,第一件事情就是运行roscore
6. 如果没有initialize roscore,可能会出现network configuration issue问题。
7. 如果roscore 没有初始化并且发了一条消息说缺少permissions,则运行:
$ sudo chown -R <your_username> ~/.ros
8. 使用rosnode
1. 首先注意,打开新的terminal时环境会被重置,~/.bashrc文件会被source,如果执行命令出现了问题,则需要添加环境设置文件到~/.bashrc或者手动重新source。
2. rosnode可以显示正在运行的ROS Nodes的有关信息,比如
$ rosnode list
可以显示正在运行的node,将会看到
/rosout
如果运行
$ rosnode info /rosout
则会显示有关rosout的更多信息
9. 使用rosrun: rosrun + package名 + node 可以直接运行pacakge下的node,避免了输入具体路径。比如在新的terminal输入
$ rosrun turtlesim turtlesim_node
10. 此时在新的terminal中输入
$ rosnode list
可以看到
/rosout /turtlesim
11. ROS有一个强大的特点是可以通过命令行重新分配名字,如改变节点名字:
$ rosrun turtlesim turtlesim_node __name:=my_turtle
此时再重新查看
$ rosnode list
则会显示
/rosout /my_turtle
如果名字没变,可能是因为之前用ctrl+c关闭了node,尝试:
$ rosnode cleanup
12. 使用节点命令ping来测试
$ rosnode ping my_turtle