-
Notifications
You must be signed in to change notification settings - Fork 6
Using Joysticks
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
- Running the Example:
- Alternate Options
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.
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:
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.
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
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:
- If you haven't already run the
joy_node
from the previous step:
$ rosrun joy joy_node
- 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 )
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.
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>
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.
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.