add trying multiple controllers to headless

This commit is contained in:
SHC-ASTRA
2026-01-14 04:56:55 -06:00
parent 14141651bf
commit 0e775c65c6

View File

@@ -74,11 +74,17 @@ class Headless(Node):
print("No gamepad found. Waiting...")
# Initialize the gamepad
self.gamepad = pygame.joystick.Joystick(0)
id = 0
while True:
if id >= pygame.joystick.get_count():
self.get_logger().fatal("Ran out of controllers to try")
sys.exit(1)
self.gamepad = pygame.joystick.Joystick(id)
self.gamepad.init()
print(f"Gamepad Found: {self.gamepad.get_name()}")
if self.gamepad.get_numhats() == 0:
if self.gamepad.get_numhats() == 0 or self.gamepad.get_numaxes() < 5:
self.get_logger().error("Controller not correctly initialized.")
if not is_user_in_group("input"):
self.get_logger().warning(
@@ -88,8 +94,9 @@ class Headless(Node):
self.get_logger().warning(
"If using NixOS, you may need to remove yourself from the 'plugdev' group."
)
time.sleep(1)
sys.exit(1)
else:
break
id += 1
self.create_timer(0.15, self.send_controls)