A ROS Message is a strictly typed data structure, defined in a .msg file, that is used for serialization and deserialization when publishing to ROS Topics or calling ROS Services. Each .msg file defines a compound type by listing its fields—such as standard primitives (e.g., string, int32, float64) or other message types—enabling nodes to exchange structured data with a shared, language-agnostic schema. This definition is compiled by the ROS build tools into language-specific code (e.g., C++ classes, Python modules) that handles the binary conversion for network transmission.
Glossary
ROS Message (.msg)

What is ROS Message (.msg)?
A ROS Message is the fundamental unit of data exchange in the Robot Operating System (ROS), providing strict typing and serialization for inter-process communication.
The .msg file format enforces data contract reliability across a distributed system, ensuring that publishers and subscribers agree on the structure and semantics of the information being passed. Common patterns include wrapping sensor readings (like sensor_msgs/Image for camera data or geometry_msgs/Twist for velocity commands) or composing complex state information. This strict typing is central to ROS's middleware function, allowing for tooling like rosbag for recording and the rostopic echo command for introspection, while providing the deterministic foundation necessary for real-time robotic control systems.
Core Characteristics of ROS Messages
A ROS Message (.msg) is the fundamental unit of data exchange in the Robot Operating System. It is a strictly typed, serializable data structure defined in a simple text file.
Definition and Serialization
A ROS Message is a strictly typed data structure defined in a .msg file. Its primary purpose is serialization—converting complex data into a flat byte stream for transmission over a network or storage in a ROS Bag. The .msg file serves as a contract between publishing and subscribing nodes, ensuring data integrity. For example, a common sensor message like sensor_msgs/Image serializes header information, image height/width, encoding, and raw pixel data into a single byte array for efficient transport.
Primitive and Built-in Types
ROS Messages are composed of primitive field types that map directly to programming language primitives. The core built-in types include:
- Numeric types:
int8,uint32,float64 - Boolean:
bool - String:
string - Time/Duration:
time,duration - Raw byte array:
byte,charThese types ensure predictable memory layout and cross-language compatibility. For instance, afloat64in a.msgfile will deserialize to adoublein C++ and afloatin Python.
Arrays, Bounded Arrays, and Constants
Messages support complex field modifiers for flexible data structuring.
- Unbounded Arrays: Defined with
[](e.g.,float32[] ranges), these are variable-length sequences. - Bounded Arrays: Defined with a fixed size
[N](e.g.,float64[3] position), which serializes to a known, fixed block of bytes, improving memory predictability. - Constants: Allow defining immutable values within the message (e.g.,
uint8 SUCCESS=0). These constants are compiled into the generated code and are accessible to nodes using the message type.
Message Composition and Nested Types
Messages can be composed of other message types, enabling hierarchical and complex data structures. This is a key mechanism for code reuse and standardization.
- Field Composition: A message can have a field of another message type (e.g.,
geometry_msgs/Pose pose). - Standard Message Definitions: The ROS ecosystem provides common package libraries (like
std_msgs,geometry_msgs,sensor_msgs) with widely adopted message definitions. For example,sensor_msgs/LaserScancomposes astd_msgs/Header, float arrays for ranges and intensities, and scan parameters.
Code Generation and Language Support
The .msg file is not used directly in code. Instead, the ROS build toolchain (colcon) uses a message generator to produce language-specific source code.
- C++: Generates a header and source file defining a class with getter/setter methods for each field.
- Python: Generates a Python module with a class definition.
- Other Languages: Support for Rust, Java, etc., via additional generators.
This process ensures that a node written in C++ can seamlessly exchange a
Twistmessage with a node written in Python, as both use the same binary on-the-wire format.
Relationship to Topics, Services, and Actions
Messages are the payload for ROS's core communication mechanisms.
- Topics: Use messages for asynchronous, one-way streaming (publish/subscribe).
- Services: Use a pair of messages: one for the request and one for the response, defined in a
.srvfile. - Actions: Use three message types defined in an
.actionfile: a Goal, a Result, and periodic Feedback. This unified typing system means ageometry_msgs/Twistmessage can be published to a/cmd_veltopic for robot control, or used as part of a service call, with identical serialization.
How ROS Messages Work
A ROS Message is the fundamental unit of data exchange in the Robot Operating System, enabling deterministic communication between nodes.
A ROS Message is a strictly typed data structure, defined in a .msg file, that is used for serialization and deserialization when publishing to topics or calling services. Each message is composed of primitive fields (e.g., int32, float64, string) or other nested message types, forming a contract that ensures data integrity across the distributed system. The .msg definition is compiled into language-specific code (e.g., C++, Python) by the ROS build tools, providing developers with type-safe classes for constructing and parsing message data.
Messages enable the publish-subscribe and request-response communication models central to ROS. When a node publishes a message to a topic, it is serialized into a standard byte stream, transmitted, and then deserialized by subscribing nodes. This mechanism allows for loose coupling between system components. For complex or long-running tasks, the ROS Action protocol builds upon basic messages, using dedicated goal, feedback, and result message types to manage stateful interactions between clients and servers.
Common ROS Message Examples
ROS Messages are the fundamental data packets for communication. These examples illustrate the most common, standardized message types used across perception, control, and state estimation.
geometry_msgs/Twist
A message for expressing velocity in free space, broken into linear and angular components. It is the primary command message for mobile robot base control.
- Linear: A 3D vector (
x,y,z) for velocity in meters per second. For a differential-drive robot, typically onlylinear.xis used for forward/backward motion. - Angular: A 3D vector (
x,y,z) for rotational velocity in radians per second. For a differential-drive robot, typically onlyangular.zis used for turning (yaw).
Example: Commanding a TurtleBot3 to move forward at 0.2 m/s while turning left at 0.5 rad/s would set {linear: {x: 0.2, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.5}}.
sensor_msgs/Image
The standard message for transmitting raw or compressed image data from cameras. It contains critical metadata alongside the pixel array.
- Header: Includes a timestamp and frame ID for synchronization and transformation (
tf). - Height/Width: Image dimensions in pixels.
- Encoding: A string defining the pixel format (e.g.,
rgb8,bgr8,mono8). - is_bigendian: Byte order of the data.
- step: Full row length in bytes (
width * num_channels * bytes_per_channel). - data: The actual pixel array as a sequence of bytes.
This message is consumed by vision nodes for tasks like object detection, visual SLAM, and semantic segmentation.
nav_msgs/Odometry
A message that estimates the position and velocity of a robot in a coordinate frame (often odom or map). It is a core output of localization systems.
- Header: Timestamp and child frame ID (typically the robot's base frame, e.g.,
base_link). - Pose: Contains the estimated position (
pose.pose.position) and orientation (pose.pose.orientationas a quaternion) along with a covariance matrix (pose.covariance). - Twist: Contains the estimated linear and angular velocity (
twist.twist) with its own covariance matrix (twist.covariance).
Related Topic: Often published on the /odom topic and used by the navigation stack for feedback control.
sensor_msgs/LaserScan
A single scan from a planar range-finder (e.g., a 2D LiDAR). It represents distance measurements at fixed angular intervals in a plane.
- angle_min/max: The start and end angles of the scan (in radians).
- angle_increment: The angular distance between measurements.
- time_increment: Time between measurements (if scanning is sequential).
- scan_time: Time between complete scans.
- range_min/max: Valid range limits for the sensor.
- ranges: An array of measured distances. Values outside
[range_min, range_max]are considered invalid. - intensities: Optional array of reflection intensity values.
This is a primary input for obstacle avoidance, SLAM, and 2D mapping algorithms.
geometry_msgs/PoseStamped
A Pose (position and orientation) with a Header, allowing it to be associated with a specific coordinate frame and timestamp. It is used for specifying goals and publishing localized poses.
- Header: Contains
stamp(ros::Time) andframe_id(string, e.g.,map). - Pose: A
geometry_msgs/Poseobject containing:position: APoint(x,y,zcoordinates).orientation: AQuaternion(x,y,z,wcomponents).
Common Use Cases:
- Sending a navigation goal to
move_base. - Publishing the estimated robot pose from a localization filter.
- Defining waypoints in a task plan.
std_msgs/Header
Not a standalone message, but a critical sub-message included in almost all sensor and state messages. It provides essential metadata for data synchronization and transformation.
- seq: A consecutively increasing sequence ID (deprecated in ROS 2 in favor of timestamps).
- stamp: A
ros::Timeorbuiltin_interfaces/Timeobject representing the acquisition time of the data. This is crucial for sensor fusion. - frame_id: A string identifying the coordinate frame in which the data is expressed (e.g.,
base_link,camera_color_optical_frame). This is essential for the TF2 transform library to correctly interpret the data's spatial context.
Understanding the Header is fundamental to building robust, temporally consistent robotic systems.
Frequently Asked Questions
A ROS Message is the fundamental data structure for communication in the Robot Operating System. These frequently asked questions cover its definition, usage, and role in building robust robotic software.
A ROS Message is a strictly typed data structure, defined in a .msg file, that is used for serialization and deserialization when publishing to topics or calling services. It works by providing a common language for nodes to exchange information. A .msg file defines the data fields and their types (e.g., string, int32, float64[]). The ROS client libraries (like rclcpp for C++ or rclpy for Python) use these definitions to automatically generate source code for message classes. These classes include methods to serialize the data into a compact byte stream for network transmission and to deserialize incoming byte streams back into structured objects that the node's logic can process. This mechanism ensures data consistency and interoperability between nodes written in different programming languages.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
A ROS Message (.msg) is a fundamental data structure, but it operates within a broader ecosystem of communication patterns and system components. These related concepts define how messages are used, managed, and transformed within a robotic system.
ROS Topic
A named bus for the asynchronous, many-to-many exchange of ROS Messages using a publish-subscribe model. Nodes publish messages to a topic, and any number of subscribing nodes can receive them, enabling decoupled, streaming data flow (e.g., sensor data, velocity commands).
- Primary use: Streaming data where timing is critical but immediate acknowledgment is not required.
- Example: A
/camera/image_rawtopic publishingsensor_msgs/Imagemessages.
ROS Service
A synchronous, request-response communication mechanism. A client node sends a service request message and blocks until it receives a service reply message from the server node. Services are defined by a pair of .srv files (request and reply).
- Primary use: Remote procedure calls (RPC) for operations that require a direct, blocking response.
- Example: A
/get_mapservice where the request is empty and the reply is anav_msgs/OccupancyGridmessage.
ROS Action
An asynchronous interface for long-running, goal-oriented tasks. Built on topics, it uses three message streams: a client sends a goal, the server streams periodic feedback, and finally sends a result. Defined by a .action file.
- Primary use: Tasks like navigation or manipulation that take time and require progress updates or preemption.
- Example: A
MoveBaseaction for sending a navigation goal and receiving feedback on the robot's progress.
ROS Parameter
A configuration value (integer, string, boolean, etc.) stored on a central or node-specific parameter server. Parameters are not messages but are a key-value store for runtime configuration that nodes can retrieve, set, and monitor.
- Primary use: Tuning system behavior without recompiling code (e.g., control gains, timeout values).
- Contrast with Messages: Parameters are for configuration; messages are for dynamic data flow between nodes.
ROS IDL (Interface Definition Language)
The collective term for the definition file formats (.msg, .srv, .action) that specify the data structures for ROS communication. These files are the source of truth from which language-specific code (e.g., C++, Python classes) is automatically generated.
- Core Files:
.msgfor topics,.srvfor services,.actionfor actions. - Process: The
rosidltoolchain parses these files to create bindings, ensuring type safety across the entire ROS graph.
Serialization & Deserialization
The core technical process enabled by the ROS Message definition. Serialization (marshalling) converts an in-memory message object into a compact byte stream for network transmission or recording. Deserialization (unmarshalling) reconstructs the object from the byte stream on the receiving end.
- Mechanism: The generated message code includes methods for these operations.
- Critical For: Network communication (ROS topics/services) and data logging (ROS bags).

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us