Skip to content

Using Joysticks

Rob Linsalata edited this page Oct 4, 2013 · 4 revisions

Summary

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.

Overview

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/groovy/share/joy

If not run:

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

Substitute the appropriate ROS 'distro' for groovy if you are running 'electric' or other ROS versions.

Running the ROS joystick publisher

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

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

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
  1. 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.py <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).

See our specific instructions at PS3 Joystick Instructions.

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 iodevices/joystick.py script in the utilities package of the SDK.

Clone this wiki locally