diff --git a/tools/joystick/joystickd.py b/tools/joystick/joystickd.py index 17f220001a..bb8f483835 100755 --- a/tools/joystick/joystickd.py +++ b/tools/joystick/joystickd.py @@ -40,16 +40,13 @@ class Keyboard: class Joystick: - def __init__(self, gamepad=False): - # TODO: find a way to get this from API, perhaps "inputs" doesn't support it - if gamepad: - self.cancel_button = 'BTN_NORTH' # (BTN_NORTH=X, ABS_RZ=Right Trigger) - accel_axis = 'ABS_Y' - steer_axis = 'ABS_RX' - else: - self.cancel_button = 'BTN_TRIGGER' - accel_axis = 'ABS_Y' - steer_axis = 'ABS_RX' + def __init__(self): + # This class supports a PlayStation 5 DualSense controller on the comma 3X + # TODO: find a way to get this from API or detect gamepad/PC, perhaps "inputs" doesn't support it + # TODO: the mapping can also be wrong on PC depending on the driver + self.cancel_button = 'BTN_NORTH' # BTN_NORTH=X/triangle + accel_axis = 'ABS_Y' + steer_axis = 'ABS_Z' self.min_axis_value = {accel_axis: 0., steer_axis: 0.} self.max_axis_value = {accel_axis: 255., steer_axis: 255.} self.axes_values = {accel_axis: 0., steer_axis: 0.} @@ -87,18 +84,20 @@ def send_thread(joystick): print('\n' + ', '.join(f'{name}: {round(v, 3)}' for name, v in joystick.axes_values.items())) rk.keep_time() + def joystick_thread(joystick): Params().put_bool('JoystickDebugMode', True) threading.Thread(target=send_thread, args=(joystick,), daemon=True).start() while True: joystick.update() + if __name__ == '__main__': parser = argparse.ArgumentParser(description='Publishes events from your joystick to control your car.\n' + - 'openpilot must be offroad before starting joysticked.', + 'openpilot must be offroad before starting joystickd. This tool supports ' + + 'a PlayStation 5 DualSense controller on the comma 3X.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('--keyboard', action='store_true', help='Use your keyboard instead of a joystick') - parser.add_argument('--gamepad', action='store_true', help='Use gamepad configuration instead of joystick') args = parser.parse_args() if not Params().get_bool("IsOffroad") and "ZMQ" not in os.environ: @@ -114,6 +113,7 @@ if __name__ == '__main__': print('- `C`: Cancel cruise control') else: print('Using joystick, make sure to run cereal/messaging/bridge on your device if running over the network!') + print('If not running on a comma device, the mapping may need to be adjusted.') - joystick = Keyboard() if args.keyboard else Joystick(args.gamepad) + joystick = Keyboard() if args.keyboard else Joystick() joystick_thread(joystick)