# "Up-down BAD" ACT policy: handoff to the robot integration This repository holds the policy that carries a part **without pin (BAD / defective)** from the inspection camera to the **white box** and releases it. `bad` names the part's condition and the box it goes to; it does not describe the quality of the demonstrations, which are all successful. The recommended checkpoint is `up-down-bad_v4/checkpoints/015000/` (see the README for the ranking). ``` MikelRubi/act-up-down-bad ├── README.md ← model card, recommended checkpoint, results ├── HANDOFF.md ← this document ├── TRAINING_LOG.md ← every training run, why it was made, ranking ├── tools/ │ ├── run_policy.py ← control loop for the SO-101 (and --dry-run-dataset mode without hardware) │ ├── robust_eval.py ← offline evaluation with confidence intervals │ └── eval_bad.py ← first offline evaluation script └── up-down-bad_vN/checkpoints// ├── pretrained_model/ ← the policy (ACTPolicy.from_pretrained) + normalisers ├── dataset_features.json ← names / order / shapes of inputs and outputs (no dataset needed) └── training_state/ ← optimizer, scheduler and RNG, to resume training ``` ## 1. Where it fits in the full system ``` [Policy 1: pick] picks the part and holds it up in front of the inspection camera │ [Destination selector] decides which box the part goes to │ · in this project: the pin classifier (MikelRubi/pin-classifier, front + wrist views) says PIN / NO PIN, │ and the operator's order maps that to a box (usually GOOD = with pin → green, BAD = no pin → white) │ ├── green box → [Up-down GOOD policy] (MikelRubi/act-up-down-good, not this one) └── white box → [Up-down BAD policy] ← THIS ONE ``` Each sorting policy is **a trajectory to one specific box**, not a quality decision. This policy does not know why the part goes to the white box and does not read the classifier: it only executes the path from the camera to that box. The robot's orchestrator keeps the map *chosen destination → policy* and calls it. Changing the selection criterion therefore needs no retraining; only a new box requires recording and training its own policy. In the team's demo app (`30_full_demo_app.py` in github.com/iker-azur/hackathon-robotekin, `demos/06_imitation_learning`) that map is `policy_routes.json`, and this policy is run through `run_policy.py`. ## 2. Contract: what it expects at the start and where it ends Measured on the 88 valid demonstrations of the first 20 datasets (LeRobot follower units: degrees; gripper 0–100): | | pan | lift | elbow | wrist_flex | wrist_roll | gripper | |---|---|---|---|---|---|---| | **Start** (mean) | −33 | 1 | −38 | 1 | 114 | 5 | | Start (std) | 9 | 26 | 43 | 33 | **61** | 5 | | Start (min … max) | −49…−12 | −64…41 | −96…50 | −73…78 | −58…167 | 1…26 | | **End** (mean) | 6 | −100 | 29 | 100 | −5 | 1 | | End (std) | 8 | 10 | 10 | 4 | 9 | 1 | - **Precondition:** the part is already **held in the gripper (closed, ≈5)** in front of the inspection camera, in the pose the pick policy leaves it. Start poses vary a lot (especially `wrist_roll`), so the arm does not need an exact pose; but if the handoff pose falls outside the ranges above, the policy is outside what it saw. - **What it does:** carries the part to the white box, **opens the gripper (≈35, around mid-trajectory)**, releases it, and returns to the **rest pose** with the gripper closed. - **Duration:** median 6.7 s (p10 5.3 s, p90 8.6 s, max 20 s). - **End condition** (ACT does not output "done"): `run_policy.py` stops once the gripper **has opened above 20** and the state is within tolerance of the end pose (`REST_POSE ± REST_TOLERANCE` in the script), or after `--max-seconds` (15 s by default). ## 3. Exact inputs and outputs | Key | Content | |---|---| | `observation.images.front` | front / inspection camera, RGB 480×640, 30 fps | | `observation.images.wrist` | wrist camera, RGB 480×640, 30 fps | | `observation.state` | 6 measured follower positions | | `observation.environment_state` | 6 **joint velocities**: `state(t) − state(t−3 frames)` (0.1 s at 30 Hz; at start-up, relative to the first state). Only if the checkpoint's `dataset_features.json` lists it (v4). `run_policy.py` computes it with `add_velocity()` | | `action` (output) | 6 **absolute** position targets, same order | **Why velocity:** with one image and the current position, ACT cannot tell where or how fast the arm is moving, and the operator's command always leads the measured position. Without it, every model's first action had a larger error than staying still. If you integrate the policy in another loop, **compute the velocity the same way**: same 3-cycle lag at 30 Hz, same joint order, history reset for every part. Joint order: `shoulder_pan, shoulder_lift, elbow_flex, wrist_flex, wrist_roll, gripper` (`*.pos` keys of `SO101Follower`). Robot `so101_follower` with `use_degrees=True` (the LeRobot 0.6.1 default). Normalisation lives inside `pretrained_model/` (pre/post-processors): pass raw values. **The cameras must be named exactly `front` and `wrist`** in the robot configuration, and be mounted, framed and lit as in the recordings. If the robot PC's recorder uses other names (e.g. `overhead`), map them to these two. A camera moved to another place is the quickest way to make the policy fail. ## 4. How to run it Requires **LeRobot 0.6.1** (used to record the data and train). After downloading the repository: ```bash # 1) Without hardware: check the environment and the model on a recorded episode python tools/run_policy.py --policy up-down-bad_v4/checkpoints/015000/pretrained_model \ --dry-run-dataset /up-down-bad_all_vel --episode 95 # dataset with the velocity column # 2) On the robot (MOVES THE ARM): part already held in front of the camera python tools/run_policy.py --policy up-down-bad_v4/checkpoints/015000/pretrained_model \ --port --front-camera --wrist-camera \ --robot-id [--calibration-dir ] ``` `up-down-bad_all_vel` is the local combined dataset with the velocity column (see section 6); it is not on the Hub. To integrate it in an orchestrator, use the functions in `run_policy.py`: `load_policy()` once at start-up, and for each part sent to the white box `policy.reset()` + a new history `deque` + a new `ReplanBlend(12, n_action_steps)` → 30 Hz loop: `velocity = add_velocity(...)` → `act(...)` → `robot.send_action(...)` until `finished(...)`. **Reset all three before each part**: ACT keeps a queue of pending actions, and the velocity history and the blending count cycles from the start of the part. **Blending at replanning (`--blend 12`, on by default):** at each replan, during the first 12 cycles, the action moves gradually from "position + gain × velocity" to the policy's chunk. The policy knows where to go, but its first action after replanning is offset; the kinematic rule knows how the arm is moving at that instant. Offline it lowers the first-action error from 4.4 to 1.9 and the whole executed trajectory error by 10 %. `--blend 0` uses only the policy. Safety and control parameters: - `--max-relative-target 5`: limits each command step to 5° (or 5 gripper points), as during recording. For the first trials keep it and keep a hand on the stop. - `--n-action-steps 25`: re-observes every 25 actions (0.8 s) instead of executing the whole 100-action chunk. Offline, the error grows with the horizon (≈5 at step 0 → ≈17 at step 99), so replanning more often should help; 10 gives a tighter loop at the cost of more compute. ## 5. Current status Evaluated on **14 unseen episodes**: 9 old (4, 14, 24, 35, 45, 55, 65, 75, 85) and 5 from the new recordings (95, 115, 125, 140, 150). Every metric is measured on the action the robot would execute replanning every 24 frames, with a 95 % bootstrap confidence interval over episodes. | Acceptance target (all at once) | Threshold | |---|---| | First-action error | upper bound of the 95 % CI **below "stay still"** (≈ 3.3) | | Gripper opening F1 (gripper > 30) | ≥ 0.70 | | Correct releases | 14/14 | | Improvement over "copy the state" | ≥ 50 % | | Arm pose at release | ≤ the spread of the demonstrators themselves | | Release timing | ≤ 0.5 s error | | Model | First action (still ≈ 3.3) | Improvement | Release pose | Timing | Gripper F1 | |---|---|---|---|---|---| | v1 25K (79 ep., no velocity) | 4.68 | 50 % | 8.2° | 0.31 s | 0.71 | | v3 20K (129 ep., no velocity) | 4.55 | 54.5 % | 9.8° | 0.36 s | 0.59 | | **v4 15K (129 ep., velocity) + blend** | **1.87** | **54 %** | **5.3°** | **0.34 s** | 0.66 | F1 at threshold 30 is fragile on the new recordings, where the operator opened the gripper only to 16–36; release timing and pose do not depend on a threshold. These are **offline** measurements (prediction vs. the expert's action). **They do not replace a robot test**: none of these policies has run on the real arm yet. The real signal is: of N parts sent to the white box, how many end up inside and the arm returns to rest. ## 6. Provenance (to retrain or debug) - **Data:** the 27 `MikelRubi/up-down-bad_*` datasets on the Hub (task "Carry the bracket from the camera to the bad box and release it"), combined locally into `up-down-bad_all` (153 episodes, 30 fps; episodes 0–90 are the first 20 datasets). `up-down-bad_all_vel` is the same copy (videos linked) with the velocity column. Excluded as faulty: 28 (reversed), 32 and 112 (cut), 41 (does not return to rest), 101–103 and 110–111 (1–20 frame recordings), 131 (the gripper never opens). 129 for training, 14 for evaluation. - **Training (v4):** `lerobot-train` 0.6.1, default ACT (ImageNet ResNet18, chunk 100, VAE, lr 1e-5), batch 8, image augmentation, AMP, on `up-down-bad_all_vel`. The full output, with optimizer state, is in `up-down-bad_v4/`; v1–v3 are in `up-down-bad_v1…v3/`. - **Resume:** `lerobot-train --resume=true --config_path=up-down-bad_v4/checkpoints//pretrained_model/train_config.json` (adjust the dataset path inside `train_config.json` to your local copy). On Windows without symlink privileges, LeRobot fails to create the `last` symlink; the team used a small wrapper that skips it.