-
Notifications
You must be signed in to change notification settings - Fork 4
4.2 ROS Tutorial
Robot Operating System (ROS) is a framework designed to help people build and control robots. Despite its name, ROS isn't exactly an operating system like Windows or macOS; rather, it's a collection of software tools and libraries. Imagine ROS as the toolbox that robot developers use to build and control their robots. It provides a set of pre-made tools that make it easier to create different components of a robot's functionality. These components can include things like controlling motors, processing sensor data (like cameras and sonars), making decisions, and communicating with other robots or computers. Due to its useful functionalities, many universities and companies use it in their robots as a de facto standard for robot programming.
The main characteristics of ROS can be divided into 5 areas:
- 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++ and Python are the two most used).
- Lightweight: 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.
The ROS computation structure is composed of 7 main elements:
- 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 controls the wheel motors, another node performs localization, and so on. A ROS node is written with the use of a ROS client library, such as roscpp or rospy (these will be used in this tutorial).
- Master: The ROS Master provides name registration and lookup to the rest of the computation structure. Without the Master, nodes would not be able to find each other, exchange messages, or invoke services. Nodes connect to other nodes directly; the Master only provides lookup information.
- Parameter Server: The Parameter Server allows data to be stored by key in a central location. It is part of the Master.
- 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.
There are two ways to publish to a topic: from the command line or from an executable file (using rospy, for python, and roscpp, for C++).
In this example, we will publish the string type message “Hello” to the topic hello. In order to check whether it worked or not, we need to first use a command that echoes every message received in a given topic. First, we need to source the environment variables from the setup.bash file.