Johnny 5 with PS2 control

Anybody able to lend a hand to control Johnny 5 with a PS2 control? Currently am able to run it from SSC32 or to run the tri track with PS2 (Bot Board II and Atom Pro), but did so with the help of tutorials. I would really appreciate any help with controlling the rest of the servos with PS2, thanks!

I had my J5 working from the PS2 controller. I connected all servos to the Bot Board II. Unfortunately the Bot Board does not have enough usable connections for all the servos that J5 has, so you may have to pick and choose. Then just change your program to include the necessary code. My code was as follows…

[code]'Program name: j5 custom.BAS
'Author: Jim Frye / Nathan Scherdin (PS2 stuff)
'Modified by Laurent Gay : speed limit control with L1/L2
'Modified by Brian Nave : Normalized analog joysticks, named button variables,
’ positive boolean logic, audio feedback on speed limit
'Modified by Laurent Gay : New PS2 Controller code (more compatible)
'Modified by James Frye : Configured for Atom Pro
'Modified by Johnathan Veenstra : Configured for Johnny 5.

’ This program allows the remote control of a differentially steered robot
’ from the Sony Play Station 2 game controller.

’ The Sabertooth mode of operation is the mixer mode. This is where you have a
’ Throttle for forward and reverse speed control, and a Steering control for
’ turning. In this mode the left input is throttle and the right input is steering.
’ See the Sabertooth manual.
'*********************************************************************************
'Connections

'BotBoard II :

'Pin 12 PS2 Data
'Pin 13 PS2 Command
'Pin 14 PS2 Select
'Pin 15 PS2 Clock
'Pin 0 Sabertooth Forward.
'Pin 1 Sabertooth Turn.
'Pin 2 Pan Right/Left servo.
'Pin 3 Head Right/Left servo.
'Pin 4 UpperTorso Forward/Back servo.
'Pin 5 LowerTorso Forward/Back servo.
'Pin 6 RightArm Up/Down servo.
'Pin 7 LeftArm Up/Down servo.
'Pin 8 RightHand Forward/Back servo.
'Pin 9 LeftHand Forward/Back servo.
'Pin 10 RightArm Right/Left servo.
'Pin 11 LeftArm Right/Left servo.
'****************************************
DAT con P12
CMD con P13
SEL con P14
CLK con P15
TrkFwd con p0
TrkTurn con p1
Pan con p2
Head con p3
LowTorso con p4
UpTorso con p5
RArmUD con p6
LArmUD con p7
RHand con p8
LHand con p9
RArmLR con p10
LArmLR con p11

temp var byte ’ Variable definitions.
buttons var word
Lastbuttons var word

bpress1 var bit
bpress2 var bit

rhori var byte
rvert var byte
lhori var byte
lvert var byte

rhori_null var byte
rvert_null var byte
lhori_null var byte
lvert_null var byte

NormalizeValue var byte
NormalizeNull var byte
DeadBand con 2

ldrive var word
rdrive var word
PanPosition var word
HeadPosition var word

UpperTorsoPosition var word
LowerTorsoPosition var word

RightArm_UD var word
LeftArm_UD var word
RightHand_OC var word
LeftHand_OC var word
RightArm_LR var word
LeftArm_LR var word

Button_START var bit
Button_SELECT var bit

Button_L1 var bit
Button_L2 var bit
Button_R1 var bit
Button_R2 var bit

Button_A var bit
Button_O var bit
Button_X var bit
Button_S var bit

Dpad_UP var bit
Dpad_RIGHT var bit
Dpad_LEFT var bit
Dpad_DOWN var bit

PanPosition = 1400 ’ Start the servos at mid position.
headPosition = 1421
UpperTorsoPosition = 1500
LowerTorsoPosition = 1550
RightArm_UD = 1575
LeftArm_UD = 1425
RightHand_OC = 1200
LeftHand_OC = 1900
RightArm_LR = 1650
LeftArm_LR = 1500

low p0 ’ Ensure pulsout commands are positive going.
low p1
low p2
low p3
low p4
low p5
low p6
low p7
low p8
low p9
low P10 ’ Ensure device connected to pin 10 and 11 is off on startup
low P11

high CLK ’ Ensure CLK is negative going.

'sound 9, [100\880, 100\988, 100\1046, 100\1175] 'four quick ascending notes.

pause 1000

