I have a PS2 wireless controller connected to PC using the USB converter.I intend to read it under any programming language so that I can control my hexapod with PS2 controller through PC software.
Does anyone have any code in C++,visual basic or matlab for reading a USB joystick?
Have not been able to make any progress yet; this task seems quite elusive to me at this stage!
Any one has got some guidelines for reading a PS2 controller in windows, connected at USB port?
You will need to research the languages you desire to use for joystick code. Below is some code I use with just basic to operate a two servo pan/tilt cam via a mini-ssc servo controller using a joystick.
open "joystick demo" for window as #joy
OPEN "com1:9600,N,8,1,CD0,CS0,DS0,OP0" FOR OUTPUT AS #2
#joy "trapclose [quit]"
timer 10, [readStick] 'every ten ms read the stick
wait
[readStick]
scan
readjoystick 1 'either 1 or 2
x = (Joy1x - 1200)/195
y = (Joy1y - 1200)/195
x1 = int(x)
y1 = int(y)
if x1 > 255 then x1 = 255
if y1 > 255 then y1 = 255
x1 = 255 - x1 ' use this to reverse the servo rotation
y1 = 255 - y1 ' use this to reverse the servo rotation
if Joy1button1 = 1 then
PRINT #2, CHR$(00); CHR$(128); CHR$(x1);
PRINT #2, CHR$(01); CHR$(128); CHR$(y1);
end if
if Joy1button2 = 2 then
PRINT #2, CHR$(00); CHR$(128); CHR$(x1);
PRINT #2, CHR$(01); CHR$(128); CHR$(y1);
end if
wait
[quit]
CLOSE #2
close #joy
end
It is a simple intro programming application called JustBasic. It is a simple form of a more advanced programming application called Libertybasic. JB is free. I use it to test servo setups and such. The above program is a barebones test program for testing servo control with a joystick (I just noticed I left off the first line when I cut/pasted the code, so i put it back in). I find it very useful and easy for testing hardware without complicated programming.
Hey thanks, zoomkat! This looks worthwhile. It has serial comms and joystick support. Might be the solution I’m looking for to control my mech, Clyde. I would like to try substituting the serial cable for my bluetooth module instead though. PS2 is great for playing around at home, but I’m afraid the band would be too crowded for reliable operation at Robogames.
BTW, been following your work with webcams and remote servo operation. Great stuff, keep it up!