1_ROS basics

ROS basics

This chapter explains the most basic concepts in ROS. If you don’t understand these concepts, you can’t learn ROS. After learning these concepts, we will further understand them in the process of practice through practical operations.


What is ROS

ROS (Robot Operating System, Robot Operating System) is a software that provides a series of libraries and tools to help software developers create robot applications.
It provides many functions such as hardware abstraction, device driver, function library, visualization tool, message passing and package management.

To put it simply, ROS is a robot operating system, which is a collection of a series of software. These software together can achieve the purpose of controlling the robot.
On this basis, we can choose the appropriate software to assist us in completing the task.


1. The core concepts in ROS

NodeNode

ROS decomposes the tasks that the robot needs to perform into multiple small steps, and then implements each step in the form of a process, and each process is callednode

For example, for robot vision, we package the camera driver program into a node, then package the image processing program collected by the camera into a node, and finally package the image display program into a node, as shown in the figure below

insert image description here

Node Features

  1. The programming language written by each node is not fixed, some may be C++, some may be Python.
    For nodes, we don't pay attention to its specific implementation, we only pay attention to the functions implemented by this node
  2. In order to ensure that the node can run on different machines, the node cannot depend on the current environment, soAll nodes are executable binaries
  3. Nodes cannot have the same name

Node Manager ROS Master

Continuing with the example of robot vision above, in the above example, in order to realize the task of robot vision, we have a total of three nodes, namely the camera driver node, the image processing node and the image display node, and there is also a relationship between these three nodes
, The camera driver node will send the collected images to the image processing node, and the image processing node will send the processed data to the image display node

However, generally speaking, a large number of nodes is required to complete a task in the real world, which may be as high as one or two hundred nodes. If so many nodes are not well managed, it will eventually cause confusion. Therefore, ROS providesROS Master for managing nodes,As shown below

These three nodes must be registered in the ROS Master if they want to be run

insert image description here

Features of Node Manager

  1. The node manager provides naming and registration services for nodes
  2. The node manager tracks and records the relationships between nodes, and the relationship between nodes is usually data transmission in the form of topics and communication, which will be discussed later
  3. The node manager is responsible for providing global parameters, that is, providing parameter servers, because at some point, some parameters may be shared between multiple nodes. At this time, the ROS Master is responsible for recording these parameters and providing them when needed

parameter

The parameter refers to the dictionary shared between nodes and stored in the ROS Master

For example, the vision of a robot not only needs to see the image it is currently seeing, but also needs the angle it is currently seeing, so that the robot can understand the image it is looking at. In other words, parameter information such as the pitch angle of the camera, and this information It is shared by three nodes

Characteristics of parameters

  1. Parameters are uniformly managed by ROS Master. Specific management matters include: adding parameters, accessing parameters, etc.
  2. Parameters can be accessed via the network
  3. Parameters are suitable for storing static, non-binary configuration parameters

insert image description here


2. Communication mechanism in ROS

Topic communication mechanism – asynchronous communication mechanism

The topic communication mechanism is similar to the UDP protocol. Specifically, the data publishing node is only responsible for publishing data, while the data receiving node is only responsible for receiving data

Which node is publishing data and which one is receiving data does not care about each other

insert image description here

Message Message

Let's continue to go back to the example of robot vision just now. In the above example, data transmission is carried out between the three nodes, that is, image transmission

However, nodes can be written in different languages, and different languages ​​store data in different ways, such as Python lists and dictionaries, and C++ arrays and vectors. Data transmission is often involved between different nodes
. For this reason, ROS defines a standard data transmission format between nodes

The data written in the ROS standard format transmitted between these nodes is called a message, the transmission of data between nodes depends on the message

Features of the message
  1. The concrete implementation of the message isFiles that have nothing to do with the programming language are used .msg, and the corresponding code is generated during the compilation process
  2. .msgThe essence of the file is a plain text file, but just like files such as html, xml and json, it has a certain format/data type
    ROS has predefined a lot of data for us, including images, radar point clouds, etc. Of course, we can also define the type of message by ourselves

Topic

A topic is a bus used to transfer data between nodes

It can be a folder, such as the camera example above, the camera driver node puts the collected images under a folder, and the image processing node reads the pictures in this folder, and this folder is a topic at this time

Topic Features
  1. Topics use the publish/subscribe model
  2. Subscribers and publishers of a topic may not be unique

Subscriber Subscriber / Publisher Publisher

The publisher refers to the sender of the message in a topic, in the example of robot vision, it is the camera driver node

Subscriber refers to the receiver of messages in a topic, the above example refers to the camera driver node and image processing node

In the example of the picture below, Topic is the example folder, the topic name is also example, and message is a string that conforms to the ROS standard

insert image description here

Service Communication Mechanism – Synchronous Communication Mechanism

Another communication mechanism in ROS is the service communication mechanism, which is similar to the TCP protocol. In the service communication mechanism, a stable connection must be established between the data publishing node and the receiving node.

insert image description here

Request Request / Response Answer

Like messages, ROS also defines the data format for data transmitted between nodes using the service communication mechanism

Similarly, it is a plain text file .srvwith a suffix, and the corresponding code file is generated during compilation

Server Server / Client Client

The server refers to the node that publishes the data, and the client refers to the node that receives the data

Comparison of two communication mechanisms

insert image description here

ROS file system

The file system refers to the hierarchical organization structure between files, in ROSRefers to the hierarchical organizational structure of various functional packages

We can package several nodes that can complete independent tasks into a function package, such as a function package that independently completes viewing, grasping and walking

Then we combine these function packages into a large meta-function package. For example, the above three function packages are packaged into

In addition to searching, we can also make meta-function packages such as running, and finally all meta-function packages are combined to form a software warehouse

The combination of many software warehouses is the ROS community

insert image description here

The composition of the function package

A feature package is usually a folder with the following contents:

  • Function package list: describe the function of the function package, author and update information, third-party dependencies, etc.
  • Message type: the customized message type in the function package
  • Service type
  • the code
  • other

Guess you like

Origin blog.csdn.net/qq_45488242/article/details/110260737