Lesson 11 of 2255 minutes

Services, Actions, and Parameters

Start with the lesson question, connect the representations, and test the model with evidence.

ros2topicsservicesactionsparametersinterface designobservability

Learning objectives

  • Explain nodes, messages, topics, services, and actions.
  • Select the appropriate ROS 2 communication pattern for a task.
  • Inspect and diagnose a small robot computation graph.
Lesson flowHook, model, explanationShow guidance

Inspect the opening phenomenon

Predict what changes, then name the evidence.

Apply in the lab

Name the evidence before reading the answer.

Read only what helps

Then use the lab and recall check.

More when needed

Transcript and resources stay available below.

Course progress

AI & Robotics Foundations · Programming Robot Systems with ROS 2 Concepts · Lesson 11

Services, Actions, and Parameters

In progress

Decision challenge

Observe the phenomenon. Then connect the representations.

Use the opening example to make a prediction, identify evidence, and explain which model supports it.

ROS 2 Service or Action: Which Should You Use?

Choose an interface for a 40-second docking goal that needs feedback and cancellation.

Before

Choose an interface for a 40-second docking goal that needs feedback and cancellation.

During

Track communication shape, duration, feedback, and cancellation.

After

Explain why a docking action is not merely a slow service.

Reference drawerTranscript, source notes, scripts, and package status stay tucked away until you need them.7 files

Lesson reading

live

55 min

Video script

draft

Transcript fallback

available

courses/ai-robotics/modules/04-programming-robot-systems-with-ros2/lessons/02-services-actions-and-parameters/video-transcript.md

Choose a ROS 2 Interface Lab

draft

30 min

Mastery check

live

7 questions / 10 min

Book section:courses/ai-robotics/modules/04-programming-robot-systems-with-ros2/lessons/02-services-actions-and-parameters/book-section.md
Transcript for accessibility and fallback

# Transcript Docking takes forty seconds. The operator needs progress and a cancel button. Service or action? Use an action. A topic carries a continuing stream such as camera, lidar, or odometry. A service is one quick request and response, such as reset or query. An action owns a long-running goal: accept it, report feedback, return a result, and allow cancellation. A parameter configures a node, such as maximum speed or controller gains. Stream, quick answer, long goal, configuration. Classify the communication shape before choosing the ROS 2 interface.

Reading lab

Core explanation

Connect the lesson's words, diagrams, graphs, evidence, and equations.

The 40-second docking challenge

A mobile robot must reach its dock. The operation takes about 40 seconds. The operator needs progress updates and must be able to cancel if a person blocks the route.

Choose before reading on: topic, service, action, or parameter?

The best answer is an action. Docking is a goal with a lifecycle: accepted, executing, producing feedback, then succeeded, aborted, or canceled. A service is designed for a short request and response—not a long process that may need interruption.

ROS 2 interface decision guide

Four interfaces, four jobs

InterfaceCommunication shapeBest forRobot example
Topicasynchronous publish/subscribecontinuous observations or state, often with several consumers/scan, camera frames, odometry
Servicerequest → quick responseshort operations that return an answerreset odometry, query a map name
Actiongoal → feedback → result, with cancellationwork that takes time and has a lifecyclenavigate, dock, manipulate
Parameternamed value owned by a nodeconfiguration, tuning, and startup/runtime settingsmax_speed, frame_id, controller gains

Use this decision rule:

  1. Is it a continuing stream of samples? Use a topic.
  2. Is it a quick request that returns one answer? Use a service.
  3. Is it a long-running goal that needs progress or cancellation? Use an action.
  4. Is it configuration that changes how one node behaves? Use a parameter.

Why an action is not just a slow service

A service client usually waits for a server to perform a short computation and reply. ROS 2's official service guidance says services should return quickly and should not be used for long-running work that may need preemption.

An action exposes the lifecycle deliberately:

client -- goal --> action server
client <-- accepted/rejected -- server
client <-- feedback ----------- server
client -- cancel request -----> server   (optional)
client <-- final result -------- server

