graphic from ROS2 documentation on how nodes, publishers, subscribers, topics, messages work

graphic from ROS2 documentation on how nodes, publishers, subscribers, topics, messages work

Nodes

A node is a participant in the ROS 2 graph which uses a client library to communicate with other nodes. Nodes can communicate with other nodes. Each node should typically do one logical thing.

Nodes can publish to named topics (communication channels) to deliver data to other nodes, or subscribe to named topics to get data from other nodes. Nodes can provide configurable parameters to change behavior during run-time.

To run a node, use:

ros2 run <pkg_name> <node_name> [additional optional args]

Nodes — ROS 2 Documentation: Humble documentation

Messages

tl;dr : ROS Datatypes

Messages are a way for a ROS 2 node to send data on the network to other ROS nodes, with no response expected. For instance, if a ROS 2 node reads temperature data from a sensor, it can then publish that data on the ROS 2 network using a Temperature message. Other nodes on the ROS 2 network can subscribe to that data and receive the Temperature message.

Commonly used msg packages: std_msgs, geometry_msgs, sensor_msgs, trajectory_msgs, visualization_msgs, etc.

Messages are described and defined in .msg files in the msg/ directory of a ROS package. .msg files are composed of two parts: fields and constants.

Each field consists of a type and a name, separated by a space:

uint32 number_of_boxes
string street_name

Constants are defined with a type and a name separated by a space, followed by =value where value is the value of the constant.

int32 X=123
int32 Y=-123
string FOO="foo"
string EXAMPLE='bar'

Constant names must be entirely uppercase.

Further reading:

Interfaces — ROS 2 Documentation: Humble documentation

If you are creating your own message, you need to make some additional changes to the environment:

Creating custom msg and srv files — ROS 2 Documentation: Humble documentation