From 1f1e1bcfe89938f8f2f3a13065f056f4afc01d99 Mon Sep 17 00:00:00 2001 From: Simon Alibert Date: Sun, 23 Mar 2025 11:08:20 +0100 Subject: [PATCH] Add Motor in dxl robots --- lerobot/common/motors/dynamixel/dynamixel.py | 4 ++-- lerobot/common/motors/feetech/feetech.py | 4 ++-- lerobot/common/robots/koch/robot_koch.py | 14 ++++++------- .../robots/viperx/configuration_viperx.py | 12 ----------- lerobot/common/robots/viperx/robot_viperx.py | 20 +++++++++---------- .../common/teleoperators/koch/teleop_koch.py | 14 ++++++------- .../widowx/configuration_widowx.py | 11 ---------- .../teleoperators/widowx/teleop_widowx.py | 20 +++++++++---------- 8 files changed, 38 insertions(+), 61 deletions(-) diff --git a/lerobot/common/motors/dynamixel/dynamixel.py b/lerobot/common/motors/dynamixel/dynamixel.py index 8c5290b4..e988d3a0 100644 --- a/lerobot/common/motors/dynamixel/dynamixel.py +++ b/lerobot/common/motors/dynamixel/dynamixel.py @@ -20,7 +20,7 @@ from copy import deepcopy -from ..motors_bus import MotorsBus +from ..motors_bus import Motor, MotorsBus from .tables import MODEL_BAUDRATE_TABLE, MODEL_CONTROL_TABLE, MODEL_RESOLUTION PROTOCOL_VERSION = 2.0 @@ -48,7 +48,7 @@ class DynamixelMotorsBus(MotorsBus): def __init__( self, port: str, - motors: dict[str, tuple[int, str]], + motors: dict[str, Motor], ): super().__init__(port, motors) import dynamixel_sdk as dxl diff --git a/lerobot/common/motors/feetech/feetech.py b/lerobot/common/motors/feetech/feetech.py index 78fae13a..3e8eb20a 100644 --- a/lerobot/common/motors/feetech/feetech.py +++ b/lerobot/common/motors/feetech/feetech.py @@ -14,7 +14,7 @@ from copy import deepcopy -from ..motors_bus import MotorsBus +from ..motors_bus import Motor, MotorsBus from .tables import ( CALIBRATION_REQUIRED, MODEL_BAUDRATE_TABLE, @@ -44,7 +44,7 @@ class FeetechMotorsBus(MotorsBus): def __init__( self, port: str, - motors: dict[str, tuple[int, str]], + motors: dict[str, Motor], ): super().__init__(port, motors) import scservo_sdk as scs diff --git a/lerobot/common/robots/koch/robot_koch.py b/lerobot/common/robots/koch/robot_koch.py index ff2bdb65..1f57e6c3 100644 --- a/lerobot/common/robots/koch/robot_koch.py +++ b/lerobot/common/robots/koch/robot_koch.py @@ -23,7 +23,7 @@ import numpy as np from lerobot.common.cameras.utils import make_cameras_from_configs from lerobot.common.constants import OBS_IMAGES, OBS_STATE from lerobot.common.errors import DeviceAlreadyConnectedError, DeviceNotConnectedError -from lerobot.common.motors import TorqueMode +from lerobot.common.motors import CalibrationMode, Motor, TorqueMode from lerobot.common.motors.dynamixel import ( DynamixelMotorsBus, run_arm_calibration, @@ -52,12 +52,12 @@ class KochRobot(Robot): self.arm = DynamixelMotorsBus( port=self.config.port, motors={ - "shoulder_pan": (1, "xl430-w250"), - "shoulder_lift": (2, "xl430-w250"), - "elbow_flex": (3, "xl330-m288"), - "wrist_flex": (4, "xl330-m288"), - "wrist_roll": (5, "xl330-m288"), - "gripper": (6, "xl330-m288"), + "shoulder_pan": Motor(1, "xl430-w250", CalibrationMode.RANGE_M100_100), + "shoulder_lift": Motor(2, "xl430-w250", CalibrationMode.RANGE_M100_100), + "elbow_flex": Motor(3, "xl330-m288", CalibrationMode.RANGE_M100_100), + "wrist_flex": Motor(4, "xl330-m288", CalibrationMode.RANGE_M100_100), + "wrist_roll": Motor(5, "xl330-m288", CalibrationMode.RANGE_M100_100), + "gripper": Motor(6, "xl330-m288", CalibrationMode.RANGE_0_100), }, ) self.cameras = make_cameras_from_configs(config.cameras) diff --git a/lerobot/common/robots/viperx/configuration_viperx.py b/lerobot/common/robots/viperx/configuration_viperx.py index 44256889..186f0ad6 100644 --- a/lerobot/common/robots/viperx/configuration_viperx.py +++ b/lerobot/common/robots/viperx/configuration_viperx.py @@ -20,20 +20,8 @@ class ViperXRobotConfig(RobotConfig): # then to gradually add more motors (by uncommenting), until you can teleoperate both arms fully max_relative_target: int | None = 5 - waist: tuple = (1, "xm540-w270") - shoulder: tuple = (2, "xm540-w270") - shoulder_shadow: tuple = (3, "xm540-w270") - elbow: tuple = (4, "xm540-w270") - elbow_shadow: tuple = (5, "xm540-w270") - forearm_roll: tuple = (6, "xm540-w270") - wrist_angle: tuple = (7, "xm540-w270") - wrist_rotate: tuple = (8, "xm430-w350") - gripper: tuple = (9, "xm430-w350") - # cameras cameras: dict[str, CameraConfig] = field(default_factory=dict) # Troubleshooting: If one of your IntelRealSense cameras freeze during # data recording due to bandwidth limit, you might need to plug the camera # on another USB hub or PCIe card. - - mock: bool = False diff --git a/lerobot/common/robots/viperx/robot_viperx.py b/lerobot/common/robots/viperx/robot_viperx.py index 7dbc8d34..e4b20094 100644 --- a/lerobot/common/robots/viperx/robot_viperx.py +++ b/lerobot/common/robots/viperx/robot_viperx.py @@ -13,7 +13,7 @@ import numpy as np from lerobot.common.cameras.utils import make_cameras_from_configs from lerobot.common.constants import OBS_IMAGES, OBS_STATE from lerobot.common.errors import DeviceAlreadyConnectedError, DeviceNotConnectedError -from lerobot.common.motors import TorqueMode +from lerobot.common.motors import CalibrationMode, Motor, TorqueMode from lerobot.common.motors.dynamixel import ( DynamixelMotorsBus, run_arm_calibration, @@ -43,15 +43,15 @@ class ViperXRobot(Robot): self.arm = DynamixelMotorsBus( port=self.config.port, motors={ - "waist": config.waist, - "shoulder": config.shoulder, - "shoulder_shadow": config.shoulder_shadow, - "elbow": config.elbow, - "elbow_shadow": config.elbow_shadow, - "forearm_roll": config.forearm_roll, - "wrist_angle": config.wrist_angle, - "wrist_rotate": config.wrist_rotate, - "gripper": config.gripper, + "waist": Motor(1, "xm540-w270", CalibrationMode.RANGE_M100_100), + "shoulder": Motor(2, "xm540-w270", CalibrationMode.RANGE_M100_100), + "shoulder_shadow": Motor(3, "xm540-w270", CalibrationMode.RANGE_M100_100), + "elbow": Motor(4, "xm540-w270", CalibrationMode.RANGE_M100_100), + "elbow_shadow": Motor(5, "xm540-w270", CalibrationMode.RANGE_M100_100), + "forearm_roll": Motor(6, "xm540-w270", CalibrationMode.RANGE_M100_100), + "wrist_angle": Motor(7, "xm540-w270", CalibrationMode.RANGE_M100_100), + "wrist_rotate": Motor(8, "xm430-w350", CalibrationMode.RANGE_M100_100), + "gripper": Motor(9, "xm430-w350", CalibrationMode.RANGE_0_100), }, ) self.cameras = make_cameras_from_configs(config.cameras) diff --git a/lerobot/common/teleoperators/koch/teleop_koch.py b/lerobot/common/teleoperators/koch/teleop_koch.py index b394019a..dfd7f67d 100644 --- a/lerobot/common/teleoperators/koch/teleop_koch.py +++ b/lerobot/common/teleoperators/koch/teleop_koch.py @@ -21,7 +21,7 @@ import time import numpy as np from lerobot.common.errors import DeviceAlreadyConnectedError, DeviceNotConnectedError -from lerobot.common.motors import TorqueMode +from lerobot.common.motors import CalibrationMode, Motor, TorqueMode from lerobot.common.motors.dynamixel import ( DynamixelMotorsBus, run_arm_calibration, @@ -49,12 +49,12 @@ class KochTeleop(Teleoperator): self.arm = DynamixelMotorsBus( port=self.config.port, motors={ - "shoulder_pan": (1, "xl330-m077"), - "shoulder_lift": (2, "xl330-m077"), - "elbow_flex": (3, "xl330-m077"), - "wrist_flex": (4, "xl330-m077"), - "wrist_roll": (5, "xl330-m077"), - "gripper": (6, "xl330-m077"), + "shoulder_pan": Motor(1, "xl330-m077", CalibrationMode.RANGE_M100_100), + "shoulder_lift": Motor(2, "xl330-m077", CalibrationMode.RANGE_M100_100), + "elbow_flex": Motor(3, "xl330-m077", CalibrationMode.RANGE_M100_100), + "wrist_flex": Motor(4, "xl330-m077", CalibrationMode.RANGE_M100_100), + "wrist_roll": Motor(5, "xl330-m077", CalibrationMode.RANGE_M100_100), + "gripper": Motor(6, "xl330-m077", CalibrationMode.RANGE_0_100), }, ) diff --git a/lerobot/common/teleoperators/widowx/configuration_widowx.py b/lerobot/common/teleoperators/widowx/configuration_widowx.py index 133237e2..896405e9 100644 --- a/lerobot/common/teleoperators/widowx/configuration_widowx.py +++ b/lerobot/common/teleoperators/widowx/configuration_widowx.py @@ -36,14 +36,3 @@ class WidowXTeleopConfig(TeleoperatorConfig): # first try to teleoperate the grippers only (by commenting out the rest of the motors in this yaml), # then to gradually add more motors (by uncommenting), until you can teleoperate both arms fully max_relative_target: int | None = 5 - - # motors - waist: tuple = (1, "xm430-w350") - shoulder: tuple = (2, "xm430-w350") - shoulder_shadow: tuple = (3, "xm430-w350") - elbow: tuple = (4, "xm430-w350") - elbow_shadow: tuple = (5, "xm430-w350") - forearm_roll: tuple = (6, "xm430-w350") - wrist_angle: tuple = (7, "xm430-w350") - wrist_rotate: tuple = (8, "xl430-w250") - gripper: tuple = (9, "xc430-w150") diff --git a/lerobot/common/teleoperators/widowx/teleop_widowx.py b/lerobot/common/teleoperators/widowx/teleop_widowx.py index a661b003..702f8d44 100644 --- a/lerobot/common/teleoperators/widowx/teleop_widowx.py +++ b/lerobot/common/teleoperators/widowx/teleop_widowx.py @@ -21,7 +21,7 @@ import time import numpy as np from lerobot.common.errors import DeviceAlreadyConnectedError, DeviceNotConnectedError -from lerobot.common.motors import TorqueMode +from lerobot.common.motors import CalibrationMode, Motor, TorqueMode from lerobot.common.motors.dynamixel import ( DynamixelMotorsBus, run_arm_calibration, @@ -47,15 +47,15 @@ class WidowXTeleop(Teleoperator): self.arm = DynamixelMotorsBus( port=self.config.port, motors={ - "waist": config.waist, - "shoulder": config.shoulder, - "shoulder_shadow": config.shoulder_shadow, - "elbow": config.elbow, - "elbow_shadow": config.elbow_shadow, - "forearm_roll": config.forearm_roll, - "wrist_angle": config.wrist_angle, - "wrist_rotate": config.wrist_rotate, - "gripper": config.gripper, + "waist": Motor(1, "xm430-w350", CalibrationMode.RANGE_M100_100), + "shoulder": Motor(2, "xm430-w350", CalibrationMode.RANGE_M100_100), + "shoulder_shadow": Motor(3, "xm430-w350", CalibrationMode.RANGE_M100_100), + "elbow": Motor(4, "xm430-w350", CalibrationMode.RANGE_M100_100), + "elbow_shadow": Motor(5, "xm430-w350", CalibrationMode.RANGE_M100_100), + "forearm_roll": Motor(6, "xm430-w350", CalibrationMode.RANGE_M100_100), + "wrist_angle": Motor(7, "xm430-w350", CalibrationMode.RANGE_M100_100), + "wrist_rotate": Motor(8, "xl430-w250", CalibrationMode.RANGE_M100_100), + "gripper": Motor(9, "xc430-w150", CalibrationMode.RANGE_0_100), }, )