Never had a Tank before. But it sounded like an interesting way to spend the evening.
It might do it all. Or it might blow a loogie. 
Code:
DeadBandX CON 10 ; center mechanical Dead Area
DeadBandY CON 5
JoyX VAR BYTE ; A/D values from joystick
JoyY VAR BYTE
TrimX VAR BYTE
TrimY VAR BYTE
Xcorr VAR WORD ; corrected values (x-128)
Ycorr VAR WORD ; puts center at 0,0
Left VAR WORD ; Left Tread
Right VAR WORD ; Right Tread
LeftDir VAR BIT ; Tread directions 1 = backwards
RightDir VAR BIT
Main:
ADCIN 0, JoyX ; get Joystick values
ADCIN 1, JoyY
ADCIN 2, TrimX ; Joystick Center trims
ADCIN 3, TrimY ; set to 128 if not used
Xcorr = JoyX - 128 + (TrimX >> 3) - 16 ; adjust center position to 0
Ycorr = JoyY - 128 + (TrimY >> 3) - 16
IF ABS(Xcorr) < DeadBandX THEN Xcorr = 0 ; center deadband
IF ABS(Ycorr) < DeadBandY THEN Ycorr = 0
Left = Ycorr + Xcorr ; Mix Tread speeds
Right = Ycorr - Xcorr
LeftDir = Left.15 ; Tread Direction
RightDir = Right.15 ; 1 = backwards
Left = ABS(Left) ; make values positive
Right = ABS(Right)
if Left > 127 then Left = 127 ; Clamp max outputs
if Right > 127 then Right = 127
; Drive motors here
; LeftDir indicates the direction of the Left tread
; Left is the Speed of the motor 0 - 127
; Same for Right Track
GOTO Main
Bookmarks