Overview
Curated: · Written: · Reviewed:
ROS (Robot Operating System) Fundamentals
In one line
ROS 2 is middleware that lets robot components exchange typed topics, services and actions over DDS. Reach for it whenever you split a robot into components and must say how they connect, when their callbacks run, and what happens when a peer is slow, late or gone.
Key definitions
- Node: a graph participant with one coherent responsibility and lifecycle, not an OS process.
- Topic: one-to-many asynchronous stream governed by QoS. It has no requester, so you cannot prove anyone consumed it.
- Service: bounded request/response. The caller blocks or times out.
- Action: goal, feedback, cancellation and result. It is five DDS endpoints under a state machine.
- QoS: per-endpoint policies. The publisher's offer must satisfy the subscriber's request or no data flows.
- Executor and callback group: the executor runs ready callbacks. Mutually exclusive groups serialize, reentrant groups allow overlap.
- Lifecycle node: a managed node with explicit unconfigured, inactive, active and finalized states.
How it works
Discovery is peer-to-peer over DDS, with no master. Publisher and subscriber endpoints match per topic, and QoS compatibility decides whether data flows. The executor then runs callbacks one at a time within each mutually exclusive group, so one blocking callback delays everything queued behind it. Timers do not queue missed ticks: a 10 ms timer blocked by an 80 ms callback fires once when the executor frees up.
Worked late-joiner trace: a 50 Hz publisher with KEEP_LAST 1 and VOLATILE loses all 100 samples published during the 2 s before a subscriber joins. Switch to TRANSIENT_LOCAL with depth 1 and the subscriber gets one retained sample at match. Transient-local replays state, not history, and a retained stale command must never become valid just because it was retained.
When to use and when not to
| Choice | Use when | Avoid when |
|---|---|---|
| Topic | continuous streams, state, events | you need a reply or proof of consumption |
| Service | short bounded query within the caller's timeout | long work or continuous data |
| Action | cancellable long task that needs feedback | a one-shot query |
| Transient local | a late joiner needs current state | the message is a command that could be stale |
| Best-effort, shallow depth | sensor streams over lossy links | commands and configuration that must arrive |
| Separate callback group or process | a blocking or independent callback | shared state with no locking |
| Composition in one process | copy-heavy pipelines | you need crash isolation or separate resources |
Traps interviewers probe
- Mismatched QoS fails silently. A publisher offering BEST_EFFORT never reaches a RELIABLE subscriber, and there is no error, only a log warning. Fix: compare offered and requested policies with
ros2 topic info -vbefore debugging code. - A blocking callback starves timers and other subscriptions. Fix: give the slow callback its own mutually exclusive group on a MultiThreadedExecutor, or move it to its own process, and hand off to a bounded queue.
- Reliable does not mean on time. Retransmission adds delay and still fails under partition. Fix: best-effort with shallow depth for sensors, plus a deadline to detect staleness.
- An absolute remap ignores the namespace. A topic remapped to
/shared/imagestays there under__ns:=/front, while relative names follow the namespace. Fix: confirm the real endpoints withros2 node info. - Reentrant groups race on shared state. Fix: guard shared state with a mutex, or put the callbacks in one mutually exclusive group. For safety watchdogs, measure elapsed time on a steady clock, since a stepped system clock can make a 100 ms timeout fire early or late.
Interview tips
Opening: "Streams go on topics and cancellable long work goes on actions. I set QoS per contract, then check the executor and callback budget, time and frame authorities, and what happens on failure."
Expected follow-ups:
- How do you test QoS mismatch before deployment? Run integration tests over every offered and requested pair, plus late joins, loss and reconnect.
- How do you make a restart idempotent for physical effects? Do not replay stale goals, and gate publishers, timers and actuators behind activation.
- How do you secure a multi-robot deployment? Use DDS security with least-privilege policy per domain, topic and action. A namespace is not an authorization boundary.
30-second outline:
- Name the interface for each flow and why: topic, service or action, by delivery semantics.
- State QoS per contract: sensor streams best-effort with shallow depth, commands reliable, state transient-local only where a stale value is harmless.
- Place callbacks: which group, executor or process, so control never waits on I/O.
- Name the authorities: one publisher per dynamic transform edge, and a steady clock for timeouts.
- State the failure behavior: lifecycle gates activation, and the actuator stops when the watchdog expires.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.