Using Joysticks

From sdk-wiki
(Redirected from Ps3 joystick instructions)
Jump to: navigation, search


A number of examples in the RSDK use game controllers, or joysticks, to interact with Baxter. There is also a python utility for handling input devices like joysticks with common methods.


The ROS package joy makes it easy to use gamepad controllers in ROS programs by publishing the buttons and stick axes on a ROS Topic. Examples in the RSDK use this package to let users control Baxter with a joystick.

Any joystick controller supported by Linux should be compatible with the ROS joy package. Running the ROS joy_node publishes the input values on the /joy topic. The RSDK python examples then use a convenience class to map the array of button and axes values on this topic to a named dictionary. Every model of controller has a different definition of which button is which, so this class allows us to consistently map inputs to the same variables across brands. The RSDK examples themselves then use these consistent dictionary names and load the mapping the user indicates in an argument when you start the example.

Examples using joysticks

There are a couple RSDK examples already setup to use the joysticks to control Baxter. These can often be run in parallel with other tasks and programs and make it easier to position and coordinate Baxter while using the RSDK. Joystick examples include:

Running the Joystick Examples

Installing ROS Joystick Drivers

First ensure that the joy drivers are installed.

$ rospack find joy  
= /opt/ros/indigo/share/joy =

If not run:

$ sudo apt-get install ros-indigo-joystick-drivers

Substitute the appropriate ROS 'distro' for indigo if you are running other ROS distributions.

Running the ROS joystick publisher

Plug in your joystick and verify the computer can see the input device:

$ ls /dev/input/js*

If using a PS3 joystick, see Using a PS3 Joystick in order to make the device appear.

From an RSDK Shell start the joy_node:

$ rosrun joy joy_node

You should now be able to verify the ROS joystick part is working by echoing the /joy topic and seeing the joystick inputs being published when you use the joystick:

= in an RSDK shell: =
$ rostopic echo /joy

Running the RSDK Joystick Examples

Manual Start Method

For the joystick examples to work, the joy_node driver must be running at the same time as the example.

To manually start examples that use a joystick, you can run the joy_node program (joystick driver) in one terminal and the joint_position example in a second terminal:

1. If you haven't already run the joy_node from the previous step:

$ rosrun joy joy_node

2. In a second RSDK Shell, run the example program and pass it the type of joystick you are using in the <joystick_type> argument (e.g. 'logitech'):

$ rosrun joint_position <joystick_type>

Where <joystick_type> is 'xbox', 'logitech', or 'ps3'. (If using a ps3, make sure you run the node from the ROS ps3joy package in a separate sudo terminal. See instructions here: ps3joy )

Alternative Automatic Starting Joystick Example Programs

Examples that offer joystick integration will also include a special start script specifically for starting up the joystick drivers and the example at the same time. This script is usually called joystart.

RSDK Beta Version: To run the example:

$ rosrun joint_position joystart <joystick_type>

For the joystick examples to work, the joy_node driver must be running at the same time as the example. Using any one-line command to launch or start a joystick example is actually just using a short-cut to start the two programs at once.

Alternate Options

Specifying an input device

The joystick device used defaults to /dev/input/js0. If you have multiple input devices connected or want to specify a specific device to use, you can use the following commands.

List current input devices:

$ ls /dev/input/js*
/dev/input/js0  /dev/input/js1

From an RSDK Shell, before starting the ROS node, set the joy_node input device ROS Paramater, ~/dev, to your desired input device:

$ rosparam set /joy_node/dev /dev/input/js1

Then start the example with either the Automatic or Manual method:

$ rosrun joint_position joystart <joystick_type>

Using the PS3 Joystick

The PS3 SIXAXIS or DUALSHOCK3 joysticks require an additional component to run in order to support the bluetooth and special features of the joysticks. These drivers are thankfully taken care of in the ROS ps3joy package (included in the ros-<distro>-joystick-drivers install).

Install ROS Joystick drivers

$ sudo apt-get install ros-indigo-joystick-drivers
$ sudo apt-get install ros-hydro-joystick-drivers
$ sudo apt-get install ros-groovy-joystick-drivers

Make sure dependencies are installed:

$ rosdep update
$ rosdep install ps3joy

Pairing Controller

Set Controller’s target to this PC’s Bluetooth Address:

  • Plug PS3 into computer using USB cable.
$ cd ~/ros_ws
$ sudo ./
$ rosrun ps3joy sixpair

Connecting Bluetooth Controller for Use (Each Session)

In a background terminal, run joystick connection/driver:

$ cd ~/ros_ws
$ sudo ./
$ rosrun ps3joy

Activate connection:

  • Press ‘Playstation’ Pairing Button on Controller (unplugged).
  • Lights will start flashing rapidly and terminal will say Connection is Activated.
  • Leave terminal / program running in background.

Controller will now show up as /dev/input/js*. Can now be run like normal joystick.

Running Examples with a PS3 Controller

Run joystart script for examples like normal, using ‘ps3’ mapping argument, e.g:

$ cd ~/ros_ws
$ ./
$ rosrun baxter_examples -j ps3

Joystick Button Mappings

Look at the wiki page for individual examples to see how the buttons are mapped. Make sure you start the examples with the correct type of joystick selected, as they change per device type. You can modify or create your own joystick mappings by editing the joystick script via rosed baxter_examples