Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Windows #494

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions lerobot/scripts/find_motors_bus_port.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
import os
import time
from pathlib import Path

from serial.tools import list_ports # Part of pyserial library


def find_available_ports():
ports = []
for path in Path("/dev").glob("tty*"):
ports.append(str(path))
if os.name == "nt": # Windows
# List COM ports using pyserial
ports = [port.device for port in list_ports.comports()]
else: # Linux/macOS
# List /dev/tty* ports for Unix-based systems
ports = [str(path) for path in Path("/dev").glob("tty*")]
return ports


def find_port():
print("Finding all available ports for the MotorsBus.")
ports_before = find_available_ports()
print(ports_before)
print("Ports before disconnecting:", ports_before)

print("Remove the usb cable from your MotorsBus and press Enter when done.")
input()
print("Remove the USB cable from your MotorsBus and press Enter when done.")
input() # Wait for user to disconnect the device

time.sleep(0.5)
time.sleep(0.5) # Allow some time for port to be released
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 MotorsBus is '{port}'")
print("Reconnect the usb cable.")
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 MotorsBus.
# Helper to find the USB port associated with your MotorsBus.
find_port()
Loading