Metadata-Version: 2.4
Name: iron-fleet
Version: 0.1.0
Summary: Robot hardware abstraction layer and drivers
License-Expression: LicenseRef-Proprietary AND Apache-2.0
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: LICENSE-APACHE-2.0
License-File: THIRD_PARTY_NOTICES
Requires-Dist: numpy
Requires-Dist: opencv-contrib-python>=4.8
Requires-Dist: Pillow
Requires-Dist: pyyaml
Requires-Dist: scipy
Provides-Extra: so101
Requires-Dist: lerobot[feetech]==0.6.1; extra == "so101"
Requires-Dist: pyserial<4,>=3.5; extra == "so101"
Provides-Extra: realsense
Requires-Dist: pyrealsense2>=2.54; extra == "realsense"
Provides-Extra: xarm
Requires-Dist: xarm-python-sdk; extra == "xarm"
Provides-Extra: ur
Requires-Dist: ur-rtde; extra == "ur"
Requires-Dist: pyrobotiqgripper; extra == "ur"
Provides-Extra: robotiq
Requires-Dist: pyrobotiqgripper; extra == "robotiq"
Provides-Extra: franka
Requires-Dist: panda-python; extra == "franka"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: pyarrow; extra == "dev"
Dynamic: license-file

# iron-fleet

Robot hardware abstraction layer for QuantyCat.

`iron-fleet` provides a consistent interface for robot arms, camera/perception utilities,
calibration helpers, and deployment-side safety/policy components. The current repo
includes working support for:

- SO-101 real hardware via lerobot (`so101`)
- Camera discovery and capture on Linux and macOS
- Calibration helpers for AprilTag, checkerboard, hand-eye, and transforms

## License

Copyright (c) 2026 QuantyCat. All Rights Reserved.

This is proprietary software. Unauthorized copying, modification, distribution,
or use is strictly prohibited. See [LICENSE](LICENSE) for details.

## Repository layout

```text
inference/
└── openpi/                       # Entry points: inference.sh, setup.sh

iron_fleet/
├── robots/                       # Robot interfaces and implementations
│   └── lerobot/                  # SO-101/LeRobot adapter, go_home, run_robot, setup
├── openpi/                       # Policy server, openpi runner, state adapter, gain clip
├── calibration/                  # AprilTag, checkerboard, hand-eye, transforms
├── perception/                   # Camera config loading and camera manager
└── robot_registry/               # Driver registry (used by prime-radiant)

vendor/
└── openpi/                       # Cloned by inference/openpi/setup.sh (not checked in)

tests/                            # Unit and smoke tests
```

OpenPI training config is intentionally not maintained here. The canonical
Quantycat OpenPI training patches live in `quantycat-positronic` under
`models/openpi/vendor_patches/`; `iron-fleet` owns deployment/inference.

## Python version

- Python 3.10+

## Installation

### Standard editable install

```bash
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -e .
```

### Development install

```bash
pip install -e ".[dev]"
```

This installs the package plus development tooling such as `pytest`, `black`, `ruff`,
and `mypy`.

### Optional extras

#### RealSense support

```bash
pip install -e ".[realsense]"
```

#### SO-101 real hardware support

```bash
pip install -e ".[so101]"
```

## Running tests

```bash
python3 -m pytest -q
```

The current checked-in test suite is focused on camera/perception behavior:

```bash
python3 -m pytest tests/test_camera_manager.py -v
```

Robot smoke tests should live under `tests/` when they are added for a simulator or
hardware setup.

## Quick usage examples

### List available robot types

```python
from iron_fleet.robot_registry import RobotRegistry

print(RobotRegistry.list_registered())
```

Expected registered types currently include:

- `so101` (register your driver with `@RobotRegistry.register("so101")`)

### Load camera config from YAML

```yaml
robot:
  type: so101

cameras:
  wrist:
    serial: "ABC123"
    resolution: [480, 360]
  third_view:
    serial: "XYZ789"
    resolution: [640, 480]
```

```python
from iron_fleet.perception.config import load_camera_configs

configs = load_camera_configs("robot.yaml")
print(configs)
```

