mirror of
https://github.com/SHC-ASTRA/rover-ros2.git
synced 2026-02-11 09:20:40 +00:00
add trying multiple controllers to headless
This commit is contained in:
@@ -74,11 +74,17 @@ class Headless(Node):
|
|||||||
print("No gamepad found. Waiting...")
|
print("No gamepad found. Waiting...")
|
||||||
|
|
||||||
# Initialize the gamepad
|
# 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()
|
self.gamepad.init()
|
||||||
print(f"Gamepad Found: {self.gamepad.get_name()}")
|
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.")
|
self.get_logger().error("Controller not correctly initialized.")
|
||||||
if not is_user_in_group("input"):
|
if not is_user_in_group("input"):
|
||||||
self.get_logger().warning(
|
self.get_logger().warning(
|
||||||
@@ -88,8 +94,9 @@ class Headless(Node):
|
|||||||
self.get_logger().warning(
|
self.get_logger().warning(
|
||||||
"If using NixOS, you may need to remove yourself from the 'plugdev' group."
|
"If using NixOS, you may need to remove yourself from the 'plugdev' group."
|
||||||
)
|
)
|
||||||
time.sleep(1)
|
else:
|
||||||
sys.exit(1)
|
break
|
||||||
|
id += 1
|
||||||
|
|
||||||
self.create_timer(0.15, self.send_controls)
|
self.create_timer(0.15, self.send_controls)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user