Nodes and Topics
Understanding Nodes
A Node is a single process that performs a computation. Nodes communicate with each other using Topics, Services, and Actions.
The Publisher (Talker)
We will create a simple "Talker" node that publishes a text message every second.
Code
See src/ros2_foundations/ros2_foundations/talker.py.
The Subscriber (Listener)
We will create a "Listener" node that subscribes to the topic and prints the message.
Code
See src/ros2_foundations/ros2_foundations/listener.py.
Running the Example
-
Build the package:
cd ~/ros2_ws
colcon build --symlink-install
source install/setup.bash -
Run Talker:
ros2 run ros2_foundations talker -
Run Listener:
ros2 run ros2_foundations listener