### Use `CameraManager`

```python
from iron_fleet.perception import CameraManager

configs = {
    "wrist": {"serial": "ABC123", "resolution": [480, 360]},
    "third_view": {"serial": "XYZ789", "resolution": [640, 480]},
}

cam = CameraManager(configs)
cam.start()
frames = cam.get_frames()
print(frames.keys())
cam.stop()
```

## Supported Drivers

### Robot drivers

SO-101 (LeRobot), YAM, xArm, UR, Franka, Kinova Gen3, and AgileX Piper; see
[Robot adapters and deterministic moves](#robot-adapters-and-deterministic-moves).

## Camera and perception notes

`iron_fleet.perception.camera_manager` supports:

- Linux camera discovery through `/dev/video*` + `udevadm`
- macOS camera discovery through AVFoundation + `system_profiler` when available
- optional Intel RealSense enumeration when `pyrealsense2` is installed

Important details:

- Camera configs require both `serial` and `resolution`
- Resolution must be `[width, height]`
- On Linux, odd-numbered `/dev/video*` nodes are skipped because they are often metadata
  nodes rather than frame-producing devices

## Adding a new robot

1. Add an adapter under `iron_fleet/robots/arms/`: subclass `StreamingArm` and
   implement `_hw_open`, `_hw_close`, `_hw_read_arm`, `_hw_write_arm` (and a
   `Gripper` if the arm has one). Import the vendor SDK inside `_hw_open` with
   `require(...)` so the module imports without it.
2. Register it and list it in `_BUILTIN_ROBOTS` (`iron_fleet/robot_registry/robot_registry.py`):

```python
from iron_fleet.robot_registry import RobotRegistry

@RobotRegistry.register("your_robot")
class YourArm(StreamingArm):
    ...
```

3. Add the SDK as a pyproject extra.
4. Add a test against a fake SDK module (see `tests/test_streaming_arms.py`).

## Developer notes

- Prefer installation through `pyproject.toml` (`pip install -e .`) rather than `setup.py`.
- The helper script `compile` installs the dev extra and runs the checked-in tests.

## Known assumptions

- Real robot safety, workspace limits, and production deployment policies should be
  validated outside this repo before commanding hardware

## Robot adapters and deterministic moves

Every robot is a `RobotAdapter` (`iron_fleet/robots/base.py`), picked by the
deployment yaml's `robot.type` through `iron_fleet.robot_registry`:

| `robot.type` | Adapter | SDK (pyproject extra) | Run on hardware? |
|---|---|---|---|
| `so101` | `robots/lerobot/adapter.py` | LeRobot (`.venvs/lerobot`) | yes |
| `yam` | `robots/arms/yam.py` | i2rt (see driver install hint) | not yet |
| `xarm` | `robots/arms/xarm.py` | xarm-python-sdk (`.[xarm]`) | not yet |
| `ur` | `robots/arms/ur.py` (+ Robotiq) | ur-rtde (`.[ur]`) | not yet |
| `franka` | `robots/arms/franka.py` | panda-python (`.[franka]`) | not yet |
| `kinova` | `robots/arms/kinova.py` | kortex_api (wheel from Kinova) | not yet |
| `piper` | `robots/arms/piper.py` | pyAgxArm (see driver install hint) | not yet |

The `robots/arms` adapters share `StreamingArm` (`robots/arms/streaming.py`):
a background loop reads the joints and steps the command toward the latest
target at a capped joint speed (`max_joint_speed`, rad/s), and a separate
thread drives the gripper so a slow gripper never stalls the arm. Positions
are radians for arm joints, then the gripper in 0 (closed) .. 1 (open).
Each module's docstring shows its yaml keys; they match the constructor's
arguments, e.g.

```yaml
robot:
  type: yam
  channel: can0
  gripper_type: linear_4310
```

Adding an arm: subclass `StreamingArm`, implement `_hw_open`, `_hw_close`,
`_hw_read_arm`, `_hw_write_arm` (plus a `Gripper` if it has one), register it
with `@RobotRegistry.register("<type>")`, and add it to `_BUILTIN_ROBOTS`.

`iron_fleet.run` drives any of them. E.g. turn Qubit's base 50 degrees from
where it is (in a venv with the robot's SDK; `.venvs/lerobot` for an SO-101):

```bash
.venvs/lerobot/bin/python -m iron_fleet.run rotate --robot Qubit --joint shoulder_pan --degrees 50
```

## Live inference (SO-101 + OpenPI)

Two venvs: openpi venv serves the policy over WebSocket; lerobot venv controls the robot.

Set up once per machine:

```bash
bash inference/openpi/setup.sh   # creates .venvs/openpi, clones vendor/openpi
bash iron_fleet/robots/lerobot/setup.sh  # creates .venvs/lerobot
```

Run inference from the QuantyCat console Run tab. Runtime settings come from
`$QUANTYCAT_DEPLOYMENTS/profiles/openpi_run.json`; missing profile is an error.
Set `control.policy_trajectory_hz` to the policy's normal trajectory rate to preserve
its timing, or lower it to time-dilate policy motion while retaining the configured
robot command-loop rate. The value is required and cannot exceed
`1 / control.control_period_s`.

Key env vars:

| Variable | Default | Purpose |
|---|---|---|
| `CHECKPOINT` | none — must be set, or pass `--checkpoint <path>` | checkpoint to load |
| `CONFIG` | `$QUANTYCAT_DEPLOYMENTS/profiles/openpi_run.json` | deployment config |
| `SERVER_PORT` | `8765` | WebSocket port between policy server and robot control |

## Known issues

- **OpenCV 4.6 + high-res segfault** — handled in `iron_fleet/calibration/apriltag.py` by
  resizing frames to ≤1280px before detection.
- **macOS AVFoundation serial ordering** — use `pr-assign-cameras` (from prime-radiant) for
  visual confirmation rather than relying on serial matching alone.


## QuantyCat Core and legacy service

QuantyCat Core is now the backend for the Python SDK and Prime Radiant Small UI.
Use `quantycat setup` to start/reuse Core. Iron Fleet supplies its hardware
adapters and kinematics; a second Iron Fleet service is not needed for that flow.

`iron_fleet/legacy/quantycat_service.py` is retained for legacy SDK JSON definitions,
hand-guiding compatibility, and adapter contract tests. Core still imports shared
setup adapters, model/error types, validation, and device locking from
`quantycat_runtime`; that folder is not dead code and must not be deleted as part
of cleanup. Do not run the two services against the same physical robot.

### Legacy service only

The earlier robot execution developed inside `quantycat-library` lives in
`iron_fleet.quantycat_runtime`. The public `quantycat` package is an HTTP client;
it does not import this runtime or distribute hardware algorithms.

```bash
pip install -e '.[so101]'
python -m iron_fleet.legacy.quantycat_service --host 127.0.0.1 --port 8765
```

The old module path remains a thin compatibility shim. You can also use the
installed `iron-fleet-serve` entry point. The prepared workstation
environment is `.venvs/quantycat-service`. Starting the service does not open
hardware. It reuses the saved SDK JSON store by default; `--config-dir` chooses a
separate server-owned store. Existing console/deployment files are unchanged.

The service exposes versioned JSON operations, server-owned setup/robot sessions,
calibration uploads, command results, request deduplication, and session leases.
The client sends heartbeats. Expired resources are closed only when cleanup
succeeds. No motion request is automatically retried. Model adapters are installed
and registered privately here, not by remote client code.

`IRON_FLEET_API_TOKEN` enables bearer authentication; a token is required for
non-loopback binding. The development server needs authenticated HTTPS ingress
before remote hosting. USB hardware still needs a runtime/agent near the device.

Tests (with the sibling SDK installed for HTTP integration tests):

```bash
pytest -q tests/test_quantycat_service.py tests/quantycat_runtime
```

These tests use fake hardware. The service boundary does not change controller
speeds, targets, calibration, or existing home/motion settings on startup.
