Merge remote-tracking branch 'origin/main' into user/aliberts/2024_09_25_reshape_dataset
This commit is contained in:
commit
3b5af7eb38
|
@ -328,9 +328,17 @@ def sanity_check_dataset_name(repo_id, policy):
|
||||||
_, dataset_name = repo_id.split("/")
|
_, dataset_name = repo_id.split("/")
|
||||||
# either repo_id doesnt start with "eval_" and there is no policy
|
# either repo_id doesnt start with "eval_" and there is no policy
|
||||||
# or repo_id starts with "eval_" and there is a policy
|
# or repo_id starts with "eval_" and there is a policy
|
||||||
if dataset_name.startswith("eval_") == (policy is None):
|
|
||||||
|
# Check if dataset_name starts with "eval_" but policy is missing
|
||||||
|
if dataset_name.startswith("eval_") and policy is None:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Your dataset name begins by 'eval_' ({dataset_name}) but no policy is provided ({policy})."
|
f"Your dataset name begins with 'eval_' ({dataset_name}), but no policy is provided."
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check if dataset_name does not start with "eval_" but policy is provided
|
||||||
|
if not dataset_name.startswith("eval_") and policy is not None:
|
||||||
|
raise ValueError(
|
||||||
|
f"Your dataset name does not begin with 'eval_' ({dataset_name}), but a policy is provided ({policy})."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,36 @@
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from serial.tools import list_ports # Part of pyserial library
|
||||||
|
|
||||||
|
|
||||||
def find_available_ports():
|
def find_available_ports():
|
||||||
ports = []
|
if os.name == "nt": # Windows
|
||||||
for path in Path("/dev").glob("tty*"):
|
# List COM ports using pyserial
|
||||||
ports.append(str(path))
|
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
|
return ports
|
||||||
|
|
||||||
|
|
||||||
def find_port():
|
def find_port():
|
||||||
print("Finding all available ports for the MotorsBus.")
|
print("Finding all available ports for the MotorsBus.")
|
||||||
ports_before = find_available_ports()
|
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.")
|
print("Remove the USB cable from your MotorsBus and press Enter when done.")
|
||||||
input()
|
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_after = find_available_ports()
|
||||||
ports_diff = list(set(ports_before) - set(ports_after))
|
ports_diff = list(set(ports_before) - set(ports_after))
|
||||||
|
|
||||||
if len(ports_diff) == 1:
|
if len(ports_diff) == 1:
|
||||||
port = ports_diff[0]
|
port = ports_diff[0]
|
||||||
print(f"The port of this MotorsBus is '{port}'")
|
print(f"The port of this MotorsBus is '{port}'")
|
||||||
print("Reconnect the usb cable.")
|
print("Reconnect the USB cable.")
|
||||||
elif len(ports_diff) == 0:
|
elif len(ports_diff) == 0:
|
||||||
raise OSError(f"Could not detect the port. No difference was found ({ports_diff}).")
|
raise OSError(f"Could not detect the port. No difference was found ({ports_diff}).")
|
||||||
else:
|
else:
|
||||||
|
@ -32,5 +38,5 @@ def find_port():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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()
|
find_port()
|
||||||
|
|
Loading…
Reference in New Issue