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

61 lines
2.0 KiB
Python
Raw Normal View History

2025-03-14 21:38:06 +08:00
import logging
import time
import numpy as np
2025-03-13 19:54:27 +08:00
from ...teleoperators.keyboard import KeyboardTeleop, KeyboardTeleopConfig
2025-03-14 21:38:06 +08:00
from ...teleoperators.so100 import SO100Teleop, SO100TeleopConfig
2025-03-13 19:54:27 +08:00
from .configuration_daemon_lekiwi import DaemonLeKiwiRobotConfig
2025-03-14 21:30:55 +08:00
from .daemon_lekiwi import DaemonLeKiwiRobot, RobotMode
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")
leader_arm_config = SO100TeleopConfig(port="/dev/tty.usbmodem585A0085511")
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-14 21:38:06 +08:00
robot.connect() # Establishes ZMQ sockets with the remote mobile robot
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
while duration < 20:
2025-03-14 21:30:55 +08:00
arm_action = leader_arm.get_action()
base_action = keyboard.get_action()
2025-03-14 21:38:06 +08:00
action = np.concatenate((arm_action, base_action))
_action_sent = robot.send_action(action) # Translates to motor space + sends over ZMQ
_observation = robot.get_observation() # Receives over ZMQ, translate to body-frame vel
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-14 21:38:06 +08:00
robot.disconnect() # Cleans ZMQ comms
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()