This service allows input from usb joysticks or gamepads. You can attach to a joystick and examine axis or button data.  These button and joystick events can be sent to other services, such as servos or motor services.  It could be used for a "manual" override to take control of a robot.

Since Servos require a range of values from 0 to 180, and Joystick's raw data is between -1.0 and 1.0 a tranform is possible.   To transform -1.0 to 1.0 to 0 to 180 we need a multiplier and an offset.  In this case the multiplier is 90 and the offset is 90.

Arduino PWM values require a range between 0 and 255.  The multiplier would be 127 and the offset is 127 - this will allow the Joystick service to send correct values to an Arduino PWM.

Programmatic control can be done with Python through the Jython service.


#file : service/ edit raw
# start the service
joystick = Runtime.start("joystick","Joystick")
# print the controllers out - there may be many
# the format will be like this
# {0 - HID Keyboard Device: 0, 1 - Standard PS/2 Keyboard: 1, 2 - HID-compliant mouse: 2, 3 - Dell Touchpad: 3, 4 - 3Dconnexion KMJ Emulator: 4, 5 - Logitech Cordless RumblePad 2: 5}
# in this case I want to attach the service to the Logitech Cordless RumblePad 2, which is controller number 5
# now we'll subscribe the python to the joystick publishJoystickInput - which will make the data come back to onJoystickInput method

# this is a callback method in Jython
# when data comes from the Joystick this method is called
# "data" contains and id & value - you can add if statements
# which determine which component was pressed or moved - then do
# something exciting - like move the robot left or close the gripper
def onJoystickInput(data):
  print(data,, data.value)

  if == u'6':
    print("button 6 is ", data.value)
  if == u'z':
    print("axis z is ", data.value)


  • Testing on Raspberry Pi in the MRL Installation directory with jinput-test.jar

    java -Djava.library.path=./libraries/native/arm.32.linux -cp ./libraries/jar/jinput.jar:./libraries/jar/jinput-test.jar
    java -Djava.library.path=./libraries/native/arm.32.linux -cp ./libraries/jar/jinput.jar:./libraries/jar/jinput-test.jar
    java -Djava.library.path=./libraries/native/arm.32.linux -cp ./libraries/jar/jinput.jar:./libraries/jar/jinput-test.jar
  • If you want to use a PS3 Controller/Joystick using Bluetooth on a Raspberry PI, this is a guide on how to do that: PS3 Joystick