Type system
Rosbags ships its own pure python typesystem rosbags.typesys
. It uses parse trees to represent message definitions internally. It ships its own .idl
and .msg
definition parser to convert message definition files into the internal format.
Out of the box it supports the message types defined by the standard ROS2 distribution. Message types can be parsed and added on the fly during runtime without an additional build step.
Message instances
The type system generates a dataclass for each message type. These dataclasses give direct read write access to all mutable fields of a message. Fields should be mutated with care as no type checking is applied during runtime.
Note
Limitation: While the type system parses message definitions with array bounds and/or default values, neither bounds nor default values are enforced or assigned to message instances.
Included message types
builtin_interfaces
Duration
Time
diagnostic_msgs
DiagnosticArray
DiagnosticStatus
KeyValue
geometry_msgs
Accel
AccelStamped
AccelWithCovariance
AccelWithCovarianceStamped
Inertia
InertiaStamped
Point
Point32
PointStamped
Polygon
PolygonStamped
Pose
Pose2D
PoseArray
PoseStamped
PoseWithCovariance
PoseWithCovarianceStamped
Quaternion
QuaternionStamped
Transform
TransformStamped
Twist
TwistStamped
TwistWithCovariance
TwistWithCovarianceStamped
Vector3
Vector3Stamped
Wrench
WrenchStamped
libstatistics_collector
DummyMessage
lifecycle_msgs
State
Transition
TransitionDescription
TransitionEvent
rcl_interfaces
FloatingPointRange
IntegerRange
ListParametersResult
Log
Parameter
ParameterDescriptor
ParameterEvent
ParameterEventDescriptors
ParameterType
ParameterValue
SetParametersResult
rmw_dds_common
Gid
NodeEntitiesInfo
ParticipantEntitiesInfo
rosgraph_msgs
Clock
sensor_msgs
BatteryState
CameraInfo
ChannelFloat32
CompressedImage
FluidPressure
Illuminance
Image
Imu
JointState
Joy
JoyFeedback
JoyFeedbackArray
LaserEcho
LaserScan
MagneticField
MultiDOFJointState
MultiEchoLaserScan
NavSatFix
NavSatStatus
PointCloud
PointCloud2
PointField
Range
RegionOfInterest
RelativeHumidity
Temperature
TimeReference
shape_msgs
Mesh
MeshTriangle
Plane
SolidPrimitive
statistics_msgs
MetricsMessage
StatisticDataPoint
StatisticDataType
std_msgs
Bool
Byte
ByteMultiArray
Char
ColorRGBA
Empty
Float32
Float32MultiArray
Float64
Float64MultiArray
Header
Int16
Int16MultiArray
Int32
Int32MultiArray
Int64
Int64MultiArray
Int8
Int8MultiArray
MultiArrayDimension
MultiArrayLayout
String
UInt16
UInt16MultiArray
UInt32
UInt32MultiArray
UInt64
UInt64MultiArray
UInt8
UInt8MultiArray
stereo_msgs
DisparityImage
tf2_msgs
TF2Error
TFMessage
trajectory_msgs
JointTrajectory
JointTrajectoryPoint
MultiDOFJointTrajectory
MultiDOFJointTrajectoryPoint
unique_identifier_msgs
UUID
visualization_msgs
ImageMarker
InteractiveMarker
InteractiveMarkerControl
InteractiveMarkerFeedback
InteractiveMarkerInit
InteractiveMarkerPose
InteractiveMarkerUpdate
Marker
MarkerArray
MenuEntry
Extending the type system
Adding custom message types consists of two steps. First, message definitions are converted into parse trees using get_types_from_idl()
or get_types_from_msg()
, and second the types are registered in the type system via register_types()
. The following example shows how to add messages type definitions from .msg
and .idl
files:
from pathlib import Path
from rosbags.typesys import get_types_from_idl, get_types_from_msg, register_types
idl_text = Path('foo_msgs/msg/Foo.idl').read_text()
msg_text = Path('bar_msgs/msg/Bar.msg').read_text()
# plain dictionary to hold message definitions
add_types = {}
# add all definitions from one idl file
add_types.update(get_types_from_idl(idl_text))
# add definition from one msg file
add_types.update(get_types_from_msg(msg_text, 'bar_msgs/msg/Bar'))
# make types available to rosbags serializers/deserializers
register_types(add_types)