ROS2 Sensor Messages
CameraInfo
sensor_msgs.CameraInfo — camera calibration and metadata.
Intrinsic matrix k (3×3, 9 elements), rectification r (3×3),
projection p (3×4, 12 elements), distortion d (variable length).
CompressedImage
sensor_msgs.CompressedImage — JPEG / PNG / etc. encoded image.
Same construction model as :class:Image: bulk data is copied
once at build time, then exposed read-only via :class:BorrowedBuf.
data
property
data: BorrowedBuf
Zero-copy view of the encoded image bytes.
format
property
format: str
Codec identifier — e.g. "jpeg", "png".
Image
sensor_msgs.Image — uncompressed raster image.
Construction copies the bulk data payload once into the CDR
buffer (GIL released during the copy). Read-side data returns a
:class:BorrowedBuf exposing the in-buffer payload via the buffer
protocol — zero-copy for np.frombuffer, memoryview, etc.
Example
::
import numpy as np
pixels = np.zeros((720, 1280, 3), dtype=np.uint8)
img = Image(
header=Header(stamp=Time(1, 0), frame_id="cam"),
height=720, width=1280, encoding="rgb8",
is_bigendian=0, step=1280 * 3,
data=pixels,
)
# Zero-copy view (Py 3.11+ / non-abi3):
arr = np.frombuffer(img.data, dtype=np.uint8).reshape(720, 1280, 3)
# On abi3-py38: arr = np.frombuffer(img.data.view(), dtype=np.uint8).reshape(720, 1280, 3)
data
property
data: BorrowedBuf
Zero-copy view of the pixel data.
step
property
step: int
Row stride in bytes.
cdr_view
cdr_view() -> BorrowedBuf
Zero-copy view of the full CDR buffer (header + payload).
to_bytes
to_bytes() -> bytes
Return the full CDR buffer as bytes (one copy).
Imu
sensor_msgs.Imu — orientation, angular velocity and linear
acceleration each with a 3×3 row-major covariance matrix.
Covariance matrices are exposed as 9-element list[float] (not
numpy) since they're small fixed-size and Python list semantics are
cleaner for this scale.
NavSatStatus
sensor_msgs.NavSatStatus — GNSS fix status + service bitmask.
Status (i8): -1 NO_FIX, 0 FIX, 1 SBAS_FIX, 2 GBAS_FIX.
Service bitmask (u16):
0x01 GPS, 0x02 GLONASS, 0x04 COMPASS, 0x08 GALILEO.
CdrFixed — 4 bytes payload (i8 + pad + u16, position-dependent alignment within composite messages).
NavSatFix
sensor_msgs.NavSatFix — GNSS position fix with covariance.
position_covariance_type constants:
0 = UNKNOWN, 1 = APPROXIMATED, 2 = DIAGONAL_KNOWN, 3 = KNOWN.
PointField
sensor_msgs.PointField — descriptor of one field within a
:class:PointCloud2's packed point layout.
datatype follows the ROS 2 spec:
1 INT8, 2 UINT8, 3 INT16, 4 UINT16, 5 INT32, 6 UINT32,
7 FLOAT32, 8 FLOAT64.
PointCloud2
sensor_msgs.PointCloud2 — packed point cloud with
:class:PointField descriptors.
data is a packed byte array of width × height points, each
point_step bytes wide. Field offsets/types come from the
fields list (set at construction or returned by the property).
Example
::
fields = [
PointField(name="x", offset=0, datatype=7, count=1), # float32
PointField(name="y", offset=4, datatype=7, count=1),
PointField(name="z", offset=8, datatype=7, count=1),
PointField(name="i", offset=12, datatype=2, count=1), # uint8
]
pc = PointCloud2(
header=Header(stamp=Time(1, 0), frame_id="lidar"),
height=1, width=131072, fields=fields,
is_bigendian=False, point_step=13, row_step=13 * 131072,
data=byte_buffer, is_dense=True,
)
data
property
data: BorrowedBuf
Zero-copy view of the packed point data.
RelativeHumidity
sensor_msgs.RelativeHumidity — relative humidity measurement (0–1 ratio).
Relative humidity as a dimensionless ratio in [0, 1] with a variance field.