LESSON 06 · ROS 2

Choose a topic, service or action

Choose communication based on task duration and feedback needs.

Environment and verification

Documented target: Ubuntu 24.04 · ROS 2 Jazzy · Gazebo Harmonic where used. Browser labs tested; ROS/Ubuntu/hardware execution not performed here.

What you will understand

  • Choose the right interface.
  • Call a simulation service.
  • Read an action contract.

Prerequisites: Publish and subscribe with meaningful messages and its stated environment.

The idea, made clear.

Topics suit ongoing data streams. Services suit bounded requests with one response. Actions suit longer tasks that need progress and cancellation, such as navigation. Do not substitute a blocking service for a mission that needs supervision.

An interface is a contract. Service definitions separate request and response with ---. Action definitions have goal, result and feedback sections. Document units and ranges. Custom ROS interfaces need generation metadata and rosidl dependencies in an appropriate package.

Clients must handle unavailability and timeouts. Executors and callbacks affect responsiveness; merely choosing an action interface does not implement cancellation in the server. Inspect actual behavior and failure responses.

Goal/requestServerFeedbackResult
An original overview of the information or commissioning sequence.

Try it, step by step.

1

Inspect turtlesim

Install turtlesim if absent and run its node.

services-actions-interfaces-1.txt
ros2 run turtlesim turtlesim_node
# Other terminal:
ros2 service list
ros2 interface show turtlesim/srv/Spawn

Expected: The /spawn contract.

2

Spawn a turtle

Call the running simulation.

services-actions-interfaces-2.txt
ros2 service call /spawn turtlesim/srv/Spawn "{x: 3.0, y: 3.0, theta: 0.0, name: learner}"

Expected: A named second turtle.

3

Design an action

Design only; this is not a generated package.

services-actions-interfaces-3.txt
float64 distance_m
---
bool reached
---
float64 remaining_m

Expected: Goal, result and feedback with units.

Explore the interactive lab →

If something goes wrong

Service waits
Check that the server is running and the name matches.
Action does not cancel
Inspect server cancellation handling.

Check your understanding

Which fits a cancellable navigation mission?

Make it yours

Classify a laser stream, reset request and docking task.

Your learning progress

Optional progress stays in this browser. No account needed.

Go to the source documentation

Commands are educational examples for the stated environment, not a transcript of local ROS execution. Verify actual behavior on your machine.

Look up a term · Version notes · Report an issue