← All articles

FIELD NOTES / ZAPPD

ROS 2 for software engineers who need the robot to finish

Topics, services and actions describe different conversations. Their distinction helps software engineers reason about robot behavior.

A software engineer connecting a camera to an arm soon encounters a deceptively simple question. What does "done" mean? Receiving a request is different from starting a movement. Starting a movement is different from reaching the target. Reaching the target is different from completing the intended physical task.

ROS 2 gives these conversations more structure. Its interfaces help components exchange observations, requests and progress. Understanding those roles is a better introduction than treating ROS as a collection of packages to install.

The examples here describe a hypothetical tabletop sorting system. They explain interface choices rather than provide a complete control architecture or instructions for operating an arm.

Nodes divide responsibility

Think of a node as a participant with a defined responsibility in the robot's software system. A camera driver supplies observations. A perception component interprets them. A task coordinator decides what to attempt. A motion component handles a movement request.

This division is a design choice, not a requirement to create one operating system process for every small function. The useful question is whether each responsibility has a clear boundary and whether another participant can understand its outputs.

The official ROS interface documentation distinguishes topics for continuous streams, services for short request and response interactions, and actions for longer tasks with feedback. Their definitions describe different relationships between participants.

A familiar software analogy helps only up to a point. A robot's observations and commands have consequences in a changing physical environment. The time associated with a message can matter as much as its contents.

A stream does not promise completion

A camera image is a natural example of streaming data. A perception component can receive successive images as the scene changes. A task coordinator might subscribe to detected object information rather than request a new image through a blocking call every time it makes a decision.

In the sorting example, publishing an object position says that an estimate exists. It does not say that the arm accepted a request to pick up that object. It also does not say the estimate remains useful indefinitely.

Suppose the image was captured before an object moved. The position could be numerically well formed and still be unsuitable for the current decision. This is an illustrative failure, not a ROS specific defect. The application needs a policy for the age and context of observations.

That policy belongs in the design discussion early. If the coordinator cannot tell when an estimate was valid, it cannot make an informed choice about whether to use it.

Short requests differ from ongoing work

A short query for a component's configuration fits a request and response interaction. Moving an arm across the workspace has an ongoing lifecycle. The caller needs to know whether the goal was accepted, whether work is progressing and how the attempt ended.

The official action documentation describes goals, progress feedback and cancellation or preemption. These concepts let a caller represent an activity that continues after the initial request. The server is responsible for carrying out the procedure and responding to lifecycle requests.

For the sorter, a coordinator could request a placement action and observe its progress. If the surrounding situation changes, it could request cancellation. That request is part of the conversation. The physical system still needs a defined response and an observed outcome.

A cancellation message does not explain how a loaded mechanism should stop. Similarly, an action result needs an application meaning. "Trajectory completed" and "object is inside the tray" describe different evidence. A system that conflates them will report success too early.

Timing is a system property

It is tempting to think that choosing the right interface finishes the architecture. It establishes the shape of communication. It does not establish a deadline for the entire sequence.

Imagine that image acquisition, inference and motion planning each take variable time. Even if every component returns a correct result, the combined delay might make the observation stale. Looking at each component in isolation would miss the problem.

The useful measurement is therefore an end to end timeline. Record when the image was captured, when its interpretation became available, when a request was accepted and when motion began. These measurements locate the delay that affects the task. They also make an intermittent failure easier to investigate than an undifferentiated report that the robot is slow.

This article does not prescribe a real time control implementation. It argues that interface semantics and timing expectations should be documented together. A well named topic cannot compensate for an unspecified age limit on its data.

Start with one observable attempt

For a first ROS integration, describe one complete task attempt before adding more components. Name the observation the coordinator needs, the short queries it makes and the activity it asks another node to perform. Then define what success and failure mean to the application.

Include missing observations and interrupted work in that description. A robot that cannot complete a task still needs a comprehensible outcome. Once one attempt has an observable lifecycle, adding another sensor or task becomes a more specific change. The engineer can ask which conversation changes and how to recognize that the new behavior works.

Sources

← More from Zappd