|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| """
|
| Replays the actions of an episode from a dataset on a robot.
|
|
|
| Examples:
|
|
|
| ```shell
|
| lerobot-replay \
|
| --robot.type=so100_follower \
|
| --robot.port=/dev/tty.usbmodem58760431541 \
|
| --robot.id=black \
|
| --dataset.repo_id=aliberts/record-test \
|
| --dataset.episode=0
|
| ```
|
|
|
| Example replay with bimanual so100:
|
| ```shell
|
| lerobot-replay \
|
| --robot.type=bi_so100_follower \
|
| --robot.left_arm_port=/dev/tty.usbmodem5A460851411 \
|
| --robot.right_arm_port=/dev/tty.usbmodem5A460812391 \
|
| --robot.id=bimanual_follower \
|
| --dataset.repo_id=${HF_USER}/bimanual-so100-handover-cube \
|
| --dataset.episode=0
|
| ```
|
|
|
| """
|
|
|
| import logging
|
| import time
|
| from dataclasses import asdict, dataclass
|
| from pathlib import Path
|
| from pprint import pformat
|
|
|
| from lerobot.configs import parser
|
| from lerobot.datasets.lerobot_dataset import LeRobotDataset
|
| from lerobot.processor import (
|
| make_default_robot_action_processor,
|
| )
|
| from lerobot.robots import (
|
| Robot,
|
| RobotConfig,
|
| bi_so100_follower,
|
| hope_jr,
|
| koch_follower,
|
| make_robot_from_config,
|
| so100_follower,
|
| so101_follower,
|
| )
|
| from lerobot.utils.constants import ACTION
|
| from lerobot.utils.import_utils import register_third_party_devices
|
| from lerobot.utils.robot_utils import busy_wait
|
| from lerobot.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
|
|
|
|
|
| @parser.wrap()
|
| def replay(cfg: ReplayConfig):
|
| init_logging()
|
| logging.info(pformat(asdict(cfg)))
|
|
|
| robot_action_processor = make_default_robot_action_processor()
|
|
|
| robot = make_robot_from_config(cfg.robot)
|
| dataset = LeRobotDataset(cfg.dataset.repo_id, root=cfg.dataset.root, episodes=[cfg.dataset.episode])
|
|
|
|
|
| episode_frames = dataset.hf_dataset.filter(lambda x: x["episode_index"] == cfg.dataset.episode)
|
| actions = episode_frames.select_columns(ACTION)
|
|
|
| robot.connect()
|
|
|
| log_say("Replaying episode", cfg.play_sounds, blocking=True)
|
| for idx in range(len(episode_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_obs = robot.get_observation()
|
|
|
| processed_action = robot_action_processor((action, robot_obs))
|
|
|
| _ = robot.send_action(processed_action)
|
|
|
| dt_s = time.perf_counter() - start_episode_t
|
| busy_wait(1 / dataset.fps - dt_s)
|
|
|
| robot.disconnect()
|
|
|
|
|
| def main():
|
| register_third_party_devices()
|
| replay()
|
|
|
|
|
| if __name__ == "__main__":
|
| main()
|
|
|