setup
’ This section sets the PSX Controller to Analog Mode. (red LED should light)
’ This will work with Sony and Madcatz wired, but not with Medcatz wireless.
’ You must press the analog button on the controller to set to analog mode.
low SEL
shiftout CMD,CLK,FASTLSBPRE,$1\8]
shiftin DAT,CLK,FASTLSBPOST,[temp\8]
high SEL
pause 1

if (temp <> $73) and (temp <> $79) then
	low SEL
	shiftout CMD,CLK,FASTLSBPRE,$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER
	high SEL
	pause 1
	
	low SEL
	shiftout CMD,CLK,FASTLSBPRE,$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK
	high SEL
	pause 100
	
	low SEL
	shiftout CMD,CLK,FASTLSBPRE,$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE
	high SEL
	pause 1
	
	;low SEL
	;shiftout CMD,CLK,FASTLSBPRE,$01\8,$4D\8,$00\8,$00\8,$01\8,$FF\8,$FF\8,$FF\8,$FF\8] ;VIBRATION_ENABLE
	;high SEL
	;pause 1

	low SEL
	shiftout CMD,CLK,FASTLSBPRE,$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE
	high SEL
	pause 1
	
	low SEL
	shiftout CMD,CLK,FASTLSBPRE,$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT
	high SEL
	pause 1

	goto setup
endif

gosub get_PSX_data
gosub NullJoysticks

main
gosub get_PSX_data

'if Button_START then : gosub NullJoysticks : endif

'SET LINEARIZED JOYSTICK DISPLACEMENT BASED ON JOYSTICK CENTER POSITION
'NormalizeValue = lhori : NormalizeNull = lhori_null : gosub Normalize : lhori = NormalizeValue
'NormalizeValue = lvert : NormalizeNull = lvert_null : gosub Normalize : lvert = NormalizeValue
'NormalizeValue = rhori : NormalizeNull = rhori_null : gosub Normalize : rhori = NormalizeValue
'NormalizeValue = rvert : NormalizeNull = rvert_null : gosub Normalize : rvert = NormalizeValue

'   remove the rems (') to see the NORMALIZED joystick values in terminal 1.
'	serout S_OUT,i57600,[dec3 lhori\3," ",dec3 lvert\3," ",dec3 rhori\3," ",dec3 rvert\3," ", 13]

’ lvert=255-lvert ’ Changes vertical up from 0 to 255 and vertical down from 255 to 0.
lhori=255-lhori

'CALCULATE DRIVE SPEEDS FROM JOYSTICK POSITIONS AND SPEED LIMIT
ldrive=((lvert*4) + 1500 - (4 128)) ’ Forward / backward Start at Gear 3 (from 1 to 4)
rdrive=((lhori
3) + 1500 - (3 *128)) ’ steering

'   remove the rems (') to see the calculated drive motor speeds in terminal 1.
'	serout S_OUT,i57600,[dec5 ldrive\5," ",dec5 rdrive\5," ",13]


PanPosition  = (PanPosition  + (rhori-127)/5) MAX 2250 MIN 750
HeadPosition = (headPosition + (rvert-127)/5) MAX 2250 MIN 750

RightArm_UD = (RightArm_UD - Button_A*25 + Button_X*25) 	MAX 2250 MIN 750 	'Right Arm Up and Down.
RightArm_LR = (RightArm_LR - Button_O*25 + Button_S*25) 	MAX 2250 MIN 750 	'Right Hand Left/Right.
RightHand_OC = (RightHand_OC - Button_R2*25 + Button_R1*25) MAX 2250 MIN 750 	'Right Hand Open/Close.

LeftArm_UD = (LeftArm_UD - Dpad_DOWN*25  + Dpad_UP*25) 	    MAX 2250 MIN 750 	'Right Arm Up and Down.
LeftArm_LR = (LeftArm_LR - Dpad_RIGHT*25 + Dpad_LEFT*25) 	MAX 2250 MIN 750 	'Right Hand Left/Right.
LeftHand_OC = (LeftHand_OC - Button_L1*25 + Button_L2*25) 	MAX 2250 MIN 750 	'Right Hand Open/Close.

