kurte wrote:
This is why I suggested to simplify. Get rid of the calls to Normalize. I don't currently have a pan/tilt setup, but my MechBrat (modified from James code...) does use the joystick to turn the turret and changes the angle of the hip to allow you to aim the guns, which is more or less the same idea... Taking a look at it, it looks like i need to modify it to work with the new IDES. I have edited part of it. But for one direction the code looks like:
Code:
IF (ABS(DualShock(3)-128) > TravelDeadZone) THEN
; We also only process this if the turret servo is idle
if HservoIDLE(Turret)then
TurretAngle = HservoPos(Turret) + ((Dualshock(3) - 128)*4)
IF TurretAngle > 12000 THEN
TurretAngle = 12000
ELSEIF TurretAngle < -12000
TurretAngle = -12000
ENDIF
hservo [Turret\TurretAngle\100]
endif
ENDIF
I'm back to working on this, now that my head isn't hurting. I can either get half range with stick self centering properly, OR full range and the stick does NOT center properly.
Here is the code in question:
Code:
' SET LINEARIZED JOYSTICK DISPLACEMENT BASED ON JOYSTICK CENTER POSITION
' gosub Normalize [lhori, lhori_null], lhori
' gosub Normalize [lvert, lvert_null], lvert
' gosub Normalize [rhori, rhori_null], rhori
' gosub Normalize [rvert, rvert_null], rvert
lhori_s = lhori - 127
lvert_s = lvert - 127
rhori_s = rhori - 127
rvert_s = rvert - 127
' Main processing
if Autonomous then
' Autonomous control
gosub Steering [CurrRFAngle, CurrLFAngle, CurrRRAngle, CurrLRAngle, MoveSpeed]
else
' Remote control
PanPos = (lhori_s * 100) MAX 12000 MIN -12000
TiltPos = (lvert_s * 100) MAX 12000 MIN -12000
hservo [PanServo\PanPos\MoveSpeed, TiltServo\TiltPos\MoveSpeed]
serout S_OUT,i9600,["Remote, Left Hr: ",sdec4 lhori\4,", Left Vr: ",sdec4 lvert\4,", Right Hr: ",sdec4 rhori\4,", Right Vr: ",sdec4 rvert\4,13]
serout S_OUT,i9600,["Remote, Left Hs: ",sdec4 lhori_s\4,", Left Vs: ",sdec4 lvert_s\4,", Right Hs: ",sdec4 rhori_s\4,", Right Vs: ",sdec4 rvert_s\4,", PanPos: ",sdec6 PanPos\6,", TiltPos: ",sdec6 TiltPos\6,13,13]
endif
This code gives me full stick range, but the stick doesn't self center properly when I release it.
Below is the new Normalize subroutine (not currently being called):
Code:
Value var byte
Null var byte
Normalize [Value, Null]
if Value < (Null - DeadBand) then
Value = ((127 * Value) / (Null - DeadBand)) MAX 127
elseif Value > (Null + DeadBand)
Value = ((127 * (Value - Null)) / ((255 - DeadBand - Null) + 127)) MAX 255
else
Value = 127
endif
return Value
kurte wrote:
You can reduce the number of lines of code here by using the min/max functions on the original calculation. Obviously you would need to replace variable names and the like. Ie change DualShock(3) to lhori, TravelDeadZone to DeadBand, Turret to PanServo... You may wish to play with the timing of the move, etc.
I have not worked with this yet, but am going to try it out next. I've attached my complete code, which gives me full range on the stick, but does not self center properly.
8-Dale