aic-cheatcode-v3 / README.md
DWLKB's picture
Initial: 200 CheatCode episodes (100 SFP + 100 SC)
206cf50 verified
|
Raw
History Blame Contribute Delete
12.7 kB
# AIC CheatCode Dataset
LeRobot-compatible dataset of expert-teacher cable-insertion trajectories,
collected inside the AI for Industry Challenge (AIC) Gazebo simulation with
`ground_truth:=true` so every port/plug/TCP pose is logged exactly. The
teacher is the reference **CheatCode** policy (`aic_example_policies.ros.CheatCode`).
## What is in it
- **N episodes** — one per trial. Each episode is a full approach + insertion
attempt (truncated just after the closest approach, so the steady-state
post-insertion hold is mostly absent).
- Two trial types, interleaved by episode index:
- `sfp` — SFP module → SFP port on a NIC card
- `sc` — SC plug → SC optical port
- Three wrist-mounted cameras at 1152×1024 RGB, 20 Hz, H.264 CRF 23 (mp4).
- Full per-frame ground-truth labels for the target port's 6D pose and 9
cuboid keypoints, plus the plug, the TCP and the task board.
Successes and partial / failed trials are saved the same way; the distinction
lives in `meta/episodes.jsonl` (`success_tier3`).
## Layout
```
<dataset_root>/
├── README.md # this file
├── meta/
│ ├── info.json # dataset schema + fps
│ ├── episodes.jsonl # one row per episode
│ ├── tasks.jsonl # task type dictionary
│ └── validator_report.json # (optional) sanity audit
├── data/chunk-000/
│ └── episode_XXXXXX.parquet # 20 Hz time series
├── videos/chunk-000/
│ ├── observation.images.left/episode_XXXXXX.mp4
│ ├── observation.images.center/episode_XXXXXX.mp4
│ └── observation.images.right/episode_XXXXXX.mp4
└── assets_snapshot/
├── camera_info.json # K, D, size, cam←tcp static
├── keypoints_sfp.json # port frame 9-keypoint spec
└── keypoints_sc.json
```
## Parquet schema (per frame)
### Indexing
| column | type | meaning |
|---|---|---|
| `timestamp` | float | seconds since the first frame of this episode (wall clock) |
| `frame_index` | int | 0-based within the episode |
| `episode_index` | int | 0-based, unique within the dataset |
| `task_index` | int | 0 = SFP trial, 1 = SC trial |
### Observations
| column | shape | units | notes |
|---|---|---|---|
| `observation.images.{left, center, right}` | `(H, W, 3)` uint8 RGB | pixels | stored in mp4; read with imageio / cv2 / lerobot loader |
| `observation.state.joints` | `(7,)` | rad (joint 1-6) + m (gripper width, index 7) | current joint positions |
| `observation.state.gripper` | `(1,)` or None | m | Gazebo's `/gripper_state`; may be null when the stock eval container doesn't publish it |
| `observation.wrench` | `(6,)` | N, N·m | `[fx, fy, fz, tx, ty, tz]` at the F/T sensor |
| `observation.tcp_pose_actual` | `(7,)` | m + unit quat (xyzw) | current gripper TCP in base_link: `[x, y, z, qx, qy, qz, qw]` |
| `observation.tcp_pose_target` | `(7,)` | m + quat | controller reference TCP |
| `observation.tcp_velocity` | `(6,)` | m/s + rad/s | `[vx, vy, vz, ωx, ωy, ωz]` |
### Actions (teacher commands)
| column | shape | notes |
|---|---|---|
| `action.pose_command` | `(7,)` or None | last `MotionUpdate.pose` published by CheatCode (xyz + xyzw quat in base_link) |
| `action.joint_command` | `(7,)` or None | Joint-mode command; always `None` with CheatCode (Cartesian-only) |
### Labels (ground truth, always populated)
All 6D poses are `[x, y, z, qx, qy, qz, qw]` in the robot's **base_link** frame.
| column | shape | meaning |
|---|---|---|
| `labels.port_pose_base` | `(7,)` | target port's link pose |
| `labels.plug_pose_base` | `(7,)` | plug tip link pose |
| `labels.gripper_tcp_pose_base` | `(7,)` | `gripper/tcp` |
| `labels.task_board_pose_base` | `(7,)` | task board base link |
| `labels.port_keypoints_3d_base` | `(9, 3)` | 9 keypoints defining the port cavity as a 3D cuboid, transformed into base_link |
| `labels.port_keypoints_2d` | `dict[cam→(9, 2)]` | per-camera pixel projection of the 9 keypoints (already distortion-rectified) |
| `labels.port_keypoints_visible` | `dict[cam→(9,)]` uint8 | 1 = keypoint is in front of the camera AND inside the image bounds |
| `labels.port_bbox_2d` | `dict[cam→(4,)]` or None | axis-aligned 2D bbox of the visible keypoints: `[x0, y0, x1, y1]` |
| `labels.all_ports` | `list[dict]` | Per-port labels for every port physically present on the active module. See below. |
The `labels.port_*` columns above only cover the **target** port for the trial.
`labels.all_ports` contains labels for **every** port visible in the scene so
perception models can learn to detect all ports + select the target using the
challenge's `Task.port_name` (which says "insert into `sfp_port_0` or
`sfp_port_1`" for SFP trials). SFP trials: 2 entries
(`sfp_port_0`, `sfp_port_1`); SC trials: 1 entry (`sc_port_base`).
Each element is a dict:
| key | shape | notes |
|---|---|---|
| `port_name` | str | `sfp_port_0`, `sfp_port_1`, or `sc_port_base` |
| `is_target` | bool | True for the entry matching `Task.port_name` |
| `pose_base` | `(7,)` | 6D pose in `base_link` |
| `keypoints_3d_base` | `(9, 3)` | 9 keypoints in `base_link` |
| `keypoints_2d` | `dict[cam→(9, 2)]` | per-camera pixel projection |
| `keypoints_visible` | `dict[cam→(9,)]` uint8 | per-camera visibility |
| `bbox_2d` | `dict[cam→(4,)]` or None | per-camera axis-aligned bbox |
Keypoint order is identical to the `names` list in `assets_snapshot/keypoints_{sfp,sc}.json`:
`[center, mouth_tl, mouth_tr, mouth_bl, mouth_br, base_tl, base_tr, base_bl, base_br]`.
The 4 `mouth_*` points lie on the port entrance plane; the 4 `base_*` points
are the same rectangle translated into the port along the local +Z axis.
## episodes.jsonl (per episode)
```json
{
"episode_index": 0,
"task_index": 0,
"length": 312,
"trial_type": "sfp",
"trial_id": "trial_1",
"seed": 100000,
"randomization": {
"board_pose": {"x": ..., "y": ..., "yaw": ...},
"rails": { "nic_rail_0": {"entity_present": true, "entity_pose": {...}}, ... },
"grasp": { "gripper_offset": {...}, "roll": ..., "pitch": ..., "yaw": ... },
"cable_type": "sfp_sc_cable"
},
"target": {
"cable_name": "cable_0", "plug_type": "sfp", "plug_name": "sfp_tip",
"port_type": "sfp", "port_name": "sfp_port_0",
"target_module_name": "nic_card_mount_3", "time_limit": 180
},
"scoring": { /* full aic_engine scoring.yaml subsection */ },
"success_tier3": 75.0
}
```
- `success_tier3` — scalar: 75 = full insertion, 38–50 = partial insertion,
0–25 = proximity only, negative = wrong port (rare).
- `randomization` — full sampled scene description (reproduces the scene
given the seed).
## Coordinate frames
- `base_link` is the UR5e base; all `*_pose_base` labels are expressed in it.
- `gripper/tcp` is the tool frame at the fingertip midpoint.
- Camera `{left, center, right}` optical frames are rigidly mounted on the
wrist. Their extrinsic wrt `gripper/tcp` is constant and stored in
`assets_snapshot/camera_info.json` as `cam_T_tcp` (4×4, camera-from-tcp).
Per-frame camera-from-base is `cam_T_tcp @ inv(tcp_pose_actual_matrix)`.
- Port frame origin is **inside the cavity**, not at the entrance. The
entrance plane is at local `z = z_mouth` (see
`assets_snapshot/keypoints_{sfp,sc}.json`), and CheatCode uses `z_offset`
relative to this convention.
## Minimal loading recipe
```python
import json, pathlib, pandas as pd, imageio, numpy as np
DS = pathlib.Path("<dataset_root>")
# --- episodes metadata ---
eps = [json.loads(l) for l in open(DS/"meta"/"episodes.jsonl")]
print(len(eps), "episodes")
# --- one episode: parquet + mp4 aligned by frame_index ---
ep = eps[0]
chunk = ep["episode_index"] // 1000
df = pd.read_parquet(DS/f"data/chunk-{chunk:03d}/episode_{ep['episode_index']:06d}.parquet")
video = imageio.get_reader(
str(DS/f"videos/chunk-{chunk:03d}/observation.images.center/"
f"episode_{ep['episode_index']:06d}.mp4"))
for i, frame in enumerate(video): # frame is (H, W, 3) uint8 RGB
row = df.iloc[i]
port_pose = np.asarray(row["labels.port_pose_base"]) # (7,)
kp2d_center = np.stack(row["labels.port_keypoints_2d"]["center"]) # (9, 2)
visible = np.asarray(row["labels.port_keypoints_visible"]["center"]) # (9,)
# ... build sample
if i >= 5:
break
# --- camera intrinsics ---
cam = json.load(open(DS/"assets_snapshot/camera_info.json"))["center"]
K = np.asarray(cam["K"]) # (3, 3)
cam_T_tcp = np.asarray(cam["cam_T_tcp"]) # (4, 4) static
```
### Quality filtering
For imitation learning on clean demonstrations:
```python
clean = [e for e in eps if (e.get("success_tier3") or 0) >= 70]
```
For perception (the label is always correct even on partial trials):
```python
usable = eps # keep everything
```
For occlusion-robust training you can drop frames where no camera sees the
port:
```python
vis = np.stack([np.asarray(row["labels.port_keypoints_visible"][c])
for c in ("left", "center", "right")]) # (3, 9)
ok = (vis.sum(axis=1) >= 5).any() # at least one cam has ≥5/9 visible
```
### 2D keypoints → 3D port pose (optional PnP)
```python
import cv2
kp_local = np.asarray(
json.load(open(DS/"assets_snapshot/keypoints_sfp.json"))["points_local"]) # (9, 3)
kp2d = np.stack(row["labels.port_keypoints_2d"]["center"]) # (9, 2)
vis = np.asarray(row["labels.port_keypoints_visible"]["center"]).astype(bool)
ok, rvec, tvec = cv2.solvePnP(
kp_local[vis], kp2d[vis], K, distCoeffs=np.zeros(5),
flags=cv2.SOLVEPNP_ITERATIVE)
```
## Use cases
- **Port 6D pose regression** — input: one or three camera images, target:
`labels.port_pose_base` or `labels.port_keypoints_2d`. The 9-keypoint
supervision is compatible with heatmap-style keypoint models and direct
regression.
- **Imitation learning** — use `observation.*` as input history and
`action.pose_command` as the target; use `observation.tcp_pose_actual` if
you prefer delta actions. Task-condition with `task_index`.
- **Hybrid policy** — run a learned port-pose estimator on the images, then
reuse CheatCode's controller logic with the estimate instead of the GT TF.
## Randomization space (per trial)
Sampled independently from `seed = start_seed + episode_index`.
- **Board pose** — xy jitter ±5 cm around (0.15, −0.2), yaw ±0.5 rad around π.
- **NIC card (SFP trial)** — exactly one card, target rail uniform on {0..4};
translation in [−0.0215, 0.0234] m and yaw in [−10°, +10°]; target port
`sfp_port_{0|1}`.
- **SC port (SC trial)** — exactly one port, target rail 0 or 1, translation in
[−0.06, 0.055] m.
- **Grasp offset** — Gaussian noise around the nominal grasp: σ = 2 mm (xyz)
and σ = 0.04 rad (rpy), matching the qualification-spec uncertainty exactly.
## Known quirks
- **Gripper fingers appear slightly open around the plug.** The challenge
config sets `attach_cable_to_gripper=True`, which installs a logical fixed
joint between the plug and `gripper/tcp` rather than relying on physical
grasping, so the finger width doesn't change to match the plug dimensions.
This is cosmetic — simulation physics and all labels remain correct.
- **Frame 0 of every episode is a post-reset settled state**, not the
instant the trial started. The collector defers recording until
`/joint_states` shows sample-to-sample Δposition under ~0.02 rad for 3
consecutive ticks, which skips the one-frame teleport the engine
produces when returning the arm to home between trials.
- **Episode lengths vary** (typically 200–700 frames). Truncation cuts at
`argmin(plug→port) + 20` frames so a short stabilisation tail is kept
without the full 5 s CheatCode hold or the engine-driven reset motion.
- **`observation.state.gripper` may be null** for the entire episode if the
eval container doesn't publish `/gripper_state`. The gripper width is
included in `observation.state.joints` (last element) regardless.
- **Partial insertions are kept** (`success_tier3 < 70`); filter at train
time if your objective needs only clean demonstrations.
## Reproducing a scene
Every `episodes.jsonl` row carries a `seed` and a full `randomization` dict.
Re-running the sampler with that seed reproduces the exact scene
configuration (subject to the ROS 2 / Gazebo message-scheduling
non-determinism noted in the collection README).