[Documentation] [TitleIndex] [WordIndex

Note: This tutorial assumes that you have completed the previous tutorials: ROS tutorials.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Configuring and Using a Linux-Supported Joystick with ROS

Description: This tutorial is an introduction to using the joystick connected to a desktop computer. After reading it, you should be able to bring up the joy node and display the data coming from the joystick over ROS.

Keywords: joystick, driver

Tutorial Level: BEGINNER

Next Tutorial: Writing a Teleoperation Node for a Linux-Supported Joystick


Start by installing the package:

$ sudo apt-get install ros-indigo-joy

Configuring the Joystick

Connect your joystick to your computer. Now let's see if Linux recognized your joystick.

$ ls /dev/input/

You will see a listing of all of your input devices similar to below:

As you can see above, the joystick devices are referred to by jsX ; in this case, our joystick is js0. Let's make sure that the joystick is working.

$ sudo jstest /dev/input/jsX

You will see the output of the joystick on the screen. Move the joystick around to see the data change.

Now let's make the joystick accessible for the ROS joy node. Start by listing the permissions of the joystick:

$ ls -l /dev/input/jsX

You will see something similar to:

If XX is rw: the js device is configured properly.

If XX is --: the js device is not configured properly and you need to:

$ sudo chmod a+rw /dev/input/jsX

Starting the Joy Node

To get the joystick data published over ROS we need to start the joy node. First let's tell the joy node which joystick device to use- the default is js0.

$ roscore
$ rosparam set joy_node/dev "/dev/input/jsX"

Now we can start the joy node.

$ rosrun joy joy_node

You will see something similar to:

Now in a new terminal you can rostopic echo the joy topic to see the data from the joystick:

$ rostopic echo joy

As you move the joystick around, you will see something similar to :

On electric and above the new sensor_msgs/Joy message is emitted, which includes a Header:

2019-06-15 12:48