16
16
import time
17
17
18
18
19
- def configure_motor ( port , brand , model , motor_idx_des , baudrate_des ) :
19
+ def get_motor_bus_cls ( brand : str ) -> tuple :
20
20
if brand == "feetech" :
21
- from lerobot .common .robot_devices .motors .feetech import MODEL_BAUDRATE_TABLE
21
+ from lerobot .common .robot_devices .motors .configs import FeetechMotorsBusConfig
22
22
from lerobot .common .robot_devices .motors .feetech import (
23
- SCS_SERIES_BAUDRATE_TABLE as SERIES_BAUDRATE_TABLE ,
23
+ MODEL_BAUDRATE_TABLE ,
24
+ SCS_SERIES_BAUDRATE_TABLE ,
25
+ FeetechMotorsBus ,
24
26
)
25
- from lerobot .common .robot_devices .motors .feetech import FeetechMotorsBus as MotorsBusClass
27
+
28
+ return FeetechMotorsBusConfig , FeetechMotorsBus , MODEL_BAUDRATE_TABLE , SCS_SERIES_BAUDRATE_TABLE
29
+
26
30
elif brand == "dynamixel" :
27
- from lerobot .common .robot_devices .motors .dynamixel import MODEL_BAUDRATE_TABLE
31
+ from lerobot .common .robot_devices .motors .configs import DynamixelMotorsBusConfig
28
32
from lerobot .common .robot_devices .motors .dynamixel import (
29
- X_SERIES_BAUDRATE_TABLE as SERIES_BAUDRATE_TABLE ,
33
+ MODEL_BAUDRATE_TABLE ,
34
+ X_SERIES_BAUDRATE_TABLE ,
35
+ DynamixelMotorsBus ,
30
36
)
31
- from lerobot .common .robot_devices .motors .dynamixel import DynamixelMotorsBus as MotorsBusClass
37
+
38
+ return DynamixelMotorsBusConfig , DynamixelMotorsBus , MODEL_BAUDRATE_TABLE , X_SERIES_BAUDRATE_TABLE
39
+
32
40
else :
33
41
raise ValueError (
34
42
f"Currently we do not support this motor brand: { brand } . We currently support feetech and dynamixel motors."
35
43
)
36
44
45
+
46
+ def configure_motor (port , brand , model , motor_idx_des , baudrate_des ):
47
+ motor_bus_config_cls , motor_bus_cls , model_baudrate_table , series_baudrate_table = get_motor_bus_cls (
48
+ brand
49
+ )
50
+
37
51
# Check if the provided model exists in the model_baud_rate_table
38
- if model not in MODEL_BAUDRATE_TABLE :
52
+ if model not in model_baudrate_table :
39
53
raise ValueError (
40
- f"Invalid model '{ model } ' for brand '{ brand } '. Supported models: { list (MODEL_BAUDRATE_TABLE .keys ())} "
54
+ f"Invalid model '{ model } ' for brand '{ brand } '. Supported models: { list (model_baudrate_table .keys ())} "
41
55
)
42
56
43
57
# Setup motor names, indices, and models
44
58
motor_name = "motor"
45
59
motor_index_arbitrary = motor_idx_des # Use the motor ID passed via argument
46
60
motor_model = model # Use the motor model passed via argument
47
61
62
+ config = motor_bus_config_cls (port = port , motors = {motor_name : (motor_index_arbitrary , motor_model )})
63
+
48
64
# Initialize the MotorBus with the correct port and motor configurations
49
- motor_bus = MotorsBusClass ( port = port , motors = { motor_name : ( motor_index_arbitrary , motor_model )} )
65
+ motor_bus = motor_bus_cls ( config = config )
50
66
51
67
# Try to connect to the motor bus and handle any connection-specific errors
52
68
try :
@@ -59,7 +75,7 @@ def configure_motor(port, brand, model, motor_idx_des, baudrate_des):
59
75
# Motor bus is connected, proceed with the rest of the operations
60
76
try :
61
77
print ("Scanning all baudrates and motor indices" )
62
- all_baudrates = set (SERIES_BAUDRATE_TABLE .values ())
78
+ all_baudrates = set (series_baudrate_table .values ())
63
79
motor_index = - 1 # Set the motor index to an out-of-range value.
64
80
65
81
for baudrate in all_baudrates :
@@ -89,7 +105,7 @@ def configure_motor(port, brand, model, motor_idx_des, baudrate_des):
89
105
90
106
if baudrate != baudrate_des :
91
107
print (f"Setting its baudrate to { baudrate_des } " )
92
- baudrate_idx = list (SERIES_BAUDRATE_TABLE .values ()).index (baudrate_des )
108
+ baudrate_idx = list (series_baudrate_table .values ()).index (baudrate_des )
93
109
94
110
# The write can fail, so we allow retries
95
111
motor_bus .write_with_motor_ids (motor_bus .motor_models , motor_index , "Baud_Rate" , baudrate_idx )
0 commit comments