Feedback answers “how is it going?” A result answers “how did it finish?” Cancellation requests that the server stop the active goal safely. These are different pieces of evidence and should not be collapsed into one delayed response.

Read the goal state, not just the animation

The ROS 2 action design gives every accepted goal a state machine. Active states are ACCEPTED, EXECUTING, and CANCELING. Terminal states are SUCCEEDED, ABORTED, and CANCELED. A rejected goal never enters that state machine.

ObservationWhat it provesWhat it does not prove
Goal acceptedthe server agreed to attempt this goalthat motion has started or will succeed
Feedback receivedthe server reports progress for this goalthat the feedback matches physical reality
Cancel acceptedthe server agreed to begin cancellationthat cleanup and stopping are complete
SUCCEEDED resultthe server reports successful completionphysical safety unless separately observed
ABORTED resultthe server terminated the goal internallythe cause without logs and supporting evidence

This separation prevents a common UI mistake: showing “done” immediately after goal acceptance rather than after a terminal result.

Worked robot architecture

Imagine a warehouse robot:

  • A lidar node publishes /scan as a topic because measurements arrive continuously and localization plus obstacle avoidance both consume them.
  • A localization node offers /reset_odometry as a service because the caller makes one request and expects a quick acknowledgement.
  • Navigation exposes /navigate_to_pose as an action because travel takes time, produces progress, and may need cancellation.
  • A controller owns max_speed as a parameter because it configures behavior; it is not a stream of drive commands.

A useful boundary test

Ask what happens if the work lasts ten times longer than expected.

  • For a service, a long delay leaves the client waiting without a standard progress channel.
  • For an action, the client can keep receiving feedback and can request cancellation.

That makes duration, progress, and interruptibility architectural requirements—not implementation details.

Common design mistakes

Streaming sensor data through a service

Repeatedly polling a service for camera frames hides a continuous data stream inside repeated request/response calls. A topic states the true relationship and allows multiple subscribers.

Treating a parameter as a command bus

max_speed=0.5 is configuration. “Drive forward now” is an operational command. Parameters should not disguise time-sensitive commands or event streams.

In ROS 2, each node maintains its own parameters. Values can be provided at startup with --ros-args -p, loaded from YAML, queried, changed, and monitored for parameter events. That machinery makes parameters useful for explicit node settings, but it does not turn them into a replacement for a topic, service, or action.

Assuming availability means success

A discovered service or action server only proves an endpoint exists. Your evidence must still include response semantics, action status, feedback, result code, and robot behavior.

Evidence checklist

Before accepting an interface design, write down:

  • frequency: once, occasionally, or continuously;
  • expected duration and timeout;
  • whether feedback is valuable;
  • whether cancellation or preemption is required;
  • number of producers and consumers;
  • whether the data is configuration or operation;
  • observable success and failure evidence.

Retrieval practice

Classify each interaction:

  1. A 20 Hz joint-state feed → topic
  2. Clear a costmap and report whether the request was accepted → service
  3. Move an arm to a pose with percent-complete feedback → action
  4. Set the controller's acceleration limit → parameter

Now explain each answer using communication shape—not merely the example name.

Sources and further study

External sources are linked and cited for learning; no third-party text, figures, or footage are republished.

Practice labChoose a ROS 2 Interface LabOpen this when you are ready to apply the model, collect evidence, and check your explanation.30 min

Objective

Defend interface choices using frequency, duration, feedback, cancellation, fan-out, and configuration semantics.

Scenario

You are reviewing a delivery robot design. The team proposes a service for everything.

Materials

  • Text editor, spreadsheet, or paper
  • Lesson decision visual and evidence table
  • Optional ROS 2 installation with turtlesim for the CLI extension

Steps

  1. Classify each interaction and justify its communication shape.
  2. Repair the all-services design.
  3. Build the requested failure-evidence table.
  4. Trace the action lifecycle and compare cancellation with abort.
  5. Optionally inspect equivalent ROS 2 interfaces with the CLI.

Part 1 — Classify

