LESSON 05 · ROS 2

Publish and subscribe with meaningful messages

Inspect types and delivery settings rather than guessing at a stream.

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

  • Inspect a message type.
  • Publish and echo data.
  • Diagnose QoS mismatches.

Prerequisites: Nodes, packages and workspaces and its stated environment.

The idea, made clear.

A topic carries a typed stream. Publishers send without directly calling a chosen subscriber. A topic name is not its data contract: inspect the message definition before consuming it. Structured messages communicate units and geometry better than undocumented text.

Quality of Service settings describe reliability, durability and retained history. They do not guarantee correct sensor readings. A reliable subscriber may be incompatible with a best-effort publisher. Inspect endpoint settings when a topic exists but no data reaches your callback.

Use descriptive names and namespaces so several robots cannot accidentally share commands. Start with a String exercise, then choose standard sensor or geometry messages for real observations. Validate timestamps and frames as well as payload values.

PublisherTyped topicCompatible QoSSubscriber
An original overview of the information or commissioning sequence.

Try it, step by step.

1

Inspect String

Read the fields first.

topics-and-messages-1.txt
ros2 interface show std_msgs/msg/String

Expected: A string data field.

2

Send one sample

Quote the YAML request.

topics-and-messages-2.txt
ros2 topic pub --once /nexviora/status std_msgs/msg/String "{data: ready}"

Expected: One published sample.

3

Watch a stream

Use separate sourced terminals.

topics-and-messages-3.txt
ros2 topic pub --rate 2 /nexviora/status std_msgs/msg/String "{data: learning}"
# Other terminal:
ros2 topic echo /nexviora/status
ros2 topic info /nexviora/status --verbose

Expected: Repeated samples and endpoint QoS information.

Explore the interactive lab →

If something goes wrong

No samples
Check topic spelling, type, domain ID and QoS.
Invalid payload
Use fields from interface show and valid YAML quoting.

Check your understanding

What must endpoints agree on?

Make it yours

Compare a publisher with two subscribers in the lab and in ROS.

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