Metadata-Version: 2.5
Name: lerobot_teleoperator_rfabricd
Version: 0.1.1
Summary: LeRobot plugin: the rFabric remote operator drives a LeRobot robot over the rFabric realtime control UDS (rfabricd teleoperator and its follower robot types).
Project-URL: Homepage, https://rfabric.io
Project-URL: Repository, https://github.com/rfabric/lerobot-teleoperator-rfabricd
Author-email: rFabric <engineering@rfabric.io>
License: Apache-2.0
Keywords: lerobot,rfabric,robotics,teleoperation
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: lerobot<0.8,>=0.6.1
Requires-Dist: numpy>=2.0
Requires-Dist: rfabric-control-wire>=0.1.1
Provides-Extra: dev
Requires-Dist: lerobot[dataset]<0.8,>=0.6.1; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Provides-Extra: feetech
Requires-Dist: lerobot[feetech]<0.8,>=0.6.1; extra == 'feetech'
Provides-Extra: kinematics
Requires-Dist: lerobot[kinematics]<0.8,>=0.6.1; extra == 'kinematics'
Description-Content-Type: text/markdown

# lerobot_teleoperator_rfabricd

LeRobot plugin that lets an rFabric remote operator drive a LeRobot robot, with
stock `lerobot-teleoperate` and `lerobot-record`. It is the follower end of the
rFabric realtime control UDS: `rfabricd` connects to the socket
the teleoperator binds and relays the operator console's control frames
(`rfabric-control-wire`).

Works with stock LeRobot 0.6 and 0.7. LeRobot discovers the plugin by its
distribution name (`lerobot_teleoperator_*`); installing it in the LeRobot
environment adds:

| Flag | What it is |
|---|---|
| `--teleop.type=rfabricd` | The remote operator |
| `--robot.type=rfabric_bi_so_follower` | `bi_so_follower` that shares its joint readings with the teleoperator |
| `--robot.type=rfabric_so101_follower` | `so101_follower` that shares its joint readings with the teleoperator |

