|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
Replays the actions of an episode from a dataset on a robot. |
|
|
|
Example: |
|
|
|
```shell |
|
python -m lerobot.replay \ |
|
--robot.type=so100_follower \ |
|
--robot.port=/dev/tty.usbmodem58760431541 \ |
|
--robot.id=black \ |
|
--dataset.repo_id=aliberts/record-test \ |
|
--dataset.episode=2 |
|
``` |
|
""" |
|
|
|
import logging |
|
import time |
|
from dataclasses import asdict, dataclass |
|
from pathlib import Path |
|
from pprint import pformat |
|
|
|
import draccus |
|
|
|
from lerobot.common.datasets.lerobot_dataset import LeRobotDataset |
|
from lerobot.common.robots import ( |
|
Robot, |
|
RobotConfig, |
|
koch_follower, |
|
make_robot_from_config, |
|
so100_follower, |
|
so101_follower, |
|
) |
|
from lerobot.common.utils.robot_utils import busy_wait |
|
from lerobot.common.utils.utils import ( |
|
init_logging, |
|
log_say, |
|
) |
|
|
|
|
|
@dataclass |
|
class DatasetReplayConfig: |
|
|
|
repo_id: str |
|
|
|
episode: int |
|
|
|
root: str | Path | None = None |
|
|
|
fps: int = 30 |
|
|
|
|
|
@dataclass |
|
class ReplayConfig: |
|
robot: RobotConfig |
|
dataset: DatasetReplayConfig |
|
|
|
play_sounds: bool = True |
|
|
|
|
|
@draccus.wrap() |
|
def replay(cfg: ReplayConfig): |
|
init_logging() |
|
logging.info(pformat(asdict(cfg))) |
|
|
|
robot = make_robot_from_config(cfg.robot) |
|
dataset = LeRobotDataset(cfg.dataset.repo_id, root=cfg.dataset.root, episodes=[cfg.dataset.episode]) |
|
actions = dataset.hf_dataset.select_columns("action") |
|
robot.connect() |
|
|
|
log_say("Replaying episode", cfg.play_sounds, blocking=True) |
|
for idx in range(dataset.num_frames): |
|
start_episode_t = time.perf_counter() |
|
|
|
action_array = actions[idx]["action"] |
|
action = {} |
|
for i, name in enumerate(dataset.features["action"]["names"]): |
|
action[name] = action_array[i] |
|
|
|
robot.send_action(action) |
|
|
|
dt_s = time.perf_counter() - start_episode_t |
|
busy_wait(1 / dataset.fps - dt_s) |
|
|
|
robot.disconnect() |
|
|
|
|
|
if __name__ == "__main__": |
|
replay() |
|
|