diff --git a/src/Teleop-Control/joystick_control/launch/controller.launch.py b/src/Teleop-Control/joystick_control/launch/controller.launch.py index fc2bb13..9b722d2 100644 --- a/src/Teleop-Control/joystick_control/launch/controller.launch.py +++ b/src/Teleop-Control/joystick_control/launch/controller.launch.py @@ -7,13 +7,36 @@ import os from ament_index_python.packages import get_package_share_directory +def find_ps5(): + try: + with open("/proc/bus/input/devices", "r") as f: + device_block = "" + for line in f: + if line.strip() == "": + if "Wireless Controller" in device_block: + # Find the handlers line, e.g., H: Handlers=event19 js0 + for part in device_block.split(): + if part.startswith("js"): + # Return the full path string, not just the number + dev_path = f"/dev/input/{part.strip()}" + print(f"Found PS5 controller at {dev_path}") + return dev_path + device_block = "" + else: + device_block += line + except Exception as e: + print(f"Error reading devices: {e}") + + print("ERROR: PS5 controller not found. Defaulting to /dev/input/js0") + return "/dev/input/js0" + def generate_launch_description(): pkg_joystick_control = get_package_share_directory("joystick_control") parameters_file = os.path.join(pkg_joystick_control, "pxn.yaml") # Detect IDs dynamically arm_dev = "/dev/input/by-id/usb-LiteStar_PXN-2113_Pro-joystick" - drive_dev = "/dev/input/by-id/usb-Thrustmaster_T.16000M-joystick" + drive_dev = find_ps5() ld = LaunchDescription()