The operator sends absolute joint positions (`joint_targets`), one velocity
(`-1..1`) per joint, or - with `--teleop.urdf_path` set - the gripper's velocity
(see [End-effector control](#end-effector-control)); turning velocities into
joint positions needs the arm's present position, which LeRobot gives a
teleoperator only through the robot. The follower robot types are the stock
robots - same flags, calibration files, features and `robot_type` in datasets -
that also publish every observation and completed write to the teleoperator in
the same process.

## Install

Into the Python environment LeRobot runs from:

```bash
uv pip install lerobot_teleoperator_rfabricd
```

## Run

Teleoperate a bimanual SO-101 (what `rfabric-arms.service` runs):

```bash
lerobot-teleoperate \
  --robot.type=rfabric_bi_so_follower --robot.id=bimanual_follower \
  --robot.left_arm_config.port=/dev/ttyACM0 --robot.right_arm_config.port=/dev/ttyACM1 \
  --robot.left_arm_config.max_relative_target=24 --robot.right_arm_config.max_relative_target=24 \
  --teleop.type=rfabricd --teleop.socket_path=/run/rfabric/control.sock \
  --teleop.arms='[left,right]' --fps=60
```

Record while the remote operator drives (the dataset action is the joint
position target):

```bash
lerobot-record <the same --robot.* and --teleop.* flags> \
  --dataset.repo_id=local/remote_demo --dataset.single_task="Pick the cube"
```

A single-arm robot uses `--robot.type=rfabric_so101_follower` and leaves
`--teleop.arms` empty.

## Embodiment

The teleoperator declares the robot's state and actions in the layout below,
from the follower's first observation (`<arm>_<joint>.pos` keys). The robot's
`Embodiment` on the platform must declare the same state components and action
groups, with the same names, joints and order: rfabricd compares the two
fingerprints (`embodiment`) and refuses the session when they differ.

| Part | Name | Declared as | Elements |
|---|---|---|---|
| Action group, one per arm | the arm tag (`left`, `right`); `arm` for a single arm | `target: joints`, `mode: position` | the arm's joints in observation order |
| State component, one per arm | `<group>_position` (`left_position`) | `quantity: joint_position` | the same joints |

Groups and components follow `--teleop.arms` order. For a bimanual SO-101
(`--teleop.arms='[left,right]'`) the action names run from `left.shoulder_pan`
to `left.gripper`, then `right.shoulder_pan` to `right.gripper`; the state names
from `left_position.shoulder_pan` to `right_position.gripper`; the fingerprint is
`4199509803`. A single SO-101 is group `arm` and component `arm_position`,
fingerprint `3280823783`. Values are in the follower's joint units (degrees for
SO-101 with `use_degrees`, the gripper `0..100`).

The matching `Embodiment` of a bimanual SO-101 (add `low`, `high` and `maxRate`
per group; a remote inference session needs `maxRate`):

```json
{
  "state": {"components": [
    {"name": "left_position", "quantity": "joint_position", "joints": ["shoulder_pan", "shoulder_lift", "elbow_flex", "wrist_flex", "wrist_roll", "gripper"]},
    {"name": "right_position", "quantity": "joint_position", "joints": ["shoulder_pan", "shoulder_lift", "elbow_flex", "wrist_flex", "wrist_roll", "gripper"]}
  ]},
  "actions": {"groups": [
    {"name": "left", "target": "joints", "mode": "position", "joints": ["shoulder_pan", "shoulder_lift", "elbow_flex", "wrist_flex", "wrist_roll", "gripper"]},
    {"name": "right", "target": "joints", "mode": "position", "joints": ["shoulder_pan", "shoulder_lift", "elbow_flex", "wrist_flex", "wrist_roll", "gripper"]}
  ]}
}
```

## What the operator gets

- **Capabilities**: on each rfabricd connection, a `mode` frame (control wire
  version 2) with the fingerprint, `stateNames`, `actionNames`, the `groups`,
  `accepts: [joint_targets, joint_velocity, stop, home]` -
  `[joint_targets, joint_velocity, end_effector_velocity, stop, home]` with
  `--teleop.urdf_path` set - `positionHold: true`, each group's `home` row
  (`--teleop.home_pose`) and its `velocityScale`: per joint the speed of
  normalised velocity 1 (`joint_speed`, `gripper_speed` for the gripper),
  which rfabricd uses to bound operator velocities by the group's `maxRate`.
- **State**: one `snapshot` at `state_publish_hz`: the fingerprint and every
  joint position, packed as float32 in `stateNames` order.
- **Joint targets**: a `joint_targets` frame (`arm` names the group) is that
  arm's position target as given, joint by joint; joints it leaves out hold.
  rfabricd limits how fast consecutive targets move (the group's `maxRate`) and
  turns an operator `home` into targets toward the home row; a `home` that
  reaches the teleoperator is the home row as one target.
- **Safety**: an arm holds its present position when it receives `stop`, when its
  last command (`joint_targets`, `joint_velocity` or `end_effector_velocity`) is
  older than `watchdog_ms`, when rfabricd disconnects, on a malformed control
  payload and on a frame of another control-wire version; a `stop` without an
  arm tag stops every arm. A stale command never keeps moving anything. After
  end-effector control the jaws are the exception: they keep their last commanded
  target through every hold, so a stop never loosens a grip (see
  [End-effector control](#end-effector-control)).
- **Stop ack**: once the follower's write that carries a `stop`'s hold returned,
  the teleoperator answers with `ack{kind:"stop"}` - the preflight stop check of
  rfabricd, which the operator console requires before motion by default.
- **Episodes**: operator `terminate` / `success` / `rerecord` mode frames are
  reported by `get_teleop_events()`.

## Servo settings (`--teleop.*`)

| Flag | Default | Meaning |
|---|---|---|
| `joint_speed` | `60.0` | Joint speed at full velocity, per second (degrees for SO-101) |
| `gripper_speed` | `180.0` | Gripper speed at full velocity, per second (`0..100`) |
| `lead_cap` | `12.0` | How far a target may run ahead of the present position |
| `velocity_tau_s` | `0.10` | Low-pass time constant on operator velocities; `0` disables |
| `velocity_idle_epsilon` | `0.04` | Smoothed velocity below which a released joint holds |
| `joint_signs` | `{}` | `-1` reverses a joint, e.g. `'{right_shoulder_pan: -1}'` |
| `home_pose` | `{}` | Home position per joint, keyed like `joint_signs`; a joint left out homes to `0` |
| `watchdog_ms` | `200` | Command age after which an arm holds |

Keep `--robot.*.max_relative_target` at about twice `lead_cap`: the robot then
caps any single command as a second line of defence.

## End-effector control

With `--teleop.urdf_path` set, the teleoperator also accepts
`end_effector_velocity` frames - what the operator console's gamepad sends, one
every 33 ms while any input is non-zero, then 0.5 s of all-zero frames:

```json
{"kind": "end_effector_velocity", "arm": "left",
 "linear": {"x": 0.0, "y": 0.0, "z": 1.0}, "pitch": 0.0, "roll": 0.0, "gripper": -1.0}
```

Every value is a fraction (`-1..1`) of a top speed: `linear` moves the
gripper's wrist point, `pitch` tilts the gripper about its wrist, `roll` turns it
about its own outward axis, `gripper`
opens (`+`) or closes (`-`) the jaws. Like `joint_velocity` it is the arm's
latest command: the follower smooths it and integrates it every control tick
with the tick's real duration, so the distance travelled depends on how long a
stick is held, not on how many frames arrived. placo's kinematics, loaded from
the URDF, turn it into joint targets.

| Flag | Default | Meaning |
|---|---|---|
| `urdf_path` | unset | The follower arm's URDF; unset, the teleoperator accepts joint velocities only |
| `tip_speed` | `0.10` | Wrist point speed at full `linear` input, in metres per second |
| `pitch_speed` | `90.0` | Tilt speed at full `pitch` input, in degrees per second |
| `roll_speed` | `90.0` | `wrist_roll` speed at full `roll` input, in degrees per second |

`gripper_speed`, `velocity_tau_s`, `velocity_idle_epsilon`, `lead_cap` and
`watchdog_ms` ([Servo settings](#servo-settings---teleop)) apply to it too.

It needs placo, from the plugin's `kinematics` extra (LeRobot's `kinematics`),
and the arm's URDF with its meshes (`assets/`, which the URDF references by
relative path):

```bash
uv pip install 'lerobot_teleoperator_rfabricd[kinematics]'
git clone --depth 1 --filter=blob:none --sparse https://github.com/TheRobotStudio/SO-ARM100.git
git -C SO-ARM100 sparse-checkout set Simulation/SO101
# then: --teleop.urdf_path=$PWD/SO-ARM100/Simulation/SO101/so101_new_calib.urdf
```

The teleoperator loads one kinematics per arm at connect and fails there if
placo is missing or the URDF does not load; the first follower observation must
carry every URDF joint (`so101_new_calib.urdf` names its joints after the
SO-101 motors).

- **Frames and units**: the wrist point is the origin of the URDF frame
  `wrist_link`, on the `wrist_flex` axis, which `wrist_flex` and `wrist_roll` do
  not move. It moves in the arm's base frame (the URDF's root, `base_link`: for
  SO-101 `+x` points forward from the base, `+y` to its left seen from behind,
  `+z` up). The tilt is the elevation of the gripper's outward axis
  (`gripper_frame_link`'s `+z`) above the base's horizontal plane, in degrees:
  positive `pitch` raises the fingertips. A roll turns the gripper about that
  outward axis, right-hand rule: positive `roll` is clockwise seen from behind
  the gripper. Joints are in the follower's units: degrees for SO-101
  (`use_degrees`), the gripper `0..100`.
- **Smoothing**: each input is low-passed with `velocity_tau_s`, the joint
  servo's filter, so a full stick ramps the arm up over about `3 *
  velocity_tau_s` instead of jumping, and a released stick (or the all-zero
  frames) eases it to rest; an input whose smoothed value falls below
  `velocity_idle_epsilon` stops. At rest the arm holds its commanded joints,
  without drift.
- **Motion**: per tick the wrist point's target moves `tip_speed * dt` at full
  input, the tilt's target `pitch_speed * dt` and `wrist_roll`'s target
  `roll_speed * dt`. `shoulder_pan`, `shoulder_lift` and `elbow_flex` come from
  placo's wrist-position solve, seeded with the present joints and inside the
  URDF's joint ranges; `wrist_flex` then sets the tilt, within its URDF range,
  so a move keeps the gripper's tilt.
- **Roll**: `wrist_roll` alone turns the gripper - its axis is the gripper's
  outward axis, so neither the wrist point nor the tilt moves. Its direction
  comes from the kinematics at load (which way `wrist_roll` turns
  `gripper_frame_link` about its `+z`): on SO-101 a positive `roll` turns
  `wrist_roll` negative. It stays within the URDF's `wrist_roll` range; a
  `wrist_roll` already past it (a calibration that disagrees with the URDF) is
  not pulled back in. With no `roll` input `wrist_roll` holds its target.
- **Limits**: the body's step from the present joints - shoulder, elbow,
  `wrist_flex` and `wrist_roll` together - is scaled down as a whole until no
  joint moves more than `lead_cap`, which keeps its direction. A step that
  would leave the wrist further from its target than it is now - a soft solve
  at a singularity, such as the arm stretched out - or a failed solve is
  refused: the shoulder and elbow hold. After each tick the targets become what
  the commanded joints reach, so pushing on at the edge of the workspace or at
  a joint limit, `wrist_roll`'s included, winds nothing up and the reverse
  direction moves the arm at once.
- **Gripper**: its target moves `gripper_speed * dt` at full input, within
  `0..100`, and stays within `lead_cap` of the jaws' present position: a grip
  closed on an object squeezes with a bounded force, and the jaws never slam.
  At zero input the target stays, so a grip keeps squeezing.
- **Holds**: a `stop` or a command older than `watchdog_ms` holds the body at
  its present position at once, and the jaws at their last commanded target:
  a grip closed on an object keeps squeezing through the console's trailing
  all-zero frames, the watchdog, a `stop` or a disconnect. Only a new command
  moves the jaws: an `end_effector_velocity` with a non-zero `gripper`, or a
  `joint_velocity` on the `gripper` joint, which moves it from its present
  opening.
- **Entering Cartesian control**: the body's targets start from the present
  joints on an arm's first `end_effector_velocity` command and after a `stop`,
  the watchdog or a `joint_velocity` command; the gripper's target starts from
  the target it was held at, else from its present opening.
- **Bimanual**: one kinematics per arm tag, each in its own arm's base frame -
  a frame tagged `left` moves the left gripper in the left arm's frame.

## Development

```bash
uv sync --extra dev --extra feetech
.venv/bin/ruff check src tests && .venv/bin/ruff format --check src tests
.venv/bin/mypy src
.venv/bin/pytest
```

`rfabric-control-wire` resolves from the sibling checkout
(`[tool.uv.sources]`).
