A simple ROS 2 publisher/subscriber example implemented in Python.
- ROS 2 (Humble or newer)
- Python 3.8+
- colcon build tools
In your first terminal:
colcon build --packages-select my_py_pubsub
In a second terminal:
source install/setup.bash
ros2 run my_py_pubsub talker
In a third terminal:
source install/setup.bash
ros2 run my_py_pubsub listener
[INFO] [minimal_publisher]: Publishing: "Hello World!"
[INFO] [minimal_publisher]: Publishing: "Hello World!"
[INFO] [minimal_subscriber]: I heard: "Hello World!"
[INFO] [minimal_subscriber]: I heard: "Hello World!"
ros2-hello-world-python/
├── src/
│ └── my_py_pubsub/
│ ├── my_py_pubsub/
│ │ ├── __init__.py
│ │ ├── publisher.py
│ │ └── subscriber.py
│ ├── package.xml
│ └── setup.py
└── README.md
This project is open-source and available under the MIT License.