From 97c0d72943c122d149a7cb89ec56abc781a552bf Mon Sep 17 00:00:00 2001 From: Jetson Nano1 Date: Fri, 6 Mar 2026 21:42:55 +0000 Subject: [PATCH 1/2] ps5 controller as drive --- src/Bringup/launch/control.launch.py | 8 ++- .../launch/controller.launch.py | 58 ++++++++++++------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/Bringup/launch/control.launch.py b/src/Bringup/launch/control.launch.py index 598e043..6f61f2f 100644 --- a/src/Bringup/launch/control.launch.py +++ b/src/Bringup/launch/control.launch.py @@ -111,11 +111,15 @@ def generate_launch_description(): condition=IfCondition(use_arm), ) - delayed_spawners = RegisterEventHandler( OnProcessStart( target_action=controller_manager, - on_start=[jsb_spawner, chassis_controller_spawner, arm_controller_move_it_spawner, arm_controller_servo_spawner], + on_start=[ + jsb_spawner, + chassis_controller_spawner, + arm_controller_move_it_spawner, + arm_controller_servo_spawner, + ], ) ) diff --git a/src/Teleop-Control/joystick_control/launch/controller.launch.py b/src/Teleop-Control/joystick_control/launch/controller.launch.py index 0b473d9..71d9b58 100644 --- a/src/Teleop-Control/joystick_control/launch/controller.launch.py +++ b/src/Teleop-Control/joystick_control/launch/controller.launch.py @@ -25,27 +25,45 @@ def get_joy_id(dev_path): return -1 +def find_ps5(): + with open("/proc/bus/input/devices") as f: + device_block = "" + for line in f: + if line.strip() == "": + if "Wireless Controller" in device_block: + for part in device_block.split(): + if part.startswith("js"): + print(f"Found PS5 controller at {part}") + return int(part.replace("js", "")) + device_block = "" + else: + device_block += line + print(f"ERROR: PS5 controller not found in /proc/bus/input/devices") + return -1 + + 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 id_arm = get_joy_id("/dev/input/by-id/usb-LiteStar_PXN-2113_Pro-joystick") - id_drive = get_joy_id("/dev/input/by-id/usb-Thrustmaster_T.1600M-joystick") + # id_drive = get_joy_id("/dev/input/by-id/usb-Thrustmaster_T.16000M-joystick") + # id_drive = get_joy_id("/dev/input/by-id/bluetooth-Sony_Interactive_Entertainment_DualSense_Wireless_Controller-if03-joystick") return LaunchDescription( [ - # Node( - # package="joy", - # executable="joy_node", - # name="joy_node_a", - # parameters=[ - # { - # "device_id": id_drive, - # "deadzone": 0.05, - # } - # ], - # remappings=[("/joy", "/drive/joy")], - # ), + Node( + package="joy", + executable="joy_node", + name="joy_node_a", + parameters=[ + { + "dev": find_ps5(), + "deadzone": 0.05, + } + ], + remappings=[("/joy", "/drive/joy")], + ), Node( package="joy", executable="joy_node", @@ -66,12 +84,12 @@ def generate_launch_description(): parameters=[parameters_file], remappings=[("/joy", "/arm/joy")], ), - # Node( - # package="joystick_control", - # executable="drive", - # name="drive_teleop_node", - # parameters=[parameters_file], - # remappings=[("/joy", "/drive/joy")], - # ), + Node( + package="joystick_control", + executable="drive", + name="drive_teleop_node", + parameters=[parameters_file], + remappings=[("/joy", "/drive/joy")], + ), ] ) From 34f89623cdca6fd2e217cafe46bf0bfce7800f6a Mon Sep 17 00:00:00 2001 From: Jetson Nano1 Date: Sat, 7 Mar 2026 16:46:03 +0000 Subject: [PATCH 2/2] fixed ps5 find --- .../launch/controller.launch.py | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Teleop-Control/joystick_control/launch/controller.launch.py b/src/Teleop-Control/joystick_control/launch/controller.launch.py index 1284b62..9b722d2 100644 --- a/src/Teleop-Control/joystick_control/launch/controller.launch.py +++ b/src/Teleop-Control/joystick_control/launch/controller.launch.py @@ -8,20 +8,27 @@ from ament_index_python.packages import get_package_share_directory def find_ps5(): - with open("/proc/bus/input/devices") as f: - device_block = "" - for line in f: - if line.strip() == "": - if "Wireless Controller" in device_block: - for part in device_block.split(): - if part.startswith("js"): - print(f"Found PS5 controller at {part}") - return int(part.replace("js", "")) - device_block = "" - else: - device_block += line - print(f"ERROR: PS5 controller not found in /proc/bus/input/devices") - return -1 + 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():