LeRobot 文件
機器人與遙控操作器的處理器
並獲得增強的文件體驗
開始使用
機器人與遠端操作器的處理器
本指南介紹如何建立與修改處理管線,以連接遠端操作器(例如手機)與機器人和資料集。管線將不同動作/觀察空間之間的轉換標準化,讓您無需重寫膠水代碼(glue code)即可更換遠端操作器與機器人。
為了具體說明,我們使用「手機對 SO-100 跟隨者」作為範例,但相同的模式也適用於其他機器人。
您將學到:
- 絕對與相對終端執行器 (EE) 控制:各代表什麼意義、權衡取捨,以及如何針對您的任務進行選擇。
- 三管線模式:如何對映「遠端操作動作 → 資料集動作 → 機器人指令」以及「機器人觀察 → 資料集觀察」。
- 轉接器 (
to_transition/to_output):說明這些如何將原始字典 (raw dicts) 轉換為EnvTransition並反向轉換,以減少重複性代碼。 - 資料集特徵合約:步驟如何透過
transform_features(...)宣告特徵,以及如何進行聚合/合併以供記錄。 - 選擇表示法:何時儲存關節、絕對 EE 位姿或相對 EE 增量——以及這如何影響訓練。
- 管線客製化指導:如何安全地更換機器人/URDF,並調整邊界、步長以及 IK 初始化等選項。
絕對與相對 EE 控制
本指南中的範例使用絕對終端執行器 (EE) 位姿,因為它們易於理解。但在實作中,相對 EE 增量或關節位置通常更適合用作學習特徵。
透過處理器,您可以選擇希望用於策略的學習特徵。這可以是關節位置/速度、絕對 EE 或相對 EE 位置。您也可以選擇儲存其他特徵,例如關節扭矩、馬達電流等。
三條管線
我們通常組合三條管線。根據您的設置,如果動作和觀察空間已經相符,某些管線可以為空。這些管線中的每一條都處理不同動作和觀察空間之間的轉換。以下是每條管線的簡單說明。
- 管線 1:遠端操作動作空間 → 資料集動作空間(手機位姿 → EE 目標)
- 管線 2:資料集動作空間 → 機器人指令空間(EE 目標 → 關節)
- 管線 3:機器人觀察空間 → 資料集觀察空間(關節 → EE 位姿)
以下是我們在「手機對 SO-100 跟隨者」範例中所使用的三條管線範例:
phone_to_robot_ee_pose_processor = RobotProcessorPipeline[RobotAction, RobotAction]( # teleop -> dataset action
steps=[
MapPhoneActionToRobotAction(platform=teleop_config.phone_os),
EEReferenceAndDelta(
kinematics=kinematics_solver, end_effector_step_sizes={"x": 0.5, "y": 0.5, "z": 0.5}, motor_names=list(robot.bus.motors.keys()),
),
EEBoundsAndSafety(
end_effector_bounds={"min": [-1.0, -1.0, -1.0], "max": [1.0, 1.0, 1.0]}, max_ee_step_m=0.20,
),
GripperVelocityToJoint(),
],
to_transition=robot_action_to_transition,
to_output=transition_to_robot_action,
)
robot_ee_to_joints_processor = RobotProcessorPipeline[RobotAction, RobotAction]( # dataset action -> robot
steps=[
InverseKinematicsEEToJoints(
kinematics=kinematics_solver, motor_names=list(robot.bus.motors.keys()), initial_guess_current_joints=True,
),
],
to_transition=robot_action_to_transition,
to_output=transition_to_robot_action,
)
robot_joints_to_ee_pose = RobotProcessorPipeline[RobotObservation, RobotObservation]( # robot obs -> dataset obs
steps=[
ForwardKinematicsJointsToEE(kinematics=kinematics_solver, motor_names=list(robot.bus.motors.keys()))
],
to_transition=observation_to_transition,
to_output=transition_to_observation,
)為何使用 to_transition / to_output
為了實現從機器人/遠端操作器到管線的轉換,以及反向轉換,我們使用 to_transition 和 to_output 管線轉接器。它們將轉換過程標準化以減少重複代碼,並在機器人與遠端操作器的原始字典以及管線的 EnvTransition 格式之間搭建橋樑。在「手機對 SO-100 跟隨者」範例中,我們使用以下轉接器:
robot_action_to_transition:將遠端操作動作字典轉換為管線轉換格式。transition_to_robot_action:將管線轉換格式轉換為機器人動作字典。observation_to_transition:將機器人觀察字典轉換為管線轉換格式。transition_to_observation:將管線轉換格式轉換為觀察字典。
詳情請參閱 src/lerobot/processor/converters.py。
資料集特徵合約
資料集特徵取決於儲存在資料集中的鍵值。每個步驟可以透過稱為 transform_features(...) 的合約宣告它所修改的特徵。一旦建立了處理器,該處理器就可以使用 aggregate_pipeline_dataset_features() 聚合所有這些特徵,並使用 combine_feature_dicts(...) 合併多個特徵字典。
以下是我們在「手機對 SO-100 跟隨者」範例中,如何使用 transform_features 方法宣告特徵的範例:
def transform_features(
self, features: dict[PipelineFeatureType, dict[str, PolicyFeature]]
) -> dict[PipelineFeatureType, dict[str, PolicyFeature]]:
# We only use the ee pose in the dataset, so we don't need the joint positions
for n in self.motor_names:
features[PipelineFeatureType.ACTION].pop(f"{n}.pos", None)
# We specify the dataset features of this step that we want to be stored in the dataset
for k in ["x", "y", "z", "wx", "wy", "wz", "gripper_pos"]:
features[PipelineFeatureType.ACTION][f"ee.{k}"] = PolicyFeature(
type=FeatureType.STATE, shape=(1,)
)
return features這裡我們宣告在此步驟中修改了哪些 PolicyFeatures,以便我們在運行處理器時知道可以期待哪些特徵。這些特徵隨後可以被聚合並用於建立資料集特徵。
以下是我們在「手機對 SO-100 記錄」範例中,如何聚合與合併特徵的範例:
features=combine_feature_dicts(
# Run the feature contract of the pipelines
# This tells you how the features would look like after the pipeline steps
aggregate_pipeline_dataset_features(
pipeline=phone_to_robot_ee_pose_processor,
initial_features=create_initial_features(action=phone.action_features), # <- Action features we can expect, these come from our teleop device (phone) and action processor
use_videos=True,
),
aggregate_pipeline_dataset_features(
pipeline=robot_joints_to_ee_pose,
initial_features=create_initial_features(observation=robot.observation_features), # <- Observation features we can expect, these come from our robot and observation processor
use_videos=True,
patterns=["observation.state.ee"], # <- Here you could optionally filter the features we want to store in the dataset, with a specific pattern
),
),運作方式
aggregate_pipeline_dataset_features(...):將transform_features應用於整個管線,並按模式進行篩選(當use_videos=True時包含影像,並在指定patterns時包含狀態特徵)。combine_feature_dicts(...):合併多個特徵字典。- 使用
record_loop(...)進行記錄時,會使用build_dataset_frame(...)來建立與dataset.features一致的影格,然後呼叫add_frame(...)將影格新增至資料集。
客製化機器人管線的指導方針
您可以儲存下列任一特徵作為您的動作/觀察空間:
- 關節位置
- 絕對 EE 位姿
- 相對 EE 增量
- 其他特徵:關節速度、扭矩等。
選擇您想用於策略動作和觀察空間的內容,並相應地配置/修改管線和步驟。
不同的機器人
- 您可以輕鬆重複使用管線。例如,要使用其他機器人進行手機遠端操作,請修改範例並更換
RobotKinematics(URDF) 和motor_names,即可在手機遠端操作下使用您自己的機器人。此外,請確保target_frame_name指向您的夾爪/手腕。
安全第一
- 更改管線時,請從嚴格的邊界開始,並在操作真實機器人時實施安全措施。
- 建議先從模擬開始,然後再轉向真實機器人。
就這樣!我們希望本指南能協助您開始客製化機器人管線。如果您在任何階段遇到問題,歡迎加入我們的 Discord 社群尋求協助。
在 GitHub 上更新