Atlas Robotics
Lesson 5/11 · about 12 min

Watch on YouTube ↗Watch on Facebook ↗

Message and interface: what the data looks like

A topic is a "pipe", and message is what flows in the pipe. Each topic only carries a fixed type message — /cmd_vel is always Twist, /scan is always LaserScan. Knowing how to read message types means knowing what a node needs and what it produces, before even reading its code.

After this lesson you will

  • Distinguish 3 types of interfaces: msg (topic), srv (service), action
  • Use ros2 interface show and ros2 topic info to manually look up the structure of any message
  • Understand header (stamp + frame_id) — two fields that decide the data "when measured, according to which coordinate system"
  • Immediately recognize about 10 types of messages that every autonomous robot uses

3 interface types

TypeDefinition fileUsed forStructure
msg.msgTopic (previous lesson)A block of data
srv.srvService (next lesson)Request --- Response
action.actionAction — long-running task with progress reports and cancellation (Module 12)Goal --- Result --- Feedback

The full name has 3 parts: package/type/Name, for example geometry_msgs/msg/Twist, std_srvs/srv/Empty, nav2_msgs/action/NavigateToPose.

Self-check the structure

ros2 interface show geometry_msgs/msg/Twist
Vector3  linear
	float64 x
	float64 y
	float64 z
Vector3  angular
	float64 x
	float64 y
	float64 z

Message in message: Twist includes 2 Vector3, each Vector3 includes 3 real numbers. Frequently used search commands:

ros2 topic type /cmd_vel              # What type does this topic contain?
ros2 topic info /scan --verbose       # type + who publishes + who subscribes + QoS
ros2 interface list | grep nav_msgs   # every interface in a package
ros2 interface show sensor_msgs/msg/LaserScan

header: when to measure, in what frame

Most sensor and position messages start with std_msgs/msg/Header:

builtin_interfaces/Time stamp    # the time the data was MEASURED (not the time it was sent)
string frame_id                  # coordinate system of data, eg "lidar_link", "odom", "map"
  • frame_id: point 2 m from robot — where is 2 m from? /scan with frame_id: lidar_link means the distance measured from the LiDAR center. To know where that point is on the map, TF2 (Module 2) changes from lidar_link to map.
  • stamp: the robot is moving; its position changes every millisecond. TF2 uses stamp to look up transform at the exact time of measurement. Wrong stamps (e.g. off-clock, or using real time in simulation — see use_sim_time in Module 4) cause the classic "extrapolation into the future/past" error.

type with additional header usually has suffix Stamped: Pose → PoseStamped, Twist → TwistStamped.

~10 message types of every autonomous robot

Typical topictypeWhat to carry
/cmd_velgeometry_msgs/msg/TwistVelocity command (m/s, rad/s)
/odomnav_msgs/msg/OdometryPose + velocity from odometry, with covariance
/scansensor_msgs/msg/LaserScanArray of LiDAR distances by angle
/imusensor_msgs/msg/ImuOrientation, angular velocity, acceleration
/joint_statessensor_msgs/msg/JointStateAngle/speed of each joint (wheel)
/tf, /tf_statictf2_msgs/msg/TFMessageTransforms between frame
/mapnav_msgs/msg/OccupancyGridOccupancy grid map
/goal_posegeometry_msgs/msg/PoseStampedGoal pose (RViz "Nav2 Goal")
/initialpose, /amcl_posegeometry_msgs/msg/PoseWithCovarianceStampedPose with uncertainty
/plannav_msgs/msg/Pathpath calculated by planner

Publisher and subscribers on the same topic must have the same type. Sending TwistStamped to a node waiting for Twist gives no error — the data simply doesn't arrive. The exact use_stamped_vel issue is documented in diff_drive_controller.yaml of Atlas (Module 5). If you encounter "node not receiving data", check ros2 topic info -v first.

Custom message

When there is no suitable type, create the file .msg in a separate package (usually named *_interfaces), for example BatteryStatus.msg:

std_msgs/Header header
float32 voltage
float32 percentage
bool charging

The interface package must be built with ament_cmake + rosidl_generate_interfaces(...) in CMakeLists.txt (even if the node using it is written in Python). Advice: use the standard type before defining it yourself — the standard type is already understood by RViz, rosbag and all other tools.

Self-check

How do msg, srv, and action differ?

msg: a block of data, used for topic. srv: request/response pair, used for service. action: goal/result/feedback, used for long-running tasks with progress reports and cancellation.

How do I know what type the topic /scan contains and what fields it has?

ros2 topic type /scan (or ros2 topic info /scan) to get the type, then ros2 interface show sensor_msgs/msg/LaserScan to see the fields.

What are header.stamp and header.frame_id used for?

stamp: the time the data was measured — TF2 is used to look up the transform at that time. frame_id: coordinate system of data — shows where the measurement comes from.

Node A publishes TwistStamped to /cmd_vel, node B subscribes to Twist. Are there any errors that appear?

There is usually no obvious error — B simply did not receive the data. You must check the type yourself with ros2 topic info -v.

Messages & interfaces: what the data looks like · Module 1: ROS 2 Core Concepts — Atlas Robotics