Note: This tutorial has not been user tested. This tutorial assumes that you have completed the previous tutorials: ROS tutorials, Configuring a Linux Joystick.
(!) 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 a Multiple Joystick System

Description: This tutorial uses the joystick remapping node to allow two different joysticks to control a single robot.

Keywords: Joystick, PS3

Tutorial Level: INTERMEDIATE

Homogeneous Joysticks

If you have multiple joysticks of the same type, you can simply have multiple instances of the joy_node running. They will automatically publish to the /joy topic. You will need to make sure to launch the joy_nodes with different names in the launch file, and make sure they are not trying to read from the same joystick device.

Some teleop nodes may have trouble with multiple joysticks. For example, if one joystick is publishing a (0.0, 0.0, ...) command and another is commanding a positive velocity, your robot might behave unpredictably depending on which message it gets last. In some cases this can be avoided by leaving autorepeat off for each joystick. As long as a joystick is not moved (it has no events), it will not send messages.

The remaining parts of this tutorial involve using heterogeneous joysticks.

Compiling

This tutorial uses the joystick_remapper package. In order to use this package, you'll have to build it. Make sure that it's built on every machine that you will use it on (robot, desktop, etc).

rosmake joystick_remapper

Familiarize yourself with the joystick_remapper package documentation before moving on.

Equipment

Make sure that you have two joysticks and proper receivers. Using the Joystick Tutorial, configure and set up each joystick. It is important that they don't use the same port. It may be useful to have them use different machines.

Select one joystick to be the "primary" joystick. Configure your teleop interface around this device (see Writing a Teleoperation Node for a Linux-Supported Joystick).

Next, you'll have to find out the differences in the button mapping between the two joysticks. For example, the upper left index finger button (L1) is button #6 on a Logitech joystick, but #10 on a PS3 SIXAXIS. Once you have determined the button mapping, you'll have a list like this:

Primary Joystick

Secondary Joystick

0

9

1

-1

2

-1

3

10

4

-1

5

-1

6

-1

7

-1

8

6

9

7

10

4

11

5

12

3

13

2

14

1

15

0

Ex: Button 0 on the primary is the same as button 9 on the secondary, etc. The buttons on the Logitech joystick are numbered, but the numbers start at 1 (in the ROS message, the button index starts at 0). Note that "-1" maps a joystick button or axis to null.

Convert that table to the text format recognized by the Joystick Remapper node.

9 -1 -1 10 -1 -1 -1 -1 6 7 5 4 3 2 1 0

This means that button 0->9, 2->10, and so on. Make a similar remapping chart for the axis mapping, if needed.

Remapping

Your primary joystick is probably already in the robot's launch file. If it is not, make a launch file that correctly brings up the joystick and test it by driving your robot around.

Now, make a launch file for your secondary joystick. See Roslaunch XML Reference for roslaunch syntax.

<launch>
  <!-- Publish on "second_joy" to remap it later -->
  <node pkg="joy" type="joy_node" name="second_joy" >
    <remap from="joy" to="second_joy" />
  </node>

  <node pkg="joystick_remapper" type="joystick_remapper.py" name="remapper" >
    <remap from="joy_source" to="second_joy" /> <!-- Set input correctly -->
    <remap from="joy_dest" to="joy" /> <!-- Republish on "joy" -->
    <param name="button_mapping" type="string" value="8 11 12 9 15" />
    <param name="axis_mapping" type="string" value="=" /> <!-- No changes -->
  </node>
</launch>

This will republish a corrected version of this joystick on the "joy" topic. Since this is the default topic, both joysticks will be publishing to any subscribers.

Testing

To test your remapping, echo the joy topic and make sure that the messages are going through:

rostopic echo joy

Verify that the button mapping is correct.

Now, launch your robot and your teleop node. Do not launch the primary joystick. (The primary is the one that isn't being remapped). Test only the secondary one at first. Make sure that the robot drives correctly with your secondary joystick.

After you have tested the secondary joystick, start up the primary joystick. You should be able to command the robot from either device.

If you experience problems controlling the robot from two devices, it may be because they are both publishing different commands at the same time. See the above section on Homogeneous Joysticks for ideas on making the joysticks work together.

Now you can control the robot from two different interfaces. This will allow for: two users to drive together, a safety driver to help a novice, or experimentation with different devices.

Wiki: joystick_remapper/Tutorials/UsingJoystickRemapper (last edited 2010-03-26 19:17:14 by aarons)