Added find_motor_bus_ports.py
This commit is contained in:
@@ -377,8 +377,10 @@ class DynamixelMotorsBus:
|
|||||||
|
|
||||||
self.port_handler.setPacketTimeoutMillis(TIMEOUT_MS)
|
self.port_handler.setPacketTimeoutMillis(TIMEOUT_MS)
|
||||||
|
|
||||||
# Set expected baudrate for the bus
|
if not self.are_motors_configured():
|
||||||
self.set_bus_baudrate(BAUDRATE)
|
raise OSError(
|
||||||
|
"Motors are not configured. Please use configure_motors.py to configure motors before continuing."
|
||||||
|
)
|
||||||
|
|
||||||
def reconnect(self):
|
def reconnect(self):
|
||||||
self.port_handler = PortHandler(self.port)
|
self.port_handler = PortHandler(self.port)
|
||||||
|
|||||||
@@ -350,8 +350,10 @@ class FeetechMotorsBus:
|
|||||||
|
|
||||||
self.port_handler.setPacketTimeoutMillis(TIMEOUT_MS)
|
self.port_handler.setPacketTimeoutMillis(TIMEOUT_MS)
|
||||||
|
|
||||||
# Set expected baudrate for the bus
|
if not self.are_motors_configured():
|
||||||
self.set_bus_baudrate(BAUDRATE)
|
raise OSError(
|
||||||
|
"Motors are not configured. Please use configure_motors.py to configure motors before continuing."
|
||||||
|
)
|
||||||
|
|
||||||
def reconnect(self):
|
def reconnect(self):
|
||||||
self.port_handler = PortHandler(self.port)
|
self.port_handler = PortHandler(self.port)
|
||||||
|
|||||||
36
lerobot/scripts/find_motors_bus_port.py
Normal file
36
lerobot/scripts/find_motors_bus_port.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def find_available_ports():
|
||||||
|
ports = []
|
||||||
|
for path in Path("/dev").glob("tty*"):
|
||||||
|
ports.append(str(path))
|
||||||
|
return ports
|
||||||
|
|
||||||
|
|
||||||
|
def find_port():
|
||||||
|
print("Finding all available ports for the DynamixelMotorsBus.")
|
||||||
|
ports_before = find_available_ports()
|
||||||
|
print(ports_before)
|
||||||
|
|
||||||
|
print("Remove the usb cable from your DynamixelMotorsBus and press Enter when done.")
|
||||||
|
input()
|
||||||
|
|
||||||
|
time.sleep(0.5)
|
||||||
|
ports_after = find_available_ports()
|
||||||
|
ports_diff = list(set(ports_before) - set(ports_after))
|
||||||
|
|
||||||
|
if len(ports_diff) == 1:
|
||||||
|
port = ports_diff[0]
|
||||||
|
print(f"The port of this DynamixelMotorsBus is '{port}'")
|
||||||
|
print("Reconnect the usb cable.")
|
||||||
|
elif len(ports_diff) == 0:
|
||||||
|
raise OSError(f"Could not detect the port. No difference was found ({ports_diff}).")
|
||||||
|
else:
|
||||||
|
raise OSError(f"Could not detect the port. More than one port was found ({ports_diff}).")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Helper to find the usb port associated to all your DynamixelMotorsBus.
|
||||||
|
find_port()
|
||||||
Reference in New Issue
Block a user