lerobot/lerobot/common/robots/lekiwi/daemon_lekiwi_app.py

60 lines
1.9 KiB
Python
Raw Normal View History

2025-03-14 21:38:06 +08:00
import logging
import time
import numpy as np
2025-03-14 22:01:07 +08:00
from lerobot.common.robots.lekiwi.configuration_daemon_lekiwi import DaemonLeKiwiRobotConfig
from lerobot.common.robots.lekiwi.daemon_lekiwi import DaemonLeKiwiRobot, RobotMode
from lerobot.common.teleoperators.keyboard import KeyboardTeleop, KeyboardTeleopConfig
from lerobot.common.teleoperators.so100 import SO100Teleop, SO100TeleopConfig
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-03-18 00:38:08 +08:00
leader_arm_config = SO100TeleopConfig(port="/dev/tty.usbmodem58760429271")
2025-03-13 19:54:27 +08:00
leader_arm = SO100Teleop(leader_arm_config)
keyboard_config = KeyboardTeleopConfig()
keyboard = KeyboardTeleop(keyboard_config)
logging.info("Connecting Teleop Devices")
leader_arm.connect()
keyboard.connect()
logging.info("Configuring LeKiwiRobot Daemon")
robot_config = DaemonLeKiwiRobotConfig()
robot = DaemonLeKiwiRobot(robot_config)
2025-03-14 21:38:06 +08:00
2025-03-13 19:54:27 +08:00
logging.info("Connecting remote LeKiwiRobot")
2025-03-18 00:38:08 +08:00
robot.connect()
2025-03-14 21:30:55 +08:00
robot.robot_mode = RobotMode.TELEOP
2025-03-13 19:54:27 +08:00
logging.info("Starting LeKiwiRobot teleoperation")
start = time.perf_counter()
duration = 0
2025-03-18 01:49:05 +08:00
while duration < 100:
2025-03-14 21:30:55 +08:00
arm_action = leader_arm.get_action()
base_action = keyboard.get_action()
2025-03-18 00:38:08 +08:00
action = np.append(arm_action, base_action) if base_action.size > 0 else arm_action
_action_sent = robot.send_action(action)
_observation = robot.get_observation()
2025-03-14 06:59:39 +08:00
2025-03-14 21:30:55 +08:00
# dataset.save(action_sent, obs)
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)
2025-03-13 19:54:27 +08:00
duration = time.perf_counter() - start
logging.info("Disconnecting Teleop Devices and LeKiwiRobot Daemon")
2025-03-18 00:38:08 +08:00
robot.disconnect()
2025-03-13 19:54:27 +08:00
leader_arm.disconnect()
keyboard.disconnect()
logging.info("Finished LeKiwiRobot cleanly")
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()