Javadoc link

 

 

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.

References

[[service/Joystick.py]]

Tutorials

  • http://myrobotlab.org/content/fine-servo-control-joystick-0
  • 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 net.java.games.input.test.ControllerTextTest
    java -Djava.library.path=./libraries/native/arm.32.linux -cp ./libraries/jar/jinput.jar:./libraries/jar/jinput-test.jar  net.java.games.input.test.ControllerReadTest
    java -Djava.library.path=./libraries/native/arm.32.linux -cp ./libraries/jar/jinput.jar:./libraries/jar/jinput-test.jar  net.java.games.input.test.RumbleTest
     
  • 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
Example code (from branch develop):
#########################################
# Joystick.py
# categories: input sensor joystick
# more info @: http://myrobotlab.org/service/Joystick
#########################################
# start the services
joy = runtime.start("joy","Joystick")
python = runtime.start("python","Python")
#this set which kind of controller you want to poll data from
#it is the number you can see in the Joystick GUI when you open the list of devices
joy.setController(5)
 
#tell joystick service to send data to python as a message only when new data is aviable
joy.addInputListener(python)
 
#this is the method in python which receive the data from joystick service
#it is triggered only when new data arrive, it's not a loop !
def onJoystickInput(data):
 #this print the name of the key/button you pressed (it's a String)
 #this print the value of the key/button (it's a Float)
 print data.id, data.value
 if (data.id == "3"):
     print("button 3 was pressed its value is", data.value)
 elif (data.id == "x"):
     print("stick x", data.value)    
Example configuration (from branch develop):
!!org.myrobotlab.service.config.JoystickConfig
analogListeners: null
componentListeners: null
controller: null
listeners: null
peers: null
type: Joystick