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 : Joystick.robotHand.py
arduino = Runtime.createAndStart("arduino","Arduino")
joystick = runtime.createAndStart("joystick","Joystick")
hand = Runtime.createAndStart("hand","Servo")
arduino.setSerialDevice("COM3", 57600, 8, 1, 0)
arduino.attach(hand.getName() , 2)
b = 100
x = msg_joystick_XAxisRaw.data
if (x == 1):
b += 1
elif (x == -1):
b -= 1
# the API is 0 based cause arrays are 0 based - but when I count button I start with 1
# so now buttons start @ 1 msg_joystick_button1 = button1 - its the "right" thing to do ...
# anyway Alessandruino said we are men not machines - so I will make it manly and not sissy machine !
a = msg_joystick_button1.data
if (a == 1):
print 'button pressed'
elif ( a == 0):
print 'button not pressed'
#create a message route from joy to python so we can listen for button
joystick.addListener("XAxisRaw", python.name, "x")
joystick.addListener("button1", python.name, "a")
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