mirror of
https://github.com/huggingface/lerobot.git
synced 2026-06-04 04:41:24 +00:00
142 lines
4.2 KiB
Python
142 lines
4.2 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.
|
|
|
|
"""Policy deployment engine with pluggable rollout strategies.
|
|
|
|
``lerobot-rollout`` is the single CLI for running trained policies on
|
|
real robots.
|
|
|
|
--strategy.type=base 24/7 autonomous rollout (no recording)
|
|
--strategy.type=sentry Continuous recording with auto-upload
|
|
--strategy.type=highlight Ring buffer + keystroke save
|
|
--strategy.type=dagger Human-in-the-loop (DAgger/RaC)
|
|
|
|
Usage examples::
|
|
|
|
# Base mode (sync inference)
|
|
lerobot-rollout \\
|
|
--strategy.type=base \\
|
|
--policy.path=lerobot/act_koch_real \\
|
|
--robot.type=koch_follower \\
|
|
--task="pick up cube" --duration=30
|
|
|
|
# Base mode (RTC for slow VLAs)
|
|
lerobot-rollout \\
|
|
--strategy.type=base \\
|
|
--policy.path=lerobot/pi0_base \\
|
|
--inference.type=rtc --inference.rtc.execution_horizon=10 \\
|
|
--robot.type=so100_follower \\
|
|
--task="pick up cube" --duration=60
|
|
|
|
# Sentry mode (continuous recording)
|
|
lerobot-rollout \\
|
|
--strategy.type=sentry \\
|
|
--strategy.episode_duration_s=120 \\
|
|
--strategy.upload_every_n_episodes=5 \\
|
|
--policy.path=lerobot/pi0_base \\
|
|
--inference.type=rtc \\
|
|
--robot.type=so100_follower \\
|
|
--dataset.repo_id=user/sentry-data \\
|
|
--dataset.single_task="patrol" --duration=3600
|
|
|
|
# DAgger mode (human-in-the-loop)
|
|
lerobot-rollout \\
|
|
--strategy.type=dagger \\
|
|
--policy.path=outputs/pretrain/checkpoints/last/pretrained_model \\
|
|
--robot.type=bi_openarm_follower \\
|
|
--teleop.type=openarm_mini \\
|
|
--dataset.repo_id=user/hil-data \\
|
|
--dataset.single_task="Fold the T-shirt"
|
|
"""
|
|
|
|
import logging
|
|
|
|
from lerobot.cameras.opencv import OpenCVCameraConfig # noqa: F401
|
|
from lerobot.cameras.realsense import RealSenseCameraConfig # noqa: F401
|
|
from lerobot.cameras.zmq import ZMQCameraConfig # noqa: F401
|
|
from lerobot.configs import parser
|
|
from lerobot.robots import ( # noqa: F401
|
|
Robot,
|
|
RobotConfig,
|
|
bi_openarm_follower,
|
|
bi_so_follower,
|
|
earthrover_mini_plus,
|
|
hope_jr,
|
|
koch_follower,
|
|
omx_follower,
|
|
openarm_follower,
|
|
reachy2,
|
|
so_follower,
|
|
unitree_g1 as unitree_g1_robot,
|
|
)
|
|
from lerobot.rollout.configs import RolloutConfig
|
|
from lerobot.rollout.context import build_rollout_context
|
|
from lerobot.rollout.strategies import create_strategy
|
|
from lerobot.teleoperators import ( # noqa: F401
|
|
Teleoperator,
|
|
TeleoperatorConfig,
|
|
bi_openarm_leader,
|
|
bi_so_leader,
|
|
homunculus,
|
|
koch_leader,
|
|
omx_leader,
|
|
openarm_leader,
|
|
openarm_mini,
|
|
reachy2_teleoperator,
|
|
so_leader,
|
|
unitree_g1,
|
|
)
|
|
from lerobot.utils.import_utils import register_third_party_plugins
|
|
from lerobot.utils.process import ProcessSignalHandler
|
|
from lerobot.utils.utils import init_logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@parser.wrap()
|
|
def rollout(cfg: RolloutConfig):
|
|
"""Main entry point for policy deployment."""
|
|
init_logging()
|
|
|
|
signal_handler = ProcessSignalHandler(use_threads=True, display_pid=False)
|
|
shutdown_event = signal_handler.shutdown_event
|
|
|
|
logger.info("Building rollout context...")
|
|
ctx = build_rollout_context(cfg, shutdown_event)
|
|
|
|
strategy = create_strategy(cfg.strategy)
|
|
logger.info("Strategy: %s", cfg.strategy.type)
|
|
|
|
try:
|
|
strategy.setup(ctx)
|
|
strategy.run(ctx)
|
|
except KeyboardInterrupt:
|
|
logger.info("Interrupted by user")
|
|
finally:
|
|
strategy.teardown(ctx)
|
|
|
|
logger.info("Rollout finished")
|
|
|
|
|
|
def main():
|
|
"""CLI entry point for ``lerobot-rollout``."""
|
|
register_third_party_plugins()
|
|
rollout()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|