This commit is contained in:
Remi Cadene
2024-10-20 02:56:20 +02:00
parent bee2b3c1b1
commit 1d92acf1e3
5 changed files with 20 additions and 9 deletions

View File

@@ -352,14 +352,14 @@ class FeetechMotorsBus:
print(e) print(e)
return False return False
def find_motor_indices(self, possible_ids=None): def find_motor_indices(self, possible_ids=None, num_retry=2):
if possible_ids is None: if possible_ids is None:
possible_ids = range(MAX_ID_RANGE) possible_ids = range(MAX_ID_RANGE)
indices = [] indices = []
for idx in tqdm.tqdm(possible_ids): for idx in tqdm.tqdm(possible_ids):
try: try:
present_idx = self.read_with_motor_ids(self.motor_models, [idx], "ID")[0] present_idx = self.read_with_motor_ids(self.motor_models, [idx], "ID", num_retry=num_retry)[0]
except ConnectionError: except ConnectionError:
continue continue

View File

@@ -335,7 +335,7 @@ class ManipulatorRobot:
calibration = run_arm_calibration(arm, self.robot_type, name, arm_type) calibration = run_arm_calibration(arm, self.robot_type, name, arm_type)
elif self.robot_type in ["so100", "moss"]: elif self.robot_type in ["so100"]:
from lerobot.common.robot_devices.robots.feetech_calibration import ( from lerobot.common.robot_devices.robots.feetech_calibration import (
run_arm_auto_calibration, run_arm_auto_calibration,
run_arm_manual_calibration, run_arm_manual_calibration,
@@ -343,12 +343,21 @@ class ManipulatorRobot:
if arm_type == "leader": if arm_type == "leader":
calibration = run_arm_manual_calibration(arm, self.robot_type, name, arm_type) calibration = run_arm_manual_calibration(arm, self.robot_type, name, arm_type)
elif arm_type == "follower": elif arm_type == "follower":
calibration = run_arm_auto_calibration(arm, self.robot_type, name, arm_type) calibration = run_arm_auto_calibration(arm, self.robot_type, name, arm_type)
else: else:
raise ValueError(arm_type) raise ValueError(arm_type)
elif self.robot_type in ["moss"]:
from lerobot.common.robot_devices.robots.feetech_calibration import (
run_arm_manual_calibration,
)
if arm_type == "leader" or arm_type == "follower":
calibration = run_arm_manual_calibration(arm, self.robot_type, name, arm_type)
else:
raise ValueError(arm_type)
print(f"Calibration is done! Saving calibration file '{arm_calib_path}'") print(f"Calibration is done! Saving calibration file '{arm_calib_path}'")
arm_calib_path.parent.mkdir(parents=True, exist_ok=True) arm_calib_path.parent.mkdir(parents=True, exist_ok=True)
with open(arm_calib_path, "w") as f: with open(arm_calib_path, "w") as f:

View File

@@ -18,7 +18,7 @@ max_relative_target: null
leader_arms: leader_arms:
main: main:
_target_: lerobot.common.robot_devices.motors.feetech.FeetechMotorsBus _target_: lerobot.common.robot_devices.motors.feetech.FeetechMotorsBus
port: /dev/tty.usbmodem585A0077581 port: /dev/tty.usbmodem58760431091
motors: motors:
# name: (index, model) # name: (index, model)
shoulder_pan: [1, "sts3215"] shoulder_pan: [1, "sts3215"]
@@ -31,7 +31,7 @@ leader_arms:
follower_arms: follower_arms:
main: main:
_target_: lerobot.common.robot_devices.motors.feetech.FeetechMotorsBus _target_: lerobot.common.robot_devices.motors.feetech.FeetechMotorsBus
port: /dev/tty.usbmodem585A0080971 port: /dev/tty.usbmodem58760431191
motors: motors:
# name: (index, model) # name: (index, model)
shoulder_pan: [1, "sts3215"] shoulder_pan: [1, "sts3215"]

View File

@@ -91,9 +91,7 @@ def configure_motor(port, brand, model, motor_idx_des, baudrate_des):
baudrate_idx = list(SERIES_BAUDRATE_TABLE.values()).index(baudrate_des) baudrate_idx = list(SERIES_BAUDRATE_TABLE.values()).index(baudrate_des)
# The write can fail, so we allow retries # The write can fail, so we allow retries
motor_bus.write_with_motor_ids( motor_bus.write_with_motor_ids(motor_bus.motor_models, motor_index, "Baud_Rate", baudrate_idx)
motor_bus.motor_models, motor_index, "Baud_Rate", baudrate_idx, num_retry=2
)
time.sleep(0.5) time.sleep(0.5)
motor_bus.set_bus_baudrate(baudrate_des) motor_bus.set_bus_baudrate(baudrate_des)
present_baudrate_idx = motor_bus.read_with_motor_ids( present_baudrate_idx = motor_bus.read_with_motor_ids(
@@ -104,6 +102,7 @@ def configure_motor(port, brand, model, motor_idx_des, baudrate_des):
raise OSError("Failed to write baudrate.") raise OSError("Failed to write baudrate.")
print(f"Setting its index to desired index {motor_idx_des}") print(f"Setting its index to desired index {motor_idx_des}")
motor_bus.write_with_motor_ids(motor_bus.motor_models, motor_index, "Lock", 0)
motor_bus.write_with_motor_ids(motor_bus.motor_models, motor_index, "ID", motor_idx_des) motor_bus.write_with_motor_ids(motor_bus.motor_models, motor_index, "ID", motor_idx_des)
present_idx = motor_bus.read_with_motor_ids(motor_bus.motor_models, motor_idx_des, "ID", num_retry=2) present_idx = motor_bus.read_with_motor_ids(motor_bus.motor_models, motor_idx_des, "ID", num_retry=2)

View File

@@ -144,6 +144,9 @@ def calibrate(robot: Robot, arms: list[str] | None):
robot.home() robot.home()
return return
if arms is None:
arms = robot.available_arms
unknown_arms = [arm_id for arm_id in arms if arm_id not in robot.available_arms] unknown_arms = [arm_id for arm_id in arms if arm_id not in robot.available_arms]
available_arms_str = " ".join(robot.available_arms) available_arms_str = " ".join(robot.available_arms)
unknown_arms_str = " ".join(unknown_arms) unknown_arms_str = " ".join(unknown_arms)