1.2 Understanding ROS Core Concepts
Before diving into practical exercises, it’s essential to grasp the fundamental building blocks of ROS. These concepts form the foundation of how ROS works and how different parts of a robot's system communicate and function together. Let’s break them down in a beginner-friendly way.
Nodes
In ROS, a node is a basic unit of a robot’s system. A node is a process (or program) that performs a specific function or set of functions within the robot. In a simple robot, there could be many nodes, each handling a particular task. For instance:
One node might control the motors of the robot, responsible for movement.
Another node might process data from a sensor, such as a LIDAR or camera.
Each node performs independently, meaning they don’t directly depend on each other to function. However, they need to exchange information to work together efficiently. This is where communication mechanisms like topics, services, and actions come into play.
Example:
A node could be programmed to control a robot's wheel motors, adjusting their speed and direction.
Another node might handle the input from a LIDAR sensor, helping the robot detect obstacles.
Topics
In ROS, topics are used for unidirectional (one-way) communication between nodes. This means one node can publish information to a topic, and another node can listen to (subscribe to) that topic to receive the information. Topics are particularly useful when nodes need to continuously exchange data without waiting for a response. This type of communication is asynchronous, meaning the nodes don’t need to communicate at the same time.
Publishing: When a node sends information (e.g., sensor data or control commands), it is said to be "publishing" to a topic.
Subscribing: When another node receives this information by "subscribing" to the same topic.
Example:
A LIDAR node might publish data to a topic called
/lidar_scan. This data would contain information about the robot's surroundings, which another node (like a navigation node) could subscribe to in order to process the environment and decide the robot's next move.
Services
Services in ROS are used for two-way (bidirectional) communication between nodes, similar to calling a function in a traditional programming language. When one node needs to ask for information or perform a task and get an immediate response, it uses a service. Unlike topics, services are synchronous, meaning one node waits for the other to complete the requested task before continuing.
Request: One node sends a request for information or action.
Response: The other node processes the request and sends back a response.
Example:
A robot might have a node that monitors its battery level. Another node could request this service, asking, "What is the current battery level?" The battery-monitoring node would respond with the battery percentage.
Actions
Actions are similar to services but are used for tasks that take some time to complete. Unlike services, which wait for a quick response, actions allow for feedback during execution. For example, if the robot is moving to a specific location, the node sending the action can receive updates on the progress (e.g., "50% of the task is done"). Actions are useful when a task is not instantaneous, and you want to monitor its progress or possibly cancel the task if needed.
Example:
A robot’s motion controller might be given an action to move the robot to a specific position. The action could provide feedback during execution, such as "I am halfway to the destination" or "I encountered an obstacle."
ROS Master
The ROS Master is like the "brain" that coordinates all communication between nodes. It doesn't do any actual computation or data processing but plays an essential role in ensuring that all nodes can find each other and communicate. The ROS Master acts as a registry, where nodes can "register" themselves and say, "I am here and ready to communicate." Other nodes can then discover these registered nodes and start sending or receiving data.
When a node starts, it tells the ROS Master, "I want to publish data on this topic" or "I want to subscribe to this topic." The ROS Master connects the right nodes so they can exchange information.
The ROS Master is required for the system to run smoothly, but it does not need to stay constantly active after the nodes have established their connections.
Example:
If a robot has a LIDAR sensor node and a navigation node, both nodes will first register with the ROS Master. The LIDAR node tells the master it is publishing data on a certain topic, and the navigation node tells the master it wants to subscribe to that topic. The ROS Master ensures that these nodes find each other and start communicating.
Last updated