mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-14 16:19:45 +00:00
123495250b
* refactor(dataset): split reader and writer * chore(dataset): remove proxys * refactor(dataset): better reader & writer encapsulation * refactor(datasets): clean API + reduce leaky implementations * refactor(dataset): API cleaning for writer, reader and meta * refactor(dataset): expose writer & reader + other minor improvements * refactor(dataset): improve teardown routine * refactor(dataset): add hf_dataset property at the facade level * chore(dataset): add init for datasset module * docs(dataset): add docstrings for public API of the dataset classes * tests(dataset): add tests for new classes * fix(dataset): remove circular dependecy
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
# !/usr/bin/env python
|
|
|
|
# Copyright 2025 The HuggingFace Inc. team. All rights reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import time
|
|
|
|
from lerobot.datasets.lerobot_dataset import LeRobotDataset
|
|
from lerobot.robots.lekiwi.config_lekiwi import LeKiwiClientConfig
|
|
from lerobot.robots.lekiwi.lekiwi_client import LeKiwiClient
|
|
from lerobot.utils.constants import ACTION
|
|
from lerobot.utils.robot_utils import precise_sleep
|
|
from lerobot.utils.utils import log_say
|
|
|
|
EPISODE_IDX = 0
|
|
|
|
|
|
def main():
|
|
# Initialize the robot config
|
|
robot_config = LeKiwiClientConfig(remote_ip="172.18.134.136", id="lekiwi")
|
|
|
|
# Initialize the robot
|
|
robot = LeKiwiClient(robot_config)
|
|
|
|
# Fetch the dataset to replay
|
|
dataset = LeRobotDataset("<hf_username>/<dataset_repo_id>", episodes=[EPISODE_IDX])
|
|
actions = dataset.select_columns(ACTION)
|
|
|
|
# Connect to the robot
|
|
robot.connect()
|
|
|
|
try:
|
|
if not robot.is_connected:
|
|
raise ValueError("Robot is not connected!")
|
|
|
|
print("Starting replay loop...")
|
|
log_say(f"Replaying episode {EPISODE_IDX}")
|
|
for idx in range(dataset.num_frames):
|
|
t0 = time.perf_counter()
|
|
|
|
# Get recorded action from dataset
|
|
action = {
|
|
name: float(actions[idx][ACTION][i])
|
|
for i, name in enumerate(dataset.features[ACTION]["names"])
|
|
}
|
|
|
|
# Send action to robot
|
|
_ = robot.send_action(action)
|
|
|
|
precise_sleep(max(1.0 / dataset.fps - (time.perf_counter() - t0), 0.0))
|
|
finally:
|
|
robot.disconnect()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|