ROS 2 explained for web developers
ROS 2 has a reputation for being hard to get into. The docs talk about nodes, topics, DDS, QoS and colcon, and it all sounds like a new world.
Code: line_follower_ws on GitHub
ROS 2 has a reputation for being hard to get into. The docs talk about nodes, topics, DDS, QoS and colcon, and it all sounds like a new world. If you build web apps, though, you already know most of these ideas under other names. Here’s the translation, using the line follower I built in ROS 2 Humble.
The quick map
| ROS 2 | Closest web idea |
|---|---|
| Node | A small service or process with one job |
| Topic | A pub/sub channel, like a WebSocket room or a message queue topic |
| Message type | A TypeScript interface or JSON schema for what goes over the channel |
| Service | A request and response call, like a small HTTP endpoint |
| Action | A long-running job with progress updates and cancel |
| Package and package.xml | An npm package and package.json |
| colcon build | Building a monorepo with workspaces |
| source install/setup.bash | Loading the right environment, a bit like nvm use |
| Launch file | docker-compose: start several processes with their settings |
| rqt_graph | The network tab, showing who talks to whom |
Nodes and topics
My line follower has one node that does the thinking. It subscribes to camera frames and publishes driving commands:
class LineFollowerNode(Node):
def __init__(self):
super().__init__('line_follower')
self.bridge = CvBridge()
self.image_frame_subscriber = self.create_subscription(
Image, '/camera_sensor/image_raw', self.image_frame_callback, 10)
self.processed_image_frame_publisher = self.create_publisher(
Image, '/processed_frame', 10)
self.control_msg_publisher = self.create_publisher(
Twist, '/cmd_vel', 10)
If you squint, that’s an event handler on a socket:
socket.on('camera_sensor/image_raw', (frame) => {
const command = decide(frame);
socket.emit('cmd_vel', command);
});
The important difference is that nobody calls anybody. The camera doesn’t know the line follower exists, and the wheels don’t know who sends /cmd_vel. Each node publishes to a named topic, and whoever is subscribed gets the message. That’s what lets you swap the simulated camera for a real one without touching the controller.
Messages are typed
Every topic carries one message type. /cmd_vel uses geometry_msgs/msg/Twist, which you can inspect like an API schema:
ros2 interface show geometry_msgs/msg/Twist
Vector3 linear
float64 x
float64 y
float64 z
Vector3 angular
float64 x
float64 y
float64 z
For a wheeled robot, linear.x is forward speed in metres per second and angular.z is turning speed in radians per second. Using the standard types matters: any ROS tool or package that drives a robot already speaks Twist on /cmd_vel.
The CLI is your devtools
These commands do most of what the browser’s devtools do for a web app:
ros2 node list # what's running
ros2 topic list # which channels exist
ros2 topic echo /cmd_vel # watch messages as they go by
ros2 topic hz /camera_sensor/image_raw # how often frames arrive
ros2 topic pub --once /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.2}}"
That last one is like sending a request from Postman. It lets you test the wheels without the controller running at all. And rqt_graph draws every node and topic as a graph, which is the fastest way to spot a typo in a topic name. A subscriber on /cmd_vell gets no errors, just silence.
Launch files are docker-compose
Starting a robot means starting several processes together: the robot description publisher, the joint state publisher, the simulator and the step that spawns the robot into it. My gazebo.launch.py does exactly that, in Python. It’s the same job docker-compose does for a web stack: one command, many processes, each with its settings.
Where the analogy breaks
- Quality of service. Topics have QoS settings, roughly “reliable” or “best effort”. Camera drivers often publish best effort, because a dropped frame doesn’t matter. A subscriber that insists on reliable delivery won’t get anything from a best-effort publisher. You get one easy-to-miss warning about incompatible QoS in the log, and then nothing. If a topic shows up in ros2 topic list but your callback never fires, check QoS.
- Discovery is automatic. ROS 2 finds other nodes on your network by itself. Two robots on the same Wi-Fi will happily hear each other. Set a different ROS_DOMAIN_ID for each, the way you’d give two dev servers different ports.
- Time. In simulation, the clock is the simulator’s clock, not the wall clock. Nodes that should follow it need use_sim_time set to true, or timestamps won’t line up.
Where to start
Install ROS 2 Humble on Ubuntu 22.04, write one node that publishes a counter and one that prints it, and watch both in rqt_graph. Once that clicks, the rest of ROS 2 is mostly learning which packages already exist so you don’t write them yourself.