| """Minimal loader for openroboto-ai/axis-franka-datapool. |
| |
| Install with: pip install "lerobot>=0.4" torch numpy |
| """ |
|
|
| from __future__ import annotations |
|
|
| import numpy as np |
| import torch |
| from torch.utils.data import Dataset |
|
|
| FINGER_OPEN = 0.04 |
| PI05_DT = 1.0 / 15.0 |
|
|
|
|
| def _closedness(fingers: torch.Tensor) -> torch.Tensor: |
| return torch.clamp(1.0 - fingers.mean(dim=-1) / FINGER_OPEN, 0.0, 1.0) |
|
|
|
|
| def to_pi05_droid(state: torch.Tensor, action: torch.Tensor): |
| """Convert raw 9D qpos/qpos-target into Pi0.5-Axis's 8D DROID view.""" |
| if state.shape[-1] != 9 or action.shape[-1] != 9: |
| raise ValueError(f"Expected 9D state/action, got {state.shape}/{action.shape}") |
| converted_state = torch.cat([state[..., 2:9], _closedness(state[..., :2])[..., None]], dim=-1) |
| arm_action = torch.clamp((action[..., 2:9] - state[..., 2:9]) / PI05_DT, -1.0, 1.0) |
| converted_action = torch.cat([arm_action, _closedness(action[..., :2])[..., None]], dim=-1) |
| return converted_state, converted_action |
|
|
|
|
| class AxisFrankaDataset(Dataset): |
| """LeRobot-backed dataset with explicit raw-joint or Pi0.5/DROID action view.""" |
|
|
| def __init__( |
| self, |
| repo_id="openroboto-ai/axis-franka-datapool", |
| *, |
| revision="v0.1-metadata", |
| action_space="joint_position_target", |
| sample_hz=30, |
| root=None, |
| ): |
| from lerobot.datasets.lerobot_dataset import LeRobotDataset |
|
|
| if action_space not in {"joint_position_target", "pi05_droid"}: |
| raise ValueError("action_space must be 'joint_position_target' or 'pi05_droid'") |
| if sample_hz not in {15, 30}: |
| raise ValueError("sample_hz must be 15 or 30") |
| self.raw = LeRobotDataset( |
| repo_id=repo_id, |
| revision=revision, |
| root=root, |
| download_videos=False, |
| ) |
| self.action_space = action_space |
| if sample_hz == 30: |
| self.indices = None |
| else: |
| |
| |
| |
| |
| episodes = self.raw.meta.episodes |
| starts = np.asarray(episodes["dataset_from_index"], dtype=np.int64) |
| stops = np.asarray(episodes["dataset_to_index"], dtype=np.int64) |
| self.indices = np.concatenate( |
| [np.arange(start, stop, 2, dtype=np.int64) for start, stop in zip(starts, stops)] |
| ) |
|
|
| def __len__(self): |
| return len(self.raw) if self.indices is None else len(self.indices) |
|
|
| def __getitem__(self, index): |
| raw_index = int(index) if self.indices is None else int(self.indices[index]) |
| sample = self.raw[raw_index] |
| if self.action_space == "joint_position_target": |
| return sample |
| result = dict(sample) |
| result["observation.state"], result["action"] = to_pi05_droid( |
| sample["observation.state"], sample["action"] |
| ) |
| return result |
|
|
|
|
| def load_dataset(**kwargs): |
| """Convenience entry point; keyword arguments are passed to AxisFrankaDataset.""" |
| return AxisFrankaDataset(**kwargs) |
|
|