diff --git a/docs/sorting/06_INTEGRATION.md b/docs/sorting/06_INTEGRATION.md new file mode 100644 index 0000000..13d8b10 --- /dev/null +++ b/docs/sorting/06_INTEGRATION.md @@ -0,0 +1,61 @@ +# 06 Integration + +How sorting is started, watched and stopped, using the same skill machinery as Move object. + +--- + +## 1. Robot side (Thor, lumi-api) + +| Endpoint | Body | Answer | +|---|---|---| +| `POST /skills/sort` | `{}` (version 1: everything on the plate) | 200 started; 409 another skill runs; 400 with the reason when a check fails | +| `GET /skills/state` | — | existing: `status` (running / done / refused / stopped / failed), `reason`, `took_s`, last log lines; sorting adds `sort: {done, left, failed, current: {colour, box}}` | +| `GET /sort/layout`, `POST /sort/layout` | box positions, plate centre | read and set `data/sort_layout.json` (later: from the app) | + +Checks before starting (reason words in English and Korean, like the other skills): + +| Check | Refusal | +|---|---| +| arm enabled | "Switch on the arm first." | +| gripper fitted (`gripper.FITTED`) and hand empty (AI_1) | "My hand isn't empty." | +| no other skill or task | existing busy answer | +| layout file present | "The boxes aren't set up." | +| policy file matches the control mode | "The sorting program doesn't match this arm." | + +Code: + +| File | Contents | +|---|---| +| `manipulation/sort.py` | the run loop of [02](02_TASK_DESIGN.md) §2, failure counting, speech lines | +| `policies/sort/` | `policy.onnx`, `config.json` (mode, rates, scaling, run id), `obs.py` | +| `robot/servo.py` | only for mode A: enable, stream joint targets, disable, with the existing checks | +| `api/server.py` | the endpoints above, registered like `/skills/move` | +| `tests/test_sort.py` | observation parity with simulation, refusals, STOP mid-episode (arm faked) | + +The voice assistant can start it later with "sort the balls" / "공 정리해" through the intent bank; not in +version 1. + +--- + +## 2. App side (Lumi app) + +| Change | Where | +|---|---| +| SORT tile in COMMANDS → ARM & OBJECTS, needs arm on and hand empty | `src/app/(robot)/commands.tsx` (`TILES.arm`), icon in `src/ui/CommandIcon.tsx` | +| Request `POST /skills/sort`, marked as a skill so the status line follows `/skills/state` | `src/lib/commands.ts` (`sortRequest`) | +| Status line: "Sorting: 2 of 4", then "Done", or the robot's reason | existing skill status handling; counts from `sort` in `/skills/state` | +| Texts in English and Korean | `src/lib/i18n.tsx` (`cmdSort`, `cmdSortHint`, `cmdAskSort`, counts) | +| Asks first (it moves the arm) | `ConfirmDialog`, like Move object | +| Docs | `docs/COMMANDS.md` row for Sort | + +STOP on every screen already stops skills; no new stop path. + +--- + +## 3. Deploy steps + +1. Export the student policy (`rl/sorting/export.py`) → `policy.onnx`, `config.json`, `obs.py`, run id. +2. Copy to `real/thor/policies/sort/` in this repository, commit, sync to the Thor (`tools/thor_sync/sync.sh`). +3. Run `tests/test_sort.py` on the Thor. +4. Restart lumi-api only when the base is not driving (`GET /status` → `base.move_status`). +5. Dry run ([05](05_SIM_TO_REAL.md) §5 step 1) with the owner at the robot. diff --git a/docs/sorting/07_PLAN.md b/docs/sorting/07_PLAN.md new file mode 100644 index 0000000..813b96e --- /dev/null +++ b/docs/sorting/07_PLAN.md @@ -0,0 +1,117 @@ +# 07 Plan + +Phases in order. A phase is closed only by its check, written as a result in [08_EXPERIMENT_LOG.md](08_EXPERIMENT_LOG.md). +"Robot" means the owner is at the robot with STOP ready; everything else is done without moving it. + +| Phase | Name | Robot needed | Depends on | +|---|---|---|---| +| 0 | Hardware and measurements | yes (no arm motion) | — | +| 1 | System identification | yes | 0 | +| 2 | Simulation scene and robot model | no | 0 (numbers), 1 (numbers, later) | +| 3 | Training setup (where Isaac Lab runs) | no | — (can run beside 0–2) | +| 4 | Teacher policy | no | 2, 3 | +| 5 | Student policy and sim-to-sim | no | 4 | +| 6 | Robot skill and app button | yes for tests | 1 (mode), can start beside 4 | +| 7 | Real trials | yes | 5, 6 | +| 8 | Write-up and portfolio | no | 7 | + +--- + +## Phase 0: Hardware and measurements + +| Task | Output | +|---|---| +| Fit the Zimmer with the new straight fingers; set `FITTED = True` | gripper on the robot | +| Measure the tip gap open and closed, finger length, width, mass, material | numbers in [01](01_HARDWARE_FACTS.md) §2 | +| Teach the new grasp point (free-drive tips onto a ball, read the flange pose) | grasp point in the flange frame | +| Measure the balls: diameter, mass, colours; pick 2 colours (red, blue) | numbers in [02](02_TASK_DESIGN.md) §1 | +| Choose boxes and plate; tape the layout; measure positions with the arm (touch each corner, read the hand position) | `data/sort_layout.json` | +| AI_1 closed on a ball and on nothing, 10 each | thresholds for "holding" | + +**Check:** a close on a ball held by hand gives an AI_1 clearly between open and shut-on-nothing; the open gap +clears the ball by ≥ 8 mm each side. + +## Phase 1: System identification + +| Task | Output | +|---|---| +| Read the controller version; test servo mode over the JSON port (5 s small motion on J6, STOP ready) | mode A or B decided | +| Step responses in the chosen mode ([05](05_SIM_TO_REAL.md) §1) | `rl/sorting/sysid/*.csv`, fitted lag and delay | +| Gripper strokes ×40 | stroke time, spread | +| Camera on balls: detection rate, colour reading, bias and noise at 5 positions | perception numbers | +| Ball bounce and roll films | contact numbers | + +**Check:** a script replays the recorded commands in MuJoCo and the simulated joint angles follow the recorded +ones within the measured noise; the colour rule reads both chosen colours right in ≥ 95 % of readings. + +## Phase 2: Simulation scene and robot model + +| Task | Output | +|---|---| +| Gripper model with the new fingers (URDF + MJCF), attached at the measured offset | `sim/sorting/zimmer_straight.*` | +| MuJoCo sorting scene: table, plate, boxes, balls at measured values; fixed column and head bodies | `sim/sorting/scene.xml` | +| A scripted (not learned) pick and place in MuJoCo using IK, to prove the scene can be solved | `sim/sorting/scripted_demo.py`, a video | +| Same robot and scene in Isaac Lab (import route decided in phase 3) | `rl/sorting/assets/` | +| Kinematics check: fitted kinematics vs both simulators at 20 poses | ≤ 1 mm | + +**Check:** the scripted pick and place sorts 4 balls in both simulators; kinematics match. + +## Phase 3: Training setup + +| Task | Output | +|---|---| +| Spike, half a day at most: install Isaac Lab 3.0 (Newton, no Isaac Sim) on the Thor in a separate venv or the nvcr PyTorch container; run a stock manipulation example headless for 10 minutes | works or the exact error | +| If the Thor fails: pick a cloud x86 machine with an RTX GPU (price per hour noted), install Isaac Lab there; data transfer by git + rsync | training machine ready | +| Run a stock Isaac Lab reach or lift task to completion | baseline speed: steps per second at 4096 scenes | + +The Thor runs the robot (LLM, whisper, vision). Training on it only happens when nobody uses Lumi, and never during +a demo. + +**Check:** a stock example trains to its documented reward on the chosen machine. + +## Phase 4: Teacher policy + +| Task | Output | +|---|---| +| Environment: observations, actions (mode from phase 1), rewards, resets, curriculum ([04](04_RL.md)) | `rl/sorting/env/` | +| Unit tests: reward terms, resets, gripper stroke model, workspace limits | `rl/sorting/tests/` | +| Train the teacher, 3 seeds; tune rewards one change at a time, each a logged run | runs in [08](08_EXPERIMENT_LOG.md) | + +**Check:** teacher ≥ 95 % on the randomised set ([04](04_RL.md) §10). + +## Phase 5: Student policy and sim-to-sim + +| Task | Output | +|---|---| +| Student with robot-only observations and memory; DAgger from the teacher, then PPO fine-tune | student policy | +| Ablations: no randomisation / no sensor model / no teacher (direct PPO on student obs) | table of success rates | +| Export to ONNX; parity test: ONNX and PyTorch outputs equal for 1000 recorded inputs | `policy.onnx`, `config.json`, `obs.py` | +| Run the student in MuJoCo | MuJoCo success | + +**Check:** student ≥ 90 % in Isaac Lab randomised, ≥ 85 % in MuJoCo. + +## Phase 6: Robot skill and app button + +| Task | Output | +|---|---| +| `manipulation/sort.py`, `policies/sort/`, endpoints, `robot/servo.py` if mode A ([06](06_INTEGRATION.md)) | Thor code | +| Tests with the arm faked: observation parity, refusals, STOP | `tests/test_sort.py` passes | +| App SORT tile, texts EN + KO, status counts | Lumi app change | + +**Check:** dry run on the robot ([05](05_SIM_TO_REAL.md) §5 step 1) passes; STOP ends a run within 0.5 s. + +## Phase 7: Real trials + +Steps 2–5 of [05](05_SIM_TO_REAL.md) §5, with every trial filmed and logged, failures classified, fixes in +simulation and retrained when needed ([05](05_SIM_TO_REAL.md) §6). + +**Check:** the success criteria in [README](README.md). + +## Phase 8: Write-up and portfolio + +| Task | Output | +|---|---| +| Results page: method, numbers sim vs sim vs real, ablations, failures and what fixed them | [08](08_EXPERIMENT_LOG.md) final section | +| Side-by-side video: Isaac Lab, MuJoCo, real robot, same ball positions | 60–90 s video | +| Short technical summary (one page) for the CV and interviews | PDF | +| Clean public code (no private data, no addresses, no passwords) | repository section | diff --git a/docs/sorting/08_EXPERIMENT_LOG.md b/docs/sorting/08_EXPERIMENT_LOG.md new file mode 100644 index 0000000..a81c707 --- /dev/null +++ b/docs/sorting/08_EXPERIMENT_LOG.md @@ -0,0 +1,81 @@ +# 08 Experiment log + +Every measurement, training run and real trial session is recorded here, newest at the bottom of its table. The +raw files live next to the code (`rl/sorting/runs/`, `rl/sorting/sysid/`, Thor `logs/sort/`); this page holds the +numbers and the conclusions. + +--- + +## 1. Naming + +| Thing | Name | Example | +|---|---|---| +| Training run | `___s` | `2026-12-03_teacher_lift-reward-2x_s1` | +| Sysid session | `_sysid_` | `2026-11-28_sysid_modeB-steps` | +| Real session | `_real_` | `2026-12-15_real_one-ball-anywhere` | + +A run record says: git commit, machine, config file, what changed from the previous run and why, the result, and +what was decided because of it. + +--- + +## 2. Metrics + +| Metric | Definition | +|---|---| +| Success | ball at rest inside the target box, gripper open, within 15 s | +| Drop rate | ball left the hand outside the target box | +| Wrong box | ball at rest in the other box | +| Missed grasp | close ended without the ball (AI_1 near shut-on-nothing) | +| Unsafe stop | a safety check refused a step | +| Time to success | from episode start to success, successful episodes only | +| Smoothness | mean action-rate cost per episode | +| Real-to-sim gap | MuJoCo success − real success, same ball positions | + +Success rates are given with the number of trials and a 95 % interval (Wilson), e.g. "41 / 50 = 82 % (69–90 %)". + +--- + +## 3. Measurements + +| Date | Session | Result | Used for | +|---|---|---|---| +| | | | | + +## 4. Training runs + +| Run | Change | Isaac Lab success (randomised) | MuJoCo success | Decision | +|---|---|---|---|---| +| | | | | | + +## 5. Ablations + +| Variant | Isaac Lab | MuJoCo | Real (if tried) | +|---|---|---|---| +| Full method | | | | +| No domain randomisation | | | | +| No sensor model | | | | +| No teacher (direct PPO on robot observations) | | | | + +## 6. Real trial sessions + +| Session | Policy run | Trials | Success | Failures by cause | Notes | +|---|---|---|---|---|---| +| | | | | | | + +--- + +## 7. Portfolio checklist + +What a robotics learning team asks about, and where this project answers it: + +| Topic | Evidence | +|---|---| +| Simulation and environment design | Isaac Lab environment, MuJoCo twin, robot and gripper models ([03](03_SIMULATION.md)) | +| RL formulation | observations, actions, reward, curriculum ([04](04_RL.md)) | +| Domain randomisation from measured ranges | sysid data and the ranges table | +| Privileged teacher and student distillation | phase 5 runs and the ablation | +| Sim-to-sim and sim-to-real gap, measured | sections 4–6 above | +| Deployment on an embedded computer | ONNX policy on the Jetson Thor, timing logs | +| Safety in a real system | envelope, STOP, refusal logs ([05](05_SIM_TO_REAL.md) §4) | +| Engineering | tests, reproducible runs, seeds, this log |