ROS 2 Nodes tutorials

A Node in ROS 2 is a process that performs computation. Multiple nodes can be running at the same time and can communicate with each other. Each node in ROS has a unique name, and they can interact by publishing/subscribing to topics, calling services, or using actions.

Each node in ROS should be responsible for a single, modular purpose, e.g. controlling the wheel motors or publishing the sensor data from a laser range-finder. Each node can send and receive data from other nodes via topics, services, actions, or parameters.

A full robotic system is comprised of many nodes working in concert. In ROS 2, a single executable (C++ program, Python program, etc.) can contain one or more nodes.

Example: Creating and Running a Simple Node

Let's create a simple ROS 2 node in Python.

  1. Create a Python Script:

    • Open your ROS 2 workspace or create one:

    • Create a new file simple_node.py:

  2. Write a Simple Node:

    • Add this basic code to create a ROS 2 node that logs a message:

  3. Run the Node:

    • Make the script executable and run it:

    • The output will be:

    This shows that your node is running and logging messages to the console.

Last updated