πŸ”§ Gamepad Setup#

Purpose#

Set up a Logitech Gamepad on the Master to work with ROS2 Humble on Ubuntu. This will allow you to use a Logitech Gamepad for controlling robots. Follow these steps to install dependencies, configure the gamepads, and test them in your ROS2 workspace.

../_images/LogitechGamepad.png

Steps#

1. Install the joy Package#

(Note: This package is already installed on the Master computer.)
The joy package in ROS2 is required to read inputs from gamepads. If needed, install it with the following commands:

sudo apt update  
sudo apt install ros-humble-joy  

2. Install the teleop_twist_joy Package#

(Note: This package is also pre-installed on the Master computer.)
If you plan to control a robot with the gamepad, install the teleop_twist_joy package:

sudo apt install ros-humble-teleop-twist-joy  

3. Plug in Your Gamepads#

Connect your Logitech Gamepad to your computer via USB.

4. Verify Gamepad Detection#

To ensure the gamepads are detected:

  1. Open a terminal and run:

    ls /dev/input/js*  
    
  2. You should see output like js0, js1, etc., corresponding to your connected gamepads.

5. Install and Use the Joystick GUI Calibration Tool#

  1. Install the joystick calibration tool:

    sudo apt-get install jstest-gtk  
    
  2. Launch the calibration tool:

    jstest-gtk  
    
  3. Once the GUI opens:

    • Double-click on your gamepad to open its settings.

    • Move the joysticks and press buttons to see which axes and buttons correspond to the output values.

    • If the joystick values do not return to zero in the neutral position, click the Calibration button and follow the steps to calibrate the gamepad.

6. Launch the joy Node#

The joy node reads input from your gamepads and publishes joystick data to ROS topics. To start the node, run:

ros2 run joy joy_node  

7. Test Joystick Output#

  1. Check that the gamepad is working by echoing the /joy topic:

    ros2 topic echo /joy  
    
  2. Move the joysticks or press buttons on your gamepad. You should see data being published in the terminal.