'   remove the rems (') to see the gripper and pan positions in terminal 1.
'serout S_OUT,i57600,[dec4 PanPosition\4," ",dec4 HeadPosition\4, 13]
'serout S_OUT,i57600,[dec4 LeftArm_UD\4," ",dec4 LeftArm_LR\4," ",dec4 LeftHand_OC\4, 13]
'serout S_OUT,i57600,[dec4 RightArm_UD\4," ",dec4 RightArm_LR\4," ",dec4 RightHand_OC\4, 13]

’ Send out the servo pulses
pulsout 0,(ldrive2) ’ Left Sabertooth Forward channel.
pulsout 1,(rdrive
2) ’ Right Sabertooth Turn channel.
pulsout 2,(PanPosition2) ’ Pan servo.
pulsout 3,(headPosition
2) ’ Head servo.
pulsout 4,(UpperTorsoPosition2) ’ Upper Torso servo.
pulsout 5,(LowerTorsoPosition
2) ’ Lower Torso servo.
pulsout 6,(RightArm_UD2) ’ Right Arm Up/Down servo.
pulsout 7,(LeftArm_UD
2) ’ Left Arm Up/Down servo.
pulsout 8,(RightHand_OC2) ’ Right Hand Open/Close servo.
pulsout 9,(LeftHand_OC
2) ’ Left Hand Open/Close servo.
pulsout 10,(RightArm_LR2) ’ Right Arm Left/Right servo.
pulsout 11,(LeftArm_LR
2) ’ Left Arm Left/Right servo.
pause 20
goto main

get_PSX_data
’ This section gets the data from the PSX controller.
’ The first byte is the mode (Temp)
’ The 2 next bytes are the pushbutton data (button1, button2).
’ The 4 next bytes are the analog joystick data (rhori,rvert,lhori,lvert).
Lastbuttons = buttons
low SEL
’ Initiate request for data from PSX controller.
shiftout CMD,CLK,FASTLSBPRE,$1\8,$42\8]
’ Temp is the Mode value, it will be dumped. Then it puts the button data into two byte variables.
shiftin DAT,CLK,FASTLSBPOST,[temp\8,buttons.LOWBYTE\8,buttons.HIGHBYTE\8,rhori\8,rvert\8,lhori\8,lvert\8]
high SEL
pause 1

buttons = buttons ^ $FFFF	' SO WE CAN USE POSITIVE BOOLEAN LOGIC WHEN EVALUATING BUTTONS

Button_SELECT 	= Buttons.bit0
Button_START 	= Buttons.bit3

Dpad_UP 		= Buttons.bit4
Dpad_RIGHT 		= Buttons.bit5
Dpad_DOWN 		= buttons.bit6
Dpad_LEFT 		= Buttons.bit7

Button_L2 		= Buttons.bit8
Button_R2 		= Buttons.bit9
Button_L1 		= Buttons.bit10
Button_R1 		= Buttons.bit11

Button_A 		= Buttons.bit12
Button_O 		= Buttons.bit13
Button_X 		= Buttons.bit14
Button_S 		= Buttons.bit15	

’ remove the rems (’) to see the RAW joystick and Button values in terminal 1.
’ serout S_OUT,i57600,[bin buttons\16," “]
’ serout S_OUT,i57600,[dec3 rhori\3,” “,dec3 rvert\3,” “,dec3 lhori\3,” “,dec3 lvert\3,” "]
’ serout S_OUT,i57600,[13]
return

Normalize
if NormalizeValue < (NormalizeNull-DeadBand) then
NormalizeValue = (127NormalizeValue)/(NormalizeNull-DeadBand) MAX 127
elseif NormalizeValue > (NormalizeNull+DeadBand)
NormalizeValue = (127
(NormalizeValue-NormalizeNull)/(255-DeadBand-NormalizeNull) + 127) MAX 255
else
NormalizeValue = 127
endif
return

NullJoysticks
'READ ANALOG JOYSTICKS TO NULL OFF-CENTER VALUES
rhori_null = rhori
rvert_null = rvert
lhori_null = lhori
lvert_null = lvert
return
[/code]

I did not like the range of the PS2 controller…about 20 ft. Overall was a great addition to J5. Lynxmotion gives a drawing for a setup using the SSC32 + PS2 controller w/ Bot Board II, but I am am not sure if the intentions of that was only to control base or not.

Old post, but here is a thread with a J5 style bot controlled from the PS2 using the SSC-32, and it includes code. :wink:
viewtopic.php?f=20&t=6805