ROS 101

https://www.clearpathrobotics.com/blog/2014/01/how-to-guide-ros-101/

什么是ROS

ROS(robot operating system)是一个用于PC控制机器人组件的开源系统.一个ROS系统包含多个独立nodes,nodes直接通过pub/sub(发布/订阅)模式通信.比如传感器可以实现为一个传感器Node,传感器node采集数据,数据可以被其他node,比如导航node,路径查找node等等消费.

Why ROS

ROS的node不一定非得在一个computer上,甚至是不需要在同种结构的设备上.比如你可以用一个硬件设备采集数据,pub msg,在笔记本电脑上订阅这个msg,在手机上收取msg。这使得ROS具有高度灵活性.而且ROS是开源的.

基础概念

  • ROS Master
  • ROS Node

每一个node都要向master注册,master类似于消息中间件.node之间通过向master注册进行通信.node之间通过pub/sub模式通信.pub/sub 一个topic.类似于zmq里的pub/sub topic概念.

举个例子:
camera node负责和cmaera交互,image process node负责图片处理,image display node负责图片展示。在开始的时候,每一个node都要注册到master,
camera node注册的时候告诉master,他将要发布topic为image_data的消息,其余node注册的时候告诉master,想要订阅topic为image_data的数据.这样,当camera node收到来自camera采集的数据时,它就会发送image_data数据到image process node和image display node。

  • Services

上面的例子中,process node是被动接收camera数据的,如果process node想要主动获取数据呢?

process node向master注册一个specific service。然后process node就可以向camera node发一个request,请求image_data,然后camera node控制camera采集数据,reply给process node。

http://wiki.ros.org/ROS/Concepts

Concepts

  • Filesystem level
    提供一些基础层面,硬件层面的操作
  • Computation Graph level
  • Community level

Filesystem level

  • Packages: Packages are the main unit for organizing software in ROS. A package may contain ROS runtime processes (nodes), a ROS-dependent library, datasets, configuration files, or anything else that is usefully organized together. Packages are the most atomic build item and release item in ROS. Meaning that the most granular thing you can build and release is a package.
  • Metapackages: Metapackages are specialized Packages which only serve to represent a group of related other packages. Most commonly metapackages are used as a backwards compatible place holder for converted rosbuild Stacks.
  • Package Manifests: Manifests (package.xml) provide metadata about a package, including its name, version, description, license information, dependencies, and other meta information like exported packages. The package.xml package manifest is defined in REP-0127.
  • Repositories: A collection of packages which share a common VCS system. Packages which share a VCS share the same version and can be released together using the catkin release automation tool bloom. Often these repositories will map to converted rosbuild Stacks. Repositories can also contain only one package.
  • Message (msg) types: Message descriptions, stored in my_package/msg/MyMessageType.msg, define the data structures for messages sent in ROS.
  • Service (srv) types: Service descriptions, stored in my_package/srv/MyServiceType.srv, define the request and response data structures for services in ROS.

Computation Graph level

  • Node
    可以理解为一个程序.比如node1控制激光测距仪,node2控制车轮,nodes控制路径规划等等.

  • Master
    类似dsn。各个node都注册过来,提供查找lookup功能. node之间是直接通信的,并不经过master.

Nodes connect to other nodes directly; the Master only provides lookup information, much like a DNS server. Nodes that subscribe to a topic will request connections from nodes that publish that topic, and will establish that connection over an agreed upon connection protocol. The most common protocol used in a ROS is called TCPROS, which uses standard TCP/IP sockets.

  • Parameter Server
  • Messages
    just a data structure

Nodes communicate with each other by passing messages. A message is simply a data structure, comprising typed fields. Standard primitive types (integer, floating point, boolean, etc.) are supported, as are arrays of primitive types. Messages can include arbitrarily nested structures and arrays (much like C structs).

  • Topics
    pub/sub一个topic. 为了解耦,puber不需要知道有没有suber,puber只管produce这个topic的msg.suber不需要知道有没有puber,suber只管消费这个topic的msg

Messages are routed via a transport system with publish / subscribe semantics. A node sends out a message by publishing it to a given topic. The topic is a name that is used to identify the content of the message. A node that is interested in a certain kind of data will subscribe to the appropriate topic. There may be multiple concurrent publishers and subscribers for a single topic, and a single node may publish and/or subscribe to multiple topics. In general, publishers and subscribers are not aware of each others' existence. The idea is to decouple the production of information from its consumption. Logically, one can think of a topic as a strongly typed message bus. Each bus has a name, and anyone can connect to the bus to send or receive messages as long as they are the right type.

  • Services
    通过service完成request/reply. pub/sub中消息的消费是被动的,一个Node想要主动去向另一个node要消息,就得通过service完成request/reply.
  • Bags

Bags are a format for saving and playing back ROS message data. Bags are an important mechanism for storing data, such as sensor data, that can be difficult to collect but is necessary for developing and testing algorithms.

ROS Master在ROS计算图中扮演nameservice角色,存储topics和services注册信息.当注册信息改变,相应node就收到信息,类似zk里对某些node的watch机制.
names在ROS里作用巨大.

Names have a very important role in ROS: nodes, topics, services, and parameters all have names. Every ROS client library supports command-line remapping of names, which means a compiled program can be reconfigured at runtime to operate in a different Computation Graph topology.

比如,刚开始我们有个激光传感器node,在topic:scan上pub消息.相应的,suber在scan上消费消息. 后来我们想换个激光传感器,我们只需要重配置我们的系统.把names remap就行.比如新的激光传感器采集到的数据,我们定义一个新topic:scan_base,rename原来的scan->scan_base.我们再起一个激光传感器node,这个时候他就在scan_base上发消息了.

Names

Before we describe names further, here are some example names:

  • / (the global namespace)
  • /foo
  • /stanford/robot/name
  • /wg/node1
    每一个resource都define在一个namespace下,多个resources可能定义在同一个namespace下.resource可以在自己的namespace下create一个resource.resource可以访问自己的namespace下的resource或者更上层namespace下的resource.

Graph Resource Names are an important mechanism in ROS for providing encapsulation. Each resource is defined within a namespace, which it may share with many other resources. In general, resources can create resources within their namespace and they can access resources within or above their own namespace

There are four types of Graph Resource Names in ROS: base, relative, global, and private, which have the following syntax:

  • base
  • relative/name
  • /global/name
  • ~private/name
    解析规则如下
原文地址:https://www.cnblogs.com/sdu20112013/p/10495536.html