For each interaction, choose topic, service, action, or parameter and write one sentence of evidence.

  1. Publish battery state every second.
  2. Ask whether a named map is loaded.
  3. Navigate to room 214 with live remaining distance and cancel.
  4. Configure the local planner's maximum velocity.
  5. Stream camera frames to perception and recording.
  6. Reset a localization estimate and return acknowledgement.
  7. Execute a 25-second grasp with stage feedback.
  8. Configure the robot base frame name at startup.

Part 2 — Repair the design

The current design polls GetLatestCameraFrame ten times per second and calls DockRobot, a service that may block for two minutes.

  • Replace the camera service with a typed topic and name two subscribers.
  • Replace docking with an action. Define one goal field, two feedback fields, and three possible terminal outcomes.
  • Identify one docking value that belongs in a parameter instead.

Part 3 — Failure evidence

Create an evidence table with columns: interface, success evidence, failure evidence, timeout, and operator response.

Part 4 — Simulate an action lifecycle

No ROS installation is required. Trace these events on paper or in a text file:

00 s  client sends Dock goal
01 s  server accepts goal
05 s  feedback: 3.2 m remaining
12 s  feedback: 1.6 m remaining
14 s  obstacle appears
15 s  client requests cancel
16 s  server accepts cancel request
18 s  server reports CANCELED

For every event, record:

  1. the goal state you can justify;
  2. the evidence visible to the operator;
  3. one conclusion that would still be unsafe to assume.

Then change the final event to ABORTED. Explain how the operator response and evidence request should change.

Optional ROS 2 CLI extension

If ROS 2 and turtlesim are available, inspect the action graph rather than controlling hardware:

ros2 action list -t
ros2 action info /turtle1/rotate_absolute
ros2 interface show turtlesim/action/RotateAbsolute
ros2 action send_goal --feedback /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"

Capture the action name/type, goal fields, feedback, and terminal result. Do not treat terminal status alone as proof of a safety-critical physical outcome.

For a service comparison, inspect rather than repeatedly poll:

ros2 service list -t
ros2 service type /clear
ros2 service info /clear
ros2 interface show std_srvs/srv/Empty

Record the request type, response type, and server count. Service-event echoing requires introspection support to be enabled; absence of echoed traffic is therefore not automatically evidence that no calls occurred.

Expected Result

A strong submission should include these design decisions:

  • battery state and camera frames are topics because new samples continue to arrive;
  • map query and odometry reset are services because each is a bounded request with a prompt response;
  • navigation and grasp are actions because each has a goal lifecycle, useful feedback, and cancellation;
  • maximum velocity and frame name are parameters because they configure node behavior;
  • the docking action distinguishes goal rejection, cancellation, abort, and success.

Troubleshooting the reasoning

  • If every answer is “service,” ask whether the client is polling a hidden stream or waiting through long work without progress.
  • If every answer is “topic,” ask who owns the result and how a caller knows that a specific request finished.
  • If a parameter sounds like a verb—drive_now, grip_object, or stop_robot—it is probably disguising an operation.
  • If duration is uncertain, design from the worst credible duration and the need for cancellation, not the happy-path average.

Accessibility and hardware-free option

No ROS 2 installation or robot is required. Complete the classification and evidence table with a text editor, spreadsheet, or paper. The lesson transcript and decision table provide the same concepts as the video. A screen-reader user may describe each interface as a communication sequence instead of drawing arrows.

Success criteria

  • Every choice states the communication shape.
  • Long-running work exposes feedback and cancellation.
  • Configuration is separated from operational commands.
  • The design names observable success and failure evidence.
  • The submission remains usable without video or physical hardware.

Reflection Questions

  1. Why does a long duration alone not fully determine whether an interaction should be an action?
  2. What additional evidence is required after an action reports CANCELED?
  3. How can repeated service polling hide a topic-shaped data stream?

Extension Challenge

Design an interface contract for a one-minute grasp task. Define its goal, two feedback fields, terminal outcomes, cancellation behavior, one configuration parameter, and the physical evidence required before declaring success.