Thanks kenji but that's not the problem i have with the servos.
I didn't add pauses, and i always use hservowait after an hservo command.
Edit: I noticed you said don't add a step speed to the first hservo command, but that's the problem, i want a step speed in the first hservo command, because i want the servos to goto POS 0, but slower, else they snap there rather quickly, not good on a weight sensitive arm. The servos i used are junky ones, but these were free.
Code:
Hservo [p5\0\0,p6\0\0]
hservowait [p5,p6]
PAUSEUS 2000000
Hservo [p1\0\0,p312000\0]
hservowait [p1,p3]
PAUSEUS 2000000
That's in my code, above the main section, I want it to center my servos before anything else.
My problem is where you see[p5 .p6 ] is the speed sets are the problem.
if i set it to p5 100, it freaks out, but eventually returns to the right area (giving the servo hasn't overextended itself and locked up)
However if i use p5 100 later on in the code, the speed works fine.
It only has problems when the speed is 100, but outside of the main area.
I'll post my entire code.
You'll notice the servo commands near the top, if i set their speed to 100, they over extend and freakout, where as if i set the speed to 0, they move directly to their designated positions.
note: Camera = robotic arm, i just didnt bother to rename it.
Code:
enablehserial
enablehservo
SETHSERIAL H9600, H8databits, Hnoparity, h1stopbits
PAUSEUS 40000
high p7
high p10
PAUSEUS 400000
LOW p11 ;motor controller reset on pin 13
PAUSEUS 400000
HIGH p11
PAUSEUS 600000 ;motor controller startup time
Hservo [p5\0\0,p6\0\0]
hservowait [p5,p6]
PAUSEUS 2000000
Hservo [p1\0\0,p312000\0]
hservowait [p1,p3]
PAUSEUS 2000000
main
cbot var word
cbot2 var word
drive1 var sword
drive2 var sword
drive3 var sword
drive4 var sword
change var bit
hserin 8000000, main,[dec4 cbot,sdec4 cbot2]
hserout [dec cbot,",",sdec drive1,",",sdec drive2,",",sdec drive3,",",sdec drive4," "]
if (cbot = 1000) then
SEROUT p10, i9600, [$80, 0, 0, 0]
SEROUT p10, i9600, [$80, 0, 2, 0]
elseif (cbot >= 1001 and cbot <= 1100)
goto movement
elseif (cbot >= 2000 and cbot <= 2100)
goto camera
endif
goto main
movement
if (cbot = 1001) then ;forward full speed
SEROUT p10, i9600, [$80, 0, 0, 127]
serout p10, i9600, [$80, 0, 2, 127]
PAUSEUS 200000
elseif (cbot = 1002) ;backwards full speed
SEROUT p10, i9600, [$80, 0, 1, 127]
serout p10, i9600, [$80, 0, 3, 127]
PAUSEUS 200000
elseif (cbot = 1003) ;rotate left, right track forward, left track reverse at reduced speed
SEROUT p10, i9600, [$80, 0, 2, 90]
SEROUT p10, i9600, [$80, 0, 1, 90]
PAUSEUS 200000
elseif (cbot = 1004) ;Rotate right opposite of above
SEROUT p10, i9600, [$80, 0, 3, 90]
SEROUT p10, i9600, [$80, 0, 0, 90]
PAUSEUS 200000
elseif (cbot = 1005) ;forward Slow
SEROUT p10, i9600, [$80, 0, 0, 55]
serout p10, i9600, [$80, 0, 2, 55]
PAUSEUS 200000
elseif (cbot = 1006) ;backwards slow
SEROUT p10, i9600, [$80, 0, 1, 55]
serout p10, i9600, [$80, 0, 3, 55]
PAUSEUS 200000
elseif (cbot = 1007) ;rotate left slow
SEROUT p10, i9600, [$80, 0, 2, 30]
SEROUT p10, i9600, [$80, 0, 1, 30]
PAUSEUS 200000
elseif (cbot = 1008) ;Rotate right slow
SEROUT p10, i9600, [$80, 0, 3, 30]
SEROUT p10, i9600, [$80, 0, 0, 30]
PAUSEUS 200000
endif
goto main
camera
if (cbot = 2000 and change = 0) then ;Resets Servos
drive1 = 0
drive2 = 0
drive3 = 0
drive4 = 12000
change = 1
goto pantilt
elseif (cbot = 2001 and drive1 < 12250 and change = 0) ;Rotate
drive1 = drive1 + 250
change = 1
goto pantilt
elseif (cbot = 2002 and drive1 > -12750 and change = 0)
drive1 = drive1 - 250
change = 1
goto pantilt
elseif (cbot = 2003 and drive2 < 13500 and change = 0) ;first arm
drive2 = drive2 + 250
change = 1
goto pantilt
elseif (cbot = 2004 and drive2 > -8000 and change = 0)
drive2 = drive2 - 250
change = 1
goto pantilt
elseif (cbot = 2005 and drive3 < 3000 and change = 0) ;Grabber
drive3 = drive3 + 250
change = 1
goto pantilt
elseif (cbot = 2006 and drive3 > -6000 and change = 0)
drive3 = drive3 - 250
change = 1
goto pantilt
elseif (cbot = 2007 and drive4 < 12500 and change = 0) ;Second arm
drive4 = drive4 + 250
change = 1
goto pantilt
elseif (cbot = 2008 and drive4 > -13000 and change = 0)
drive4 = drive4 - 250
change = 1
goto pantilt
endif
goto main
pantilt
if change = 1 then
hservo [p5drive1100,p6drive2100]
hservo [p1drive3100,p3drive4100]
hservowait [p1,p3,p5,p6]
change = 0
goto main
endif
goto main