ros2_client library

A type-safe, streaming ROS 2 client for Dart and Flutter.

Speaks the rosbridge v2 protocol over WebSockets, so it runs everywhere Dart runs — Android, iOS, Linux, macOS, Windows and the browser — without needing a ROS installation on the client.

final ros = Ros2Client(Uri.parse('ws://192.168.1.10:9090'));
await ros.connect();

ros.subscribe<LaserScan>('/scan', qos: QosProfile.sensorData)
   .listen((scan) => print('${scan.ranges.length} beams'));

final cmdVel = ros.advertise<Twist>('/cmd_vel');
cmdVel.publish(Twist.drive(forward: 0.2, turn: 0.1));

Classes

ActionCodec<Goal, Feedback, Result>
Converter for a ROS 2 action's goal/feedback/result triple.
ActionRegistry
Registry of action codecs, keyed by Dart goal type.
Backpressure
What to do with messages that arrive while the consumer is busy.
BatteryState
sensor_msgs/msg/BatteryState.
BoolMsg
std_msgs/msg/Bool.
BridgeInfo
What a bridge can do, as reported by its own rosapi node.
ColorRGBA
std_msgs/msg/ColorRGBA.
CompressedImage
sensor_msgs/msg/CompressedImage — usually the cheapest way to stream a camera to a UI, since the payload is already JPEG/PNG and can be handed straight to a Flutter RosImage.memory.
EmptyMsg
std_msgs/msg/Empty.
Field
Field decoding helpers shared by all generated message classes.
Float64Msg
std_msgs/msg/Float64.
GoalHandle<Feedback, Result>
A handle to an in-flight action goal.
std_msgs/msg/Header.
Imu
sensor_msgs/msg/Imu.
Int32Msg
std_msgs/msg/Int32.
JointState
sensor_msgs/msg/JointState.
JsonMessage
An untyped message: a plain rosbridge JSON map.
LaserScan
sensor_msgs/msg/LaserScan.
MapMetaData
nav_msgs/msg/MapMetaData.
MessageCodec<T>
Bidirectional converter between a Dart type T and the rosbridge wire form.
MessageRegistry
Global registry of message codecs.
sensor_msgs/msg/NavSatFix.
NodeInfo
What a node publishes, subscribes to and serves.
OccupancyGrid
nav_msgs/msg/OccupancyGrid.
Odometry
nav_msgs/msg/Odometry.
Point
geometry_msgs/msg/Point.
PointCloud2
sensor_msgs/msg/PointCloud2.
PointCloudReader
Reads values out of a PointCloud2's packed buffer in place.
PointField
Registers every sensor_msgs codec. sensor_msgs/msg/PointField — one channel in a PointCloud2's blob.
Pose
geometry_msgs/msg/Pose.
PoseStamped
geometry_msgs/msg/PoseStamped.
QosProfile
A ROS 2 Quality of Service profile.
Quaternion
geometry_msgs/msg/Quaternion.
ReconnectPolicy
Controls retry timing after an unexpected disconnect.
Ros2Client
A ROS 2 client speaking the rosbridge v2 protocol.
RosDuration
builtin_interfaces/msg/Duration.
RosImage
sensor_msgs/msg/Image.
RosMessage
Marker for a generated (or hand-written) ROS 2 message type.
RosPath
nav_msgs/msg/Path.
RosPublisher<T>
A typed publisher bound to one topic.
RosStatus
A diagnostic message emitted by the rosbridge server.
RosTime
builtin_interfaces/msg/Time.
RosTransform
geometry_msgs/msg/Transform.
RosTransformStamped
geometry_msgs/msg/TransformStamped.
RosTransport
A bidirectional frame transport (WebSocket today, others later).
ServiceCodec<Req, Res>
Converter for a ROS 2 service's request/response pair.
ServiceRegistry
Registry of service codecs, keyed by Dart request type.
StringMsg
std_msgs/msg/String.
TfBuffer
A tf2 transform buffer: stores the frame tree and answers lookups.
TfListener
Keeps a TfBuffer fed from a robot's /tf and /tf_static topics.
TFMessage
tf2_msgs/msg/TFMessage — the payload of /tf and /tf_static.
TopicInfo
A topic name paired with its ROS type.
Twist
geometry_msgs/msg/Twist — the canonical velocity command.
Vector3
geometry_msgs/msg/Vector3.
WebSocketTransport
A RosTransport over a WebSocket, working on every Flutter target (mobile, desktop, and web, where dart:io is unavailable).
WireCodec
Decodes rosbridge frames off the wire into plain Dart structures.

Enums

Compression
Wire compression for subscriptions.
Durability
ROS 2 QoS durability policy.
GoalStatus
Terminal status of an action goal, mirroring action_msgs/msg/GoalStatus.
History
ROS 2 QoS history policy.
Liveliness
ROS 2 QoS liveliness policy. ROS 2 QoS liveliness policy.
Reliability
ROS 2 QoS reliability policy.
RosConnectionState
Lifecycle of a Ros2Client connection.
StatusLevel
Severity levels emitted by rosbridge status messages.

Extensions

PointMath on Point
QuaternionMath on Quaternion
Rigid-body maths on the geometry_msgs value types.
Ros2Introspection on Ros2Client
Live introspection of the ROS graph, via the rosapi node.
TransformMath on RosTransform
Vector3Math on Vector3

Functions

registerGeometryMsgs() → void
Registers every geometry_msgs codec.
registerNavMsgs() → void
Registers every nav_msgs codec.
registerSensorMsgs() → void
registerStandardMessages() → void
Registers codecs for the bundled std_msgs, geometry_msgs, sensor_msgs and nav_msgs types.
registerStdMsgs() → void
Registers every std_msgs / builtin_interfaces codec.

Exceptions / Errors

ActionFailedException
Thrown when an action goal is rejected or ends in a non-success state.
PointCloudFormatException
Thrown when a cloud's declared layout does not match the bytes it carries.
ServiceCallException
Thrown when a service call is rejected or fails on the ROS side.
TfException
Thrown when a transform cannot be resolved.
UnknownMessageTypeError
Thrown when a message type is used before its codec has been registered.