# 6. ROS Basic Concepts

In this chapter, I will help you understand the basic concepts of ROS: Master, Node, Topic, Publisher, Subscriber, and Service. After that, you are going to implement these concepts by adding codes to the *my\_cam* package, which we created in the [previous chapter.](https://robodev.blog/ros-packages-and-workspace) First, let's start with [ROS Nodes]((http://wiki.ros.org/ROS/Tutorials/UnderstandingNodes)).

# ROS Master and Nodes

To easily understand Node, let's imagine our camera node as a Photographer who starts working in an office of a magazine. On the first day of his job, he takes some photos and notifies his Boss that he will leave these photos on a specific Table in the office. The Boss thanks him for the notification.

![ros_master_publisher.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1670164679323/_aQsrv102.jpg align="center")

In our story, the Boss represents the [ROS Master](http://wiki.ros.org/Master), which you always have to have when you use ROS. "The **ROS Master** provides **naming** and **registration** services to the rest of the nodes in the ROS system. It tracks publishers and subscribers to topics as well as services" ([source](http://wiki.ros.org/Master)). ROS Master is called by using the command `roscore`. There should be only one ROS Master running at a time. If you try to call another one, there will be an error. The Photographer represents **a ROS Node which must always register to Master when it starts** similar to the Photographer notifying his Boss.

![roscore.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1670143511505/lwy-FOAdn.png align="center")

# ROS Topic and Message

The photos themselves are [Messages](http://wiki.ros.org/Messages) and they belong to the type [sensor\_msgs](http://wiki.ros.org/sensor_msgs). That's why you had to include *sensor\_msgs* when creating the package from the [last chapter](https://robodev.blog/ros-packages-and-workspace). The action of leaving photos on the Table is called **Publish** in ROS. Finally, the Table itself serves as a [ROS Topic](http://wiki.ros.org/Topics) to which other nodes can *subscribe*.

What is *subscribe*? Now imagine there is another person (i.e. another Node) in our story called the Photocopier. This guy wants to take photos from the Table and print them out. What is he going to do? He of course needs to notify the Boss first and then if there are photos on the Table, he can collect and print them. The action of taking photos from the Table is called **Subscribe** in ROS.

![ros_master_subscriber.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1670144596242/971gYqiIl.jpg align="center")

After notifying the Boss, both the Photographer and the Photocopier know about each other and they now just give/take photos to/from each other respectively.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1670276541104/v5KUWPlav.jpg align="center")

# ROS Service

In the previous section, the Photographer continuously publishes images while the Photocopier continuously subscribes to these images. The Photocopier now said only when he asked for an image, the Photographer should take one and send it to him. This request/reply interaction is basically the idea behind [ROS Service](http://wiki.ros.org/Services)**.** In our example, after both registrations (i.e. notifying the Boss) are done, the Photocopier acts as a Client sending a request to the Photographer who acts as a Server. After receiving the request, the Photographer grasps some images and sends them back to the Photocopier (actually he just leaves them on the Table as usual).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1670307838439/THveFzP9Y.png align="left")

Great job! You've just gone through all the core concepts of ROS. Of course, there are many more but for a beginner, it is already a big step. [Next](https://robodev.blog/write-a-ros-publisher), you will learn how to implement all of them and get your first ROS application running.

# Summary

1. "The **ROS Master** provides **naming and registration** services to the rest of the nodes in the ROS system. It tracks publishers and subscribers to topics as well as services" ([source](http://wiki.ros.org/Master)).
    
2. "A **node** is a process that performs computation." (source). Nodes can communicate with one another using **streaming topics (publish/subscribe)** or **services (client/server)**.
    

# Reference

1. Cover photo: [http://wiki.ros.org/fuerte](http://wiki.ros.org/fuerte)
    
2. Icons: [https://www.flaticon.com/](https://www.flaticon.com/)
