🔹 1. Publisher & Subscriber (Pub/Sub model)

- Publisher: A node that sends data on a topic (topic carries message)
- msg = format of data
- topic = channel that carries that data
- Subscriber: A node that listens to a topic and receives that data.
📌 Example:
- A camera node publishes images on
/camera/image_raw
.
- A display node subscribes to
/camera/image_raw
and shows the image.
Message type (.msg
) defines what kind of data flows through a topic.
geometry_msgs/msg/Twist → linear & angular velocity
std_msgs/msg/String → simple string
🔹 2. Service (Request–Response)

- Different from pub/sub: communication is synchronous.
- One node requests something, another node responds.
📌 Example:
- A
turtlesim
client calls the /spawn
service → “please create a new turtle at (x, y).”
- The server responds → “ok, turtle2 created.”
Service type (.srv
) has two parts:
Request → input data
Response → output data
Example std_srvs/srv/Empty
: