lerobot/examples/robots/lekiwi_client_app.py

144 lines
4.2 KiB
Python
Raw Normal View History

2025-03-20 16:48:55 +08:00
# Copyright 2024 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.
2025-03-14 21:38:06 +08:00
import logging
from lerobot.common.datasets.lerobot_dataset import LeRobotDataset
from lerobot.common.robots.config import RobotMode
from lerobot.common.robots.lekiwi.config_lekiwi import LeKiwiClientConfig
from lerobot.common.robots.lekiwi.lekiwi_client import LeKiwiClient
2025-03-14 22:01:07 +08:00
from lerobot.common.teleoperators.keyboard import KeyboardTeleop, KeyboardTeleopConfig
2025-04-04 17:48:41 +08:00
from lerobot.common.teleoperators.so100 import SO100Leader, SO100LeaderConfig
DUMMY_FEATURES = {
"observation.state": {
"dtype": "float64",
"shape": (9,),
"names": {
"motors": [
"arm_shoulder_pan",
"arm_shoulder_lift",
"arm_elbow_flex",
"arm_wrist_flex",
"arm_wrist_roll",
"arm_gripper",
"base_left_wheel",
"base_right_wheel",
"base_back_wheel",
]
},
},
"action": {
"dtype": "float64",
"shape": (9,),
"names": {
"motors": [
"arm_shoulder_pan",
"arm_shoulder_lift",
"arm_elbow_flex",
"arm_wrist_flex",
"arm_wrist_roll",
"arm_gripper",
"base_left_wheel",
"base_right_wheel",
"base_back_wheel",
]
},
},
"observation.images.front": {
"dtype": "image",
"shape": (640, 480, 3),
"names": [
"width",
"height",
"channels",
],
},
"observation.images.wrist": {
"dtype": "image",
"shape": (480, 640, 3),
"names": [
"width",
"height",
"channels",
],
},
}
2025-03-13 19:54:27 +08:00
2025-03-14 21:38:06 +08:00
def main():
2025-03-13 19:54:27 +08:00
logging.info("Configuring Teleop Devices")
2025-04-04 17:48:41 +08:00
leader_arm_config = SO100LeaderConfig(port="/dev/tty.usbmodem58760429271")
leader_arm = SO100Leader(leader_arm_config)
2025-03-13 19:54:27 +08:00
keyboard_config = KeyboardTeleopConfig()
keyboard = KeyboardTeleop(keyboard_config)
2025-04-04 17:44:35 +08:00
logging.info("Configuring LeKiwi Client")
robot_config = LeKiwiClientConfig(
id="daemonlekiwi", calibration_dir=".cache/calibration/lekiwi", robot_mode=RobotMode.TELEOP
)
2025-04-04 17:44:35 +08:00
robot = LeKiwiClient(robot_config)
logging.info("Creating LeRobot Dataset")
# TODO(Steven): Check this creation
dataset = LeRobotDataset.create(
repo_id="user/lekiwi",
fps=10,
features=DUMMY_FEATURES,
)
2025-03-13 19:54:27 +08:00
logging.info("Connecting Teleop Devices")
leader_arm.connect()
keyboard.connect()
2025-04-04 17:44:35 +08:00
logging.info("Connecting remote LeKiwi")
2025-03-18 00:38:08 +08:00
robot.connect()
2025-03-13 19:54:27 +08:00
2025-04-04 17:44:35 +08:00
logging.info("Starting LeKiwi teleoperation")
i = 0
while i < 1000:
2025-03-14 21:30:55 +08:00
arm_action = leader_arm.get_action()
base_action = keyboard.get_action()
action = {**arm_action, **base_action} if base_action.size > 0 else arm_action
2025-03-14 06:59:39 +08:00
2025-03-14 21:30:55 +08:00
# TODO(Steven): Deal with policy action space
# robot.set_mode(RobotMode.AUTO)
# policy_action = policy.get_action() # This might be in body frame, key space or smt else
# robot.send_action(policy_action)
action_sent = robot.send_action(action)
observation = robot.get_observation()
frame = {**action_sent, **observation}
frame.update({"task": "Dummy Task Dataset"})
logging.info("Saved a frame into the dataset")
dataset.add_frame(frame)
i += 1
dataset.save_episode()
# dataset.push_to_hub()
2025-03-13 19:54:27 +08:00
2025-04-04 17:44:35 +08:00
logging.info("Disconnecting Teleop Devices and LeKiwi Client")
2025-03-18 00:38:08 +08:00
robot.disconnect()
2025-03-13 19:54:27 +08:00
leader_arm.disconnect()
keyboard.disconnect()
2025-04-04 17:44:35 +08:00
logging.info("Finished LeKiwi cleanly")
2025-03-13 19:54:27 +08:00
2025-03-14 21:38:06 +08:00
2025-03-13 19:54:27 +08:00
if __name__ == "__main__":
2025-03-14 21:38:06 +08:00
main()