Multi-Robot Systems, HRI & Robot Software

publish–subscribe pattern

The publish–subscribe pattern, often shortened to pub/sub, is a simple and powerful way for programs to share information without being wired directly to one another. Instead of one program calling another by name, the producer of some data just posts it to a named channel, called a topic, and any program that cares about that topic quietly listens in and receives a copy. The producer is the publisher; each listener is a subscriber. The beauty is that neither side needs to know who the other is, how many there are, or whether anyone is listening at all.

A good everyday picture is a magazine. The publisher prints an issue and sends it out under a title — say, a weekly on gardening. Subscribers signed up for that title receive every issue at home; the magazine never needs to track each reader's daily whereabouts, and readers never phone the office to ask for content. New readers can subscribe and old ones can cancel without disturbing anyone else. In a robot, a camera node might publish images to a topic, while a face-detector, a recorder, and a display all subscribe to the same topic and each get every frame — and you can add a fourth listener later without touching the camera's code.

This loose coupling — programs joined through topics rather than tied to each other — is exactly why pub/sub is the backbone of robot software like ROS. It lets a robot's many parts be developed, started, stopped, and replaced independently, and it makes it easy to tap into a stream of data just to watch or debug it without disturbing the flow.

A robot's wheel encoders publish speed readings to a topic. The navigation node and a logging tool both subscribe; later, an engineer adds a live dashboard as a third subscriber — and the wheels' program never changes at all.

One publisher, many subscribers — add or remove listeners freely.

Pub/sub is a one-way broadcast: it is great for steady streams like sensor data, but when one program needs a direct question answered by another, robots use a separate request–reply style instead.

Also called
pub/subpublish-subscribe发布订阅發布訂閱