參考:古月居《ROS探索總結》《ROS·wiki: Introduction》node
ROS(Robot Operating System)是一個機器人軟件平臺,它能爲異質計算機集羣提供相似操做系統的功能。ROS系統是起源於2007年斯坦福大學人工智能實驗室的項目與機器人技術公司Willow Garage的我的機器人項目PR2(Personal Robots Program)之間的合做,2008年以後就由Willow Garage來進行推進。算法
ROS提供一些標準操做系統服務,例如硬件抽象,底層設備控制,經常使用功能實現,進程間消息,以及包管理。它也提供用於獲取、編譯、編寫、和跨計算機運行代碼所需的工具和庫函數。ROS是基於一種圖狀架構,從而不一樣節點的進程能接受,發佈,聚合各類信息(例如傳感,控制,狀態,規劃等等)。編程
ROS能夠分紅兩層,低層(BSD許可證)是上面描述的操做系統層,高層則是廣大用戶羣貢獻的實現不一樣功能的各類軟件包,例如定位繪圖,行動規劃,感知,模擬等等。服務器
ROS是用於機器人的一種元操做系統(meta-operating system),或者說次級操做系統。它提供相似操做系統所提供的功能,包含硬件抽象描述、底層驅動程序管理、共用功能的執行、程序間的消息傳遞、程序發行包管理,它也提供一些工具程序和庫用於獲取、創建、編寫和運行多機整合的程序。網絡
The primary goal of ROS is to support code reuse in robotics research and development. ROS is a distributed framework of processes (aka Nodes) that enables executables to be individually designed and loosely coupled at runtime. These processes can be grouped into Packages and Stacks, which can be easily shared and distributed. ROS also supports a federated system of code Repositories that enable collaboration to be distributed as well. This design, from the filesystem level to the community level, enables independent decisions about development and implementation, but all can be brought together with ROS infrastructure tools.數據結構
ROS 的主要目標是爲機器人研究和開發提供代碼複用的支持。ROS是一個分佈式的進程(也就是「節點」)框架,這些進程被封裝在易於被分享和發佈的程序包和功能包中。ROS也支持一種相似於代碼儲存庫的聯合系統,這個系統也能夠實現工程的協做及發佈。這個設計可使一個工程的開發和實現從文件系統到用戶接口徹底獨立決策(不受ROS限制)。同時,全部的工程均可以被ROS的基礎工具整合在一塊兒。架構
In support of this primary goal of sharing and collaboration, there are several other goals of the ROS framework:app
ROS在某些程度上和其餘常見的機器人架構有些類似之處,如:Player、Orocos、CARMEN、Orca 和 MicrosoftRoboticsStudio。對於簡單的無機械手的移動平臺來講,Player是很是不錯的選擇。ROS則不一樣,它被設計爲適用於有機械臂和運動傳感器的移動平臺(傾角激光、雲臺、機械臂傳感器)。與Player相比,ROS更有利於分佈式計算環境。固然,Player提供了較多的硬件驅動程序,ROS則在高層架構上提供了更多的算法應用(如集成OpenCV的視覺算法)。框架
ROS implements several different styles of communication, including synchronous RPC-style communication over services, asynchronous streaming of data over topics, and storage of data on a Parameter Server. These are explained in greater detail in our Conceptual Overview.less
ROS is not a realtime framework, though it is possible to integrate ROS with realtime code. The Willow Garage PR2 robot uses a system called pr2_etherCAT, which transports ROS messages in and out of a realtime process. ROS also has seamless integration with the Orocos Real-time Toolkit.
關於點對點通訊,請參考《Ros: General Concepts》,如下僅做部分記錄:
ROS starts with the ROS Master. The Master allows all other ROS pieces of software (Nodes) to find and talk to each other. That way, we do not have to ever specifically state 「Send this sensor data to that computer at 127.0.0.1. We can simply tell Node 1 to send messages to Node 2.
How do Nodes do this? By publishing and subscribing to Topics.
... Now you may be thinking, what if I want the Image Processing Node to request data from the Camera Node at a specific time? To do this, ROS implements Services.
節點經過Topic發佈或捕獲「通知消息」——通知消息只是傳遞狀態變化,而不傳輸具體的數據——對於數據傳遞,須要經過「請求-響應」模式的服務機制實現。
A Node can register a specific service with the ROS Master, just as it registers its messages. In the below example, the Image Processing Node first requests /image_data, the Camera Node gathers data from the Camera, and then sends the reply.
from:《ROS·wiki: Concepts》
主要分爲三個級別:計算圖級、文件系統級、社區級。
計算圖是ROS處理數據的一種點對點的網絡形式。The basic Computation Graph concepts of ROS are nodes, Master, Parameter Server, messages, services, topics, and bags, all of which provide data to the Graph in different ways.
Nodes: Nodes are processes that perform computation. ROS is designed to be modular at a fine-grained scale; a robot control system usually comprises many nodes. For example, one node controls a laser range-finder, one node controls the wheel motors, one node performs localization, one node performs path planning, one Node provides a graphical view of the system, and so on. A ROS node is written with the use of a ROS client library, such as roscpp or rospy.
節點就是一些直行運算任務的進程。在這裏,節點也能夠被稱之爲「軟件模塊」。
Master: The ROS Master provides name registration and lookup to the rest of the Computation Graph. Without the Master, nodes would not be able to find each other, exchange messages, or invoke services.
控制器:消息的路由器,或者說是事件Broker,是ROS做爲分佈式系統運行的核心。ROS Master 經過RPC提供了話題註冊列表和對其餘計算圖表的查找。
節點與節點之間的鏈接是直接的,控制器僅僅提供了查詢信息,就像一個DNS服務器。節點訂閱一個主題將會要求創建一個與出版該主題的節點的鏈接,而且將會在贊成鏈接協議的基礎上創建該鏈接。
Parameter Server: The Parameter Server allows data to be stored by key in a central location. It is currently part of the Master.
若是說Master是一個Msg-Dispatcher,那麼有了Parameter Server的Master,就能夠稱之爲MQ了。
Parameter Server給ROS的節點存儲了主題和服務的註冊信息。節點與控制器通訊從而報告它們的註冊信息。當這些節點與控制器通訊的時候,它們能夠接收關於其餘以註冊及節點的信息而且創建與其它以註冊節點之間的聯繫。當這些註冊信息改變時控制器也會回饋這些節點,同時容許節點動態建立與新節點之間的鏈接。
Messages: 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: 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: The publish / subscribe model is a very flexible communication paradigm, but its many-to-many, one-way transport is not appropriate for request / reply interactions, which are often required in a distributed system. Request / reply is done via services, which are defined by a pair of message structures: one for the request and one for the reply. A providing node offers a service under a name and a client uses the service by sending the request message and awaiting the reply. ROS client libraries generally present this interaction to the programmer as if it were a remote procedure call.
雖然基於話題的發佈/訂閱模型是很靈活的通信模式,可是它廣播式的路徑規劃對於能夠簡化節點設計的同步傳輸模式並不適合。
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.
The ROS Master acts as a nameservice in the ROS Computation Graph. It stores topics and services registration information for ROS nodes. Nodes communicate with the Master to report their registration information. As these nodes communicate with the Master, they can receive information about other registered nodes and make connections as appropriate. The Master will also make callbacks to these nodes when this registration information changes, which allows nodes to dynamically create connections as new nodes are run.
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.
ROS的特殊性主要體如今消息通信層,而不是更深的層次。端對端的鏈接和配置利用XML-RPC機制進行實現,XML-RPC也包含了大多數主要語言的合理實現描述。咱們但願ROS可以利用各類語言實現的更加天然,更符合各類語言的語法約定,而不是基於C語言給各類其餘語言提供實現接口。然而,在某些狀況下利用已經存在的庫封裝後支持更多新的語言是很方便的,好比Octave的客戶端就是經過C++的封裝庫進行實現的。
ROS中有無數的節點、消息、服務、工具和庫文件,須要有效的結構去管理這些代碼。在ROS的文件系統級,有如下幾個重要概念:
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.
ROS的社區級概念是ROS網絡上進行代碼發佈的一種表現形式。結構以下圖所示:
代碼庫的聯合系統。使得協做亦能被分發。這種從文件系統級別到社區一級的設計讓獨立地發展和實施工做成爲可能。正是由於這種分佈式的結構,似的ROS迅速發展,軟件倉庫中包的數量指數級增長。
更多閱讀:《ROS: Higher-Level Concepts》
from:《ROS: Technical Overview》