Files
sunnypilot/tools/joystick/README.md
T
DevTekVE 414d397e3f Handle missing pygame import gracefully
Wrap the pygame import in a try-except block to catch ImportError. This prevents the script from crashing and provides a clear message prompting the user to install pygame if it's missing.

Remove "inputs" package and update "pygame" dependency

The "inputs" package has been removed from the lockfile and dependency list, while "pygame" is now included universally without the "dev" extra marker. This change simplifies dependencies and ensures consistency across environments.

Update dependencies: replace 'inputs' with 'pygame'

Replaced the 'inputs' library with 'pygame' for joystickd dependencies in `pyproject.toml`. Additionally, removed a redundant 'pygame' entry from the general dependencies.

Ugly, I know, but soundd is unhappy with joystick

Allowing lat with mads

Invert steering input for joystick control

The steering axis input is now multiplied by -1 to reverse its direction. This ensures correct handling of the left stick's horizontal input, aligning behavior with expected control dynamics.

Refactor joystick control to use pygame for broader support

Replaced the `inputs` library with `pygame` for joystick handling, providing improved compatibility with Xbox and PlayStation controllers. Added initialization, adaptive mappings, deadzone handling, and enhanced event processing for robust joystick operation. Updated README with dependencies and usage information for Xbox controllers.
2025-05-25 17:31:19 +02:00

2.5 KiB

Joystick

Hardware needed: device running openpilot, laptop, joystick (optional)

With joystick_control, you can connect your laptop to your comma device over the network and debug controls using a joystick or keyboard. joystick_control uses inputs which supports many common gamepads and joysticks.

Note

You might need to install xow to use the Xbox One controller on comma device. Even though xone is recommended on the xow page, xow is the one that works with the comma device.

Usage

The car must be off, and openpilot must be offroad before starting joystick_control.

Using a keyboard

SSH into your comma device and start joystick_control with the following command:

tools/joystick/joystick_control.py --keyboard

The available buttons and axes will print showing their key mappings. In general, the WASD keys control gas and brakes and steering torque in 5% increments.

Joystick on your comma three

Plug the joystick into your comma three aux USB-C port. Then, SSH into the device and start joystick_control.py.

Joystick on your laptop

In order to use a joystick over the network, we need to run joystick_control locally from your laptop and have it send testJoystick packets over the network to the comma device.

  1. Connect a joystick to your PC.
  2. Connect your laptop to your comma device's hotspot and open a new SSH shell. Since joystick_control is being run on your laptop, we need to write a parameter to let controlsd know to start in joystick debug mode:
    # on your comma device
    echo -n "1" > /data/params/d/JoystickDebugMode
    
  3. Run bridge with your laptop's IP address. This republishes the testJoystick packets sent from your laptop so that openpilot can receive them:
    # on your comma device
    cereal/messaging/bridge {LAPTOP_IP} testJoystick
    
  4. Start joystick_control on your laptop in ZMQ mode.
    # on your laptop
    export ZMQ=1
    tools/joystick/joystick_control.py
    

Now start your car and openpilot should go into joystick mode with an alert on startup! The status of the axes will display on the alert, while button statuses print in the shell.

Make sure the conditions are met in the panda to allow controls (e.g. cruise control engaged). You can also make a modification to the panda code to always allow controls.