ros2_client 0.3.0
ros2_client: ^0.3.0 copied to clipboard
A type-safe, streaming ROS 2 client for Dart and Flutter. Topics, services, actions, parameters and introspection over rosbridge.
Changelog #
0.3.0 #
Fixed
-
A service call or goal made while offline could be reported as failed and then sent anyway when the link came back: it was failed by a reconnect attempt or its timeout, but left in the outbox. The robot then ran a goal the app believed had failed, with no handle left to cancel it, and a retry ran a service twice. A request reported as failed is now never sent.
-
A half-open link, a Wi-Fi dropout or a robot losing power, stayed "connected" forever while every command went nowhere. On native platforms the WebSocket now pings every 5 s (
WebSocketTransport.pingInterval), and an unanswered ping starts a reconnect. A browser page cannot send pings, so there the client probes an idle link itself (idleProbeInterval, on by default only on the web): it publishes on a hidden topic of its own,/_ros2_client/probe_*, which it also subscribes to, and reconnects when two probes go unanswered. Nothing is probed while a call or goal is outstanding, since a bridge serving one answers nothing else. Verified withexample/real_link_check.dartthrough a proxy that goes silent: pings notice after 5 s, the probe after 7 s, and an idle healthy link survives both; before, the link was never noticed. -
Every listener on a topic after the first made rosbridge deliver the next message twice, to all of them, and so did every reconnect with several listeners: each
subscriberegisters the client with a temporary latched subscriber while the existing one keeps delivering. A topic now has one bridge subscription, set up by its first listener and shared by the rest. Their options are that subscription's, and a listener asking for others gets a warning onstatus: previously rosbridge merged them, taking the minimum throttle rate and the strongest compression. Verified against rosbridge 2.0.8 with two listeners on/chatter. -
A service call's
timeoutstayed on the client. rosbridge's default is to wait forever and to serve one client's calls in order, so one hung call blocked every later call on the connection, long after the caller gave up. The timeout is now sent with the call. Verified against rosbridge 2.0.8: a call after a timed-out one answers in 11 ms, against over 4 s before. -
fragmentSizesilently stopped every CBOR topic on the client, even after the fragmented subscription was cancelled. rosbridge applies it to the whole connection, not the subscription. Combining the two on one client now throws, naming the topics; use a separate client for the fragmented topic. -
A second listener on a topic with a different QoS got the first one's, and so a best-effort sensor topic could deliver nothing to either. rosbridge keeps one QoS per topic, so it cannot be per listener; the client now warns on
status. -
GoalHandle.cancel()disarmed the goal's timeout, so a cancel that was refused or never delivered leftresultpending forever. -
A service call after
close()waited out its full timeout, and a goal never completed. Both now fail at once. -
A decode error in a message held while the listener was paused was swallowed rather than reported on
status. -
A
uint64at or above 2^63 decoded as 9223372036854775807, whatever its value, over both CBOR and JSON:UINT64_MAXsentinels, Gazebo entity ids and FFmpeg timestamps all collapsed to one number. Publishing one sent a negative number, which rosbridge rejected. Such values are now held as their two's-complement bits, as uint64 typed arrays already were (read one back withtoUnsigned(64)), and go out as the unsigned value:WireCodec.encodewrites aBigIntas its bare digits, whichjsonEncodecannot. Verified against rosbridge 2.0.8 in both directions. -
byte[]and boundeduint8[<=N]fields could not be published. Generated code base64-encoded them, but rosbridge decodes base64 only foruint8[],uint8[N]andchar[], and rejected the rest with "msg is not a list type", on its own console only. Everystd_msgs/ByteMultiArraypublish was dropped, and every generatedrcl_interfacesSetParameterscall failed, sinceParameterValue.byte_array_valueis abyte[]. They are now sent as a list. Verified against rosbridge 2.0.8. -
TfBuffermixed samples from before and after a sim-time reset when the clock went back by less thancacheTime: a Gazebo reset in the first seconds, orros2 bag play --loopon a short bag. "Latest" kept answering the old pose, and timed lookups interpolated across the reset. Three samples in a row stamped earlier than the newest one now re-baseline the frame. -
TfBufferrefused a frame that reappeared after more thancacheTime, taking the gap for a clock jump. A detected marker or docking station froze for its next nine samples, and a frame published slower than the window kept only one sample in ten. A jump is now accepted at once when the rest of the tree is already at that time. -
Imu,NavSatFix,BatteryStateandMapMetaDatadropped fields on decode, asOdometrydid before it was fixed: IMU and GPS covariances,position_covariance_type, battery temperature, health, technology and per-cell values, and the map'smap_load_time. Relaying one lost them, and an IMU that reports no orientation (orientation_covariance[0] == -1, REP-145) looked like a real one. All fields are now carried, andImu.hasOrientationsays which case applies. -
Generated
fromJsondecoded a missing fixed-size array as empty, and rosbridge then refused to publish the message because the array was too short; a missing nestedUUIDorPoseWithCovariancecovariance was enough. A missing array now gets the constructor's default, at the declared length or with the declared array default. -
generate --from-robotemittedbyteconstants as strings:DiagnosticStatus.okwas"b'\x00'", so comparing a level with it compiled and was always false. They are now ints. -
generate --from-roboton a type with a bounded array, a bounded string or awstringcrashes the robot'srosapinode on rosbridge 2.0.8, rather than just failing the one call as the documentation said, and the generator then waited 45 s for each remaining type. It now stops at the first sign thatrosapihas gone, keeps what it already fetched, and says so. ThemessageTypedefsdocumentation now describes the crash. -
MessageRegistry.byRosType(type).toJson(message)always threw aTypeError. The codec registered by name can now encode. -
A generated integer constant beyond 2^53 broke every web build that imported its library, and one beyond int64 did not compile at all. Such constants are now parsed at runtime.
-
TfBufferfroze when sim time went back, as it does on every Gazebo restart. Each new sample was older than the cache window measured from the stale newest one, so it was trimmed on arrival, and lookups kept answering the pose from before the restart with no error. A clock jump back is now handled like a jump forward already was: one outlier is ignored, and ten in a row re-baseline the frame onto the new clock. Verified against rosbridge 2.0.8 withexample/real_clock_jump_check.dart, which fails without it. -
An aborted goal kept nothing of its result.
ActionFailedException.resultnow holds it, decoded like a successful one. It is often the only place that says why: Nav2 on Jazzy aborts a failed navigation witherror_codeanderror_msgin the result, and until now they were discarded. Verified against rosbridge 2.7.1, which forwards them. -
A goal the bridge failed itself reported only "Goal ended as unknown". rosbridge sends the exception text, which the message now includes. A result that arrives but cannot be decoded says so in the message too, rather than leaving
resultnull without explanation. -
A message or list where a scalar belongs decoded as
0,falseor'', and a scalar where a message belongs as an all-default message. Both now throwFormatException. Neither is a quirk of the wire encoding; they mean the robot's definitions differ from the generated class's. Jazzy'sFollowWaypointsreports missed waypoints as messages where Humble's has integers, and a Humble class read them as a list of plausible, wrong indices.null, numeric strings and ints for doubles still decode as before.
0.2.0 #
A minor bump rather than a patch, because pub reads ^0.1.0 as
>=0.1.0 <0.2.0: shipping these as 0.1.1 would hand them to every existing
user automatically, and several of these change behaviour that correct-looking
code depends on. Most are bug fixes — the old behaviour was wrong — but wrong
in ways a caller may have built around.
New
waitUntilConnected({timeout}).connect()reports the first attempt and throws when it fails, but on a robot link it is usually the retry loop that gets you connected, and its success was observable only onstates— so every caller wrote the samestates.firstWhere(...). Throws aTimeoutExceptionon the timeout, and aStateErrorif the client closes orReconnectPolicy.maxAttemptsruns out first, rather than waiting on a client that has stopped trying.nextRetryAtandreconnectAttempt, because the backoff doubles: a UI showing "reconnecting" could not tell an operator whether the next attempt was a second or half a minute away.probeBridge()returns aBridgeInfo— ROS version, distro, and whether the bridge is new enough for ROS 2 actions. A pre-2.0.0 bridge answers a goal with nothing at all and logs the unknown operation on the robot's own console, so without thissendGoaljust never completes. Support is read from/rosapi/servicesrather than by calling/rosapi/action_servers: with the defaultcall_services_in_new_thread:=falseanddefault_call_service_timeout:=0.0, calling a service that does not exist parks the bridge's only queue thread for the life of the connection, so a probe that called it could wedge the link it was checking.Ros2Client(protocols: [...])offers WebSocket subprotocols on the handshake. rosbridge itself has no authentication: theauthopcode is a ROS 1 feature backed byrosauth, which was never ported — 2.0.7 registers noauthcapability, and a bridge sent one answersUnknown operation: authon the robot's console and nothing whatsoever to the client. Anything that authenticates a ROS 2 bridge therefore sits in front of it, and a subprotocol is the only handshake header a browser can set. Verified against 2.0.7: the bridge selects no subprotocol and accepts the connection, and traffic flows normally.
Behaviour that changes
- A scalar float sent as
nullnow decodes to NaN instead of0.0. Code likeif (battery.percentage < 0.2)flips, because every NaN comparison is false. That is the correct reading —nullon the wire means "no measurement" — but it is a change. Field.asListthrows on a corrupt element instead of dropping it. A message that used to decode short now fails, and the client reports it onstatus.RosTopicBuilderdefaults toBackpressure.latest, so a widget that was accumulating every message now sees only the newest. PassBackpressure.bufferto keep the old behaviour.- The teleop widgets advertise
perishable: true, so motion commands issued while offline are dropped rather than replayed on reconnect. - An absent nested message decodes to its declared defaults rather than all
zeros, so an absent
Quaternionis now the identity. - A cycle in the tf tree throws from
lookupOrThrowinstead of returning an answer derived through an arbitrary edge. set_levelis no longer sent on connect; rosbridge has never implemented it.
Fixes
Audits of the tf2 and message layers, neither of which had been reviewed
before. The core maths came out clean — Hamilton products,
lookupTransform composition order and toMatrix4 all verified to ~1e-16
against an independent derivation — but the edges around it did not.
Gimbal lock returned garbage roll and yaw. At a pitch of exactly ±90° the
rpy decomposition is degenerate, and clamping the pitch alone left roll and
yaw as atan2 of two rounding errors: up to 37° of silent error. Straight down
is a mast camera or a depth sensor looking at the floor, not an exotic pose.
Now returns roll = 0 with the rotation folded into yaw, which reconstructs
exactly. Near-lock is untouched — the ordinary formulae stay accurate to a
pitch of pi/2 - 1e-6.
One future-stamped sample poisoned the whole tf buffer. The cache window was anchored on the newest stamp, so a single message from a node whose clock was a minute fast dropped every sample held and every good sample that arrived afterwards. The buffer never recovered; the UI silently stopped updating. Clock skew between a robot and a bridge is routine. Implausible future stamps are now refused, with a re-baseline if they persist so a genuine clock change is still followed.
A static transform hid live data. A frame published on both /tf and
/tf_static answered from the latched value while dynamic samples sat unread,
so the frame stopped moving with no diagnostic. Dynamic samples now win, with
the static one as fallback.
A cycle in the tree gave two contradictory answers instead of an error:
lookup(a, b) and lookup(b, a) resolved through different edges and a round
trip did not return to its origin. Now throws.
/tf and /tf_static used the wrong QoS depth — and it lost real frames.
Confirmed against a robot with three independent static broadcasters: with the
0.1.0 profiles only the last one's frame arrives, and looking up either of
the others throws "does not exist in the tf tree". Every robot has more than
one static broadcaster. tf2_ros uses reliable
depth 100 for both; a best-effort keep-last-5 reader drops transforms under
load, and a one-deep transient-local reader keeps only one publisher's latched
backlog — so some static frames never arrived at all.
waitForFrame was the only API that did not strip a leading /, so it
blocked for its full timeout on a frame the robot was publishing.
Negative durations and pre-epoch times were a second wrong, and flipped
sign: seconds truncated toward zero while nanoseconds used Dart's
always-positive %. -0.5 s came back as +0.5 s.
Odometry discarded the covariance it was given and re-encoded 36 zeros,
so relaying a message turned "this is my uncertainty" into "I am certain".
Both matrices are now carried through.
PointCloud2 ignored row_step, reading coordinates out of the row
padding an organised cloud from a depth camera contains, and shifting every
point after the first row.
PointCloud2 and TFMessage had no ==, contradicting the value-type
contract every other message honours. PointCloud2.fromJson also defaulted
height to 0 and is_dense to false, disagreeing with its own constructor.
A null float decoded as 0.0 instead of NaN. rosbridge writes null for
every non-finite float, so null means "no measurement" — and NaN is how ROS
spells that. An unknown battery charge read as a confident 0 %, and a NaN pose
component rendered at the origin. The array converters had always mapped null
to NaN; scalars now agree with them.
An absent nested message decoded to all zeros, which for Quaternion is
the invalid rotation rather than the identity its definition declares. A zero
quaternion behaves like identity when rotating a point but annihilates a
Hamilton product, so a single absent link silently erased the rotation of an
entire tf chain — a 90° turn became no turn, with no exception and no NaN.
Both are fixed by decoding against the key rather than the value:
Field.doubleAt(json, 'w', 1) can tell an absent field from one sent as
null, and carries the default the .msg declares. The generator emits these,
and the old value-based helpers remain for code generated against 0.1.0.
asList silently dropped elements it could not type-match, renumbering
everything after them — a path's waypoints shifted by one with nothing to
indicate they had. A loosely typed Map<Object?, Object?> element emptied the
array entirely. Loose maps are now accepted; a genuinely corrupt element throws,
which the client reports on status and costs one message rather than the
subscription.
Also: wss:// verified against a TLS bridge, including certificate pinning
for the self-signed case; CI added; the tree is now dart format clean.
example/real_connection_check.dart covers the connection-level additions
against a real bridge — 6/6 against rosbridge 2.0.7 on Humble.
0.1.0 #
Initial release.
-
Code generator (
dart run ros2_client:generate) for.msg,.srvand.actiondefinitions, with automatic transitive dependency resolution; generated services and actions register typed codecs, socallServiceandsendGoalneed no type strings -
sendGoaltakes an optionaltimeout: a goal sent to an action server that does not exist gets no reply at all, and would otherwise never complete -
CBOR is now the default wire encoding: rosbridge serialises non-finite floats as JSON
null, soinfandnanare indistinguishable over plain JSON -
Connection management with exponential backoff, jitter, and a stability window so a flapping bridge is backed off rather than hammered
-
Typed topic subscribe/advertise via a message codec registry
-
Services, ROS 2 actions (goal/feedback/result/cancel), and parameters
-
Full ROS 2 QoS profiles, including
sensorDataandtransientLocalpresets -
JSON and CBOR wire codecs; CBOR typed arrays decode without a per-element copy. Handles base64
uint8[]and message fragmentation -
Non-finite floats are encoded as
nullon the wire.jsonEncodethrows oninf/nan, so republishing aLaserScanwhose out-of-range beams areinfpreviously crashed -
tf2 transforms:
TfBufferwith tree walking, time interpolation and slerp,TfListenerfeeding it from/tfand/tf_static, and rigid-body maths on thegeometry_msgstypes -
Graph introspection through
rosapi, with timeouts sized for how slow those graph-wide queries actually are -
std_msgs,geometry_msgs,sensor_msgsandnav_msgscore types