Queston regarding Panning servo via Ps2

ok here is a short-ish code. (hope its short enough to post like this)
The following code is for Panning a servo using the left joystick on a Ps2 remote.
using ABBII, SSC32, APro28.

My question is: im finding that the reaction of the servo is slow in either direction, it will not return to center when j stick is zero’d. the speed is variable regarding the travel of the stick but its not reading the true values of the stick, by this i mean it either moves left or right with slow variable speed (as mentioned) but will not react to the true direction of the input.

any thoughts on this.?

[code];-------------Constants
;PS2 Controller / BotBoard II
DAT con P12
CMD con P13
SEL con P14
CLK con P15
SSC32 con p11

DeadZone con 28 ; must be >= 28
PadMode con $79

;Arm
Servo3Pin con 1
Servo3_PulseDef con 1500
Servo3_PulseMin con 850
Servo3_PulseMax con 2150
;-------------Variables
index var Byte
DualShock var Byte(7)
LastButton var Byte(2)

Time var Word

XCoord var Sbyte
YCoord var Sbyte
ZCoord var Sbyte
WCoord var Sbyte

Servo3_Pulse var word
;-------------Init
;DualShock
pause 500

clear
high CLK

again
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
low SEL
shiftout CMD,CLK,FASTLSBPRE,$1\8]
shiftin DAT,CLK,FASTLSBPOST,[DualShock(0)\8]
high SEL
pause 1
;serout S_OUT,i57600,"PadMode : ",HEX2 DualShock(0),13]
Sound 9,[100\4435]
if DualShock(0) <> PadMode then again

LastButton(0) = 255
LastButton(1) = 255

pause 500

;--------------------------------------------------------------------
;-------------Main loop
main
;DS2
low SEL
shiftout CMD,CLK,FASTLSBPRE,$1\8,$42\8]
shiftin DAT,CLK,FASTLSBPOST,[DualShock(0)\8, DualShock(1)\8, DualShock(2)\8, DualShock(3)\8, |
DualShock(4)\8, DualShock(5)\8, DualShock(6)\8]
high SEL
pause 1

XCoord = DualShock(5) - 128
if XCoord > DeadZone then
	XCoord = XCoord - DeadZone
elseif XCoord < -DeadZone
	XCoord = XCoord + DeadZone
else
	XCoord = 0 
endif

if XCoord then
	Servo3_Pulse = Servo3_Pulse + XCoord / 8
	if Servo3_Pulse > Servo3_PulseMax then
		Servo3_Pulse = Servo3_PulseMax
	elseif Servo3_Pulse < Servo3_PulseMin
		Servo3_Pulse = Servo3_PulseMin	
	endif
	serout SSC32,i38400,"#",DEC Servo3Pin,"P",DEC Servo3_Pulse," T100",13]
endif

pause 36		

LastButton(0) = DualShock(1)
LastButton(1) = DualShock(2)

goto main
[/code]

Jonny,

I don’t see where you set:

Servo3_Pulse == Servo3_PulseDef
initially.

You add and subtract a scaled Xcoord, which should work, but you need to start somehwere, no? Also need a way to find the real null position, which might not be at 1500.

Alan KM6VV

at the moment we have implemented NULL values.

[code]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[/code]

In Main:

[code] ;Start Button test
IF (DualShock(1).bit3 = 0) and LastButton(0).bit3 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

’ lvert=255-lvert ’ Changes vertical up from 0 to 255 and vertical down from 255 to 0.
lhori=255-lhori[/code]

these are the Subs:

Normalize if NormalizeValue < (NormalizeNull-DeadBand) then NormalizeValue = (127*NormalizeValue)/(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

So does the code work with these additions?

We have two “centering” problems. The center of the joystick, and the center of the servo.

Alan KM6VV