|
I have a program that reads the joystick values from a PS2 controller. The program work great and I can see all of the values change when the joy sticks are moved. However, as soon as I add an hservo command to the program (even the initialization command for analog servos - hservo [p0\0,p1\0,p2\0,p3\0]) I get corrupted text coming back in the terminal window.
Below are two examples of corrupted values while attempting to read the X Axis value of the right joystick:
¢ight XAxis:@0 RXAxisCëÉÉ+s£Ó þ0
RiÃK› «‰É+s£Óght XAxis: 0 Ra þ0
The full program code is listed below:
If I comment out all hservo commands everything looks fine in the terminal window
;[PS2 Controller Constants] ; Set the constants to match how the wires are connected to the ARC-32 board ; For a PS2 controller use AUX2 since these pins all have a built in pull up resistor on the ARC-32 board ; and it is required for a PS2 controller. DAT con P43 ; Constant - PS2 Controller DAT (Brown) CMD con P42 ; Constant - PS2 controller CMD (White) ATT con P41 ; Constant - PS2 Controller SEL (Yellow) CLK con P40 ; Constant - PS2 Controller CLK (Blue) PadMode con $79
ENABLEHSERVO ENABLEHSERVO2 ; This command MUST!!! be present to control servos on the ARC-32 ; See P. 14 of servo_controller_robot_80010.pdf
;-------------------------------------------------------------------- ;[Ps2 Controller Variables] DualShock var Byte(18) ; array of 18 Bytes of RAM memory storage LastButton var Byte(2) ; array of 2 Bytes of RAM memory storage DS2Mode var Byte ; Dual Shock 2 Mode - 1 Byte of RAM memory storage ;PS2Index var byte ; 1 Byte of RAM memory storage
RXAxisCurrent var Word RXAxisPrevious var Word RXAxisCurrent = 0 RXAxisPrevious = 0 ;hservo [p0\0,p1\0,p2\0,p3\0] ;-------------------------------------------------------------------- main gosub ControlInput[dualshock(16),dualshock(17)] ; serout txpin{\fpin},baudmode,{pace,}{timeout,tlabel,}[{modifi ers} OutputData1, ..., {modifi ers} OutputDataN] ; Note: s_out or S_OUT is a reserved word in MBASIC ; NOTE: the 0 in the first serout command is to clear the terminal window screen. ; sdec = Signed decimal ; SDEC{#max} expression{\#min} ; #max: optional maximum number of digits to send ; #min: optional minimum number of digits to send ; The DEC modifi er when used in an output command will convert a stored values to ASCII characters. ; The example will format the value of temp so it prints out the number in a terminal window. The output
;serout s_out,i38400,[0," DPad-Left: ",bin1 dualshock(0).bit7\1," ",dec dualshock(7),13] ;serout s_out,i38400,[" DPad-Down: ",bin1 dualshock(0).bit6\1," ",dec dualshock(9),13] ;serout s_out,i38400,[" DPad-Right: ",bin1 dualshock(0).bit5\1," ",dec dualshock(6),13] ;serout s_out,i38400,[" DPad-Up: ",bin1 dualshock(0).bit4\1," ",dec dualshock(8),13] serout s_out,i38400,[0," Right XAxis: ",sdec 128-dualshock(2),13] ;serout s_out,i38400,[" Right YAxis: ",sdec 128-dualshock(3),13] ;serout s_out,i38400,[" Left XAxis: ",sdec 128-dualshock(4),13] ;serout s_out,i38400,[" Left YAxis: ",sdec 128-dualshock(5),13] ;serout s_out,i38400,[" Start: ",bin1 dualshock(0).bit3\1,13] ;serout s_out,i38400,[" RAxis(R3): ",bin1 dualshock(0).bit2\1,13] ;serout s_out,i38400,[" LAxis(L3): ",bin1 dualshock(0).bit1\1,13] ;serout s_out,i38400,[" Select: ",bin1 dualshock(0).bit0\1,13] ;serout s_out,i38400,[" Square: ",bin1 dualshock(1).bit7\1," ",dec dualshock(13),13] ;serout s_out,i38400,[" Cross: ",bin1 dualshock(1).bit6\1," ",dec dualshock(12),13] ;serout s_out,i38400,[" Circle: ",bin1 dualshock(1).bit5\1," ",dec dualshock(11),13] ;serout s_out,i38400,[" Triangle: ",bin1 dualshock(1).bit4\1," ",dec dualshock(10),13] ;serout s_out,i38400,[" R1: ",bin1 dualshock(1).bit3\1," ",dec dualshock(15),13] ;serout s_out,i38400,[" L1: ",bin1 dualshock(1).bit2\1," ",dec dualshock(14),13] ;serout s_out,i38400,[" R2: ",bin1 dualshock(1).bit1\1," ",dec dualshock(17),13] ;serout s_out,i38400,[" L2: ",bin1 dualshock(1).bit0\1," ",dec dualshock(16),13] RXAxisCurrent = 128-dualshock(2),13 serout s_out,i38400,[" RXAxisCurrent: ",sdec RXAxisCurrent] if RXAxisCurrent <> RXAxisPrevious then RXAxisPrevious = RXAxisCurrent if RXAxisCurrent > 100 THEN serout s_out,i38400,["RXAxisCurrent > 100"] ;Hservo [P3\100] ;Hservo [P2\100] ;hservo [p0\0,p1\0,p2\0,p3\0] else ;Hservo [P3\0] ;Hservo [P2\0] ;hservo [p0\0,p1\0,p2\0,p3\0] endif endif pause 100 ;hservo [P3\0] goto main
; NOTE ShiftIn and ShiftOut commands: ; shiftin dpin,cpin,mode,[InputData1{\bits}, ..., InputDataN{\bits}] ; shiftout dpin,cpin,mode,[OutputData1{\bits}, ..., OutputDataN{\bits}]
; NOTE: FASTLSBPRE & FASTLSBPOST are the mode number for the shiftout and shiftin commands ; FASTLSBPRE = Mode 5 Faster sampling, lsb fi rst, before clock pulse ; FASTLSBPOST = Mode 7 Faster sampling, lsb fi rst, after clock pulse
ps2_motorww var byte ps2_motoryy var byte
ControlInput [ps2_motorww,ps2_motoryy] high CLK ControlInput_Retry LastButton(0) = DualShock(1) LastButton(1) = DualShock(2) low ATT shiftout CMD,CLK,FASTLSBPRE,[$1\8] shiftin DAT,CLK,FASTLSBPOST,[DS2Mode\8] high ATT pause 1
if DS2Mode <> PadMode THEN low ATT shiftout CMD,CLK,FASTLSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;enter config mode high ATT pause 1 low ATT shiftout CMD,CLK,FASTLSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8]
;set and lock analog mode high ATT pause 1 low ATT shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4D\8,$00\8,$00\8,$01\8,$FF\8,$FF\8,$FF\8,$FF\8] ;Enable Vibration motors high ATT pause 1 low ATT shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;set 18byte reply high ATT pause 1 low ATT shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;exit config mode high ATT pause 1 DualShock(1) = 255,255 goto ControlInput_Retry else low ATT shiftout CMD,CLK,FASTLSBPRE,[$1\8,$42\8, $00\8] shiftin DAT,CLK,FASTLSBPOST,[DualShock(0)\8, DualShock(1)\8] high ATT low ATT shiftout CMD,CLK,FASTLSBPRE,[$1\8,$42\8, $00\8,ps2_motorww\8,ps2_motoryy\8] shiftin DAT,CLK,FASTLSBPOST,[DualShock(2)\8, DualShock(3)\8, DualShock(4)\8, DualShock(5)\8, | DualShock(6)\8, DualShock(7)\8, DualShock(8)\8, DualShock(9)\8, | DualShock(10)\8, DualShock(11)\8, DualShock(12)\8, DualShock(13)\8, | DualShock(14)\8, DualShock(15)\8, DualShock(16)\8, DualShock(17)\8] high ATT endif
return
|