Back to blog
Robotics··6 min read

How a Dexterous-Hand Command Travels Through Unity and ROS 2

Tracing a 26-active-DOF synthetic motion sequence across Windows/Unity, hands3d-contracts, and the WSL ROS 2 bridge: atomic admission checks, separating publish proof from arrival feedback, and locating failures fast.

#Hands3D#ROS 2#Unity#Contracts#Motion Control
—views

The fastest way to drive a simulated dexterous hand from Unity is a coroutine pushing joint angles over TCP every 50 ms. It works fine for a screen recording, then breaks in three ugly ways during real integration: editing a waypoint mid-run mutates a live motion, a dropped packet leaves you guessing whether the bridge published or the hand stalled, and reconnecting lets stale targets fight new ones for authority.

In Hands3D, the command path spans three repositories: the Windows Unity console handles authoring, preview, and unit conversion; hands3d-contracts owns cross-repo semantics; and hands3d_bridge in YQRobot-ROS handles atomic validation, timeline sampling, and lease-controlled publishing. Below, we trace one synthetic motion sequence (pinch_demo_v1) from click to feedback.

End-to-End View Across Three Boundaries

Suppose we command the virtual right hand hand-right (builtin:ros_sim_26a15p, 26 active DOFs + 15 passive coupled DOFs) through a two-segment SMOOTHSTEP pinch lasting 1.4 seconds.

Rendering diagram…

The split is strict: Unity never fakes trajectory execution by ticking manual sliders, and ROS never reads mutable editor files. Only a self-contained, immutable snapshot crosses the wire.


1. Contract Validation: Atomic Admission Before Any Motion Starts

Before sim_motion_submit is allowed, both sides negotiate sim_motion_sequence_v1 and sim_command_observation_v1 during hello. Standard real-hardware outlets do not advertise these simulation capabilities, preventing virtual planning limits from masquerading as certified actuator specs.

A condensed synthetic submission payload looks like this:

json
{
  "op": "sim_motion_submit",
  "params": {
    "device": "hand-right",
    "grant": 42,
    "configuration_id": "cfg_9a3f18c0",
    "motion_limits_id": "lim_2c8e74b1",
    "request_key": "7f4e91a2c0d34b8891e4f012a6c83d19",
    "motion_id": "pinch_demo_v1",
    "dof_ids": [1,2,4,6,8,9,11,13,15,16,18,20,22,23,25,27,29,30,31,32,33,34,36,37,40,41],
    "start_policy": "REQUIRE_FIRST_POINT",
    "segments": [
      {
        "duration_s": 0.20,
        "interpolation": "SMOOTHSTEP",
        "values": [0.00, 0.12, "...26 SI values (rad/m)...", 0.00],
        "velocity_limits": [1.047, 1.047, "...26 positive values...", 1.047],
        "acceleration_limits": [2.094, 2.094, "...26 positive values...", 2.094]
      },
      {
        "duration_s": 1.20,
        "interpolation": "SMOOTHSTEP",
        "values": [0.52, 0.78, "...26 SI values (rad/m)...", 0.05],
        "velocity_limits": [1.047, 1.047, "...26 positive values...", 1.047],
        "acceleration_limits": [2.094, 2.094, "...26 positive values...", 2.094]
      }
    ]
  }
}

The bridge validates the entire sequence atomically under one authority lock. If segment 2 violates a single bound, the entire request is rejected — segment 1 never runs:

  1. Authority & Dual Fingerprints: Verifies the session holds an active UNITY grant and both configuration_id (DOF map / device config) and motion_limits_id (planning velocity, acceleration, and tolerance profile) match the running bridge. Any profile restart invalidates stale fingerprints immediately.
  2. Canonical Active DOFs & SI Boundary: dof_ids must match the exact 26 active IDs in canonical order — no sparse payloads and none of the 15 passive coordinates. Unity converts UI degrees/millimeters to SI (rad, m, rad/s, m/s²) at the boundary; range checks allow only 1e-7 SI for floating-point round-trip and never silently clamp out-of-range targets.
  3. Explicit Limits (Zero Means Reject, Not Unlimited): Every entry in velocity_limits and acceleration_limits must be a finite positive number within server limits. A saved 0 in a local library remains editable in Unity, but is rejected at execution time.
  4. Kinematics & Start Alignment: For cubic SMOOTHSTEP (s(u)=u2(3−2u)s(u) = u^2(3-2u)), ROS checks peak velocity (1.5∣Δq∣/T1.5|\Delta q|/T at u=0.5u=0.5) and peak acceleration (6∣Δq∣/T26|\Delta q|/T^2 at the endpoints) on every segment, returning DURATION_INFEASIBLE if exceeded. Under REQUIRE_FIRST_POINT, fresh active feedback must already sit within start_tolerance of segment 0; the server never auto-slews to the start pose and instead returns START_MISMATCH.

2. Observing Commands: Separating Publish Proof from Arrival Feedback

Once accepted, the ROS sampler publishes float32[26] through the existing unified HandSimControl lease outlet. To let the console visualize real outgoing commands without confusing UI estimates for actuator motion, COMMAND_OBSERVATION_V1 enforces three sharp separations.

sim_command_state Proves Publication Only

sim_command_state (20 Hz default, capped at 30 Hz, latest-wins) updates only after publisher.publish returns successfully, copying the exact published float32[26] array with:

  • source = "ROS_MOTION" (distinct from UNITY_SIM_TARGET, UNITY_FULL_POSE, and ALGORITHM);
  • proof = "BRIDGE_PUBLISHED";
  • sample_origin = "ros_sim_synthetic".

BRIDGE_PUBLISHED proves the bridge invoked the ROS 2 publisher — nothing more. It does not prove DDS delivery, simulator adoption, or physical joint convergence.

Heartbeats vs. New Targets, Missing Data vs. Zero

Because the lease outlet periodically republishes the cached target as a heartbeat, the observation snapshot tracks target identity and publication cadence separately:

DimensionTarget Identity (Unchanged by Heartbeat)Publication Event (Increments Every Publish)
Sequencecontrol_epoch + target_sequencepublication_sequence
ROS Timestamptarget_ros_tspublish_ros_ts
Monotonic Agetarget_cache_age_spublish_age_s

If publish_age_s exceeds 250 ms — or if the device disables, loses control authority, or enters a stop window — the snapshot flips to valid = false with values = []. Read-only get_sim_command_state queries behave the same way: missing data stays empty, never zero-filled.

SCHEDULE_FINISHED Is Not REACHED

When segment 2 finishes at t=1.40 st = 1.40\,\text{s} and the final target publishes cleanly, sim_motion_state.phase becomes SCHEDULE_FINISHED. Actual convergence lives in a separate field, feedback_state (UNKNOWN / NOT_REACHED / REACHED / UNAVAILABLE), evaluated strictly from independent, fresh, same-fingerprint feedback samples. REACHED requires all 26 active joints to remain inside tolerance for at least 0.1 s across newly arriving samples (never re-reading one cached frame), and with sample_origin = ros_sim_synthetic the UI labels it as simulated arrival rather than real hardware completion.


3. Where to Look When Something Fails

Combining explicit rejection codes, state-machine phases, and observation snapshots maps almost every failure directly to its owning layer:

Symptom / Error CodeFields to Inspect FirstOwning LayerRecovery Action
Rejected with START_MISMATCHFresh feedback vs. segment 0 values and start_tolerancePre-run hand poseManually move the virtual hand into tolerance, then resubmit
Rejected with DURATION_INFEASIBLE or OUT_OF_RANGEΔq\Delta q, duration_s, SI conversionUnity unit boundary or motion authoringCheck deg/mm → rad/m and verify $1.5
CONFIG_CHANGED / LIMITS_CHANGED / STALE_GRANTgrant, configuration_id, motion_limits_idBridge reload or authority changeRefresh get_sim_motion_limits and acquire a fresh grant
Mid-run ABORTED / SCHEDULER_LATEsim_motion_state.code & bridge logsWSL/ROS sampling gap > 0.25 sBridge clears target and requests hold; check host CPU stalls before retrying
Plot freezes or grays out mid-motionsim_command_state.valid, publish_age_s, event_sequencePublication staleness (> 250 ms) or lease dropCompare target_sequence vs. publication_sequence to see if input or bridge stalled
Unsure if hand halted after cancelstop_requested vs. stop_confirmed under CANCELLEDHold-service acknowledgmentKeep warning visible when stop_confirmed=false; never auto-restart
Submit timed out (UNKNOWN local block)Query sim_motion_status with original request_keyLost reply over TCPNever blindly resend; if still unknown, run explicit software stop → wait confirm → re-enable CONFIRMED, then submit with a fresh request_key

One safety rule runs through every recovery path: reconnecting, re-acquiring authority, or re-enabling never auto-resumes a cancelled or aborted motion. Waiting for a deliberate new command is always safer than letting a dexterous hand twitch back to life after a network blip.


Takeaway

Moving a multi-segment command across Unity and ROS 2 stays debuggable when three lines hold firm: atomic admission with immutable snapshots before motion begins, distinct evidence for publish vs. schedule completion vs. independent feedback during motion, and monotonic sequencing with idempotent status queries when links drop.

For the full 6-layer Unity runtime architecture, see the Hands3D project page, alongside hands3d-contracts and YQRobot-ROS.