need help with programming
i'm working on project of hexapod robot, the robot only use 3 servo. the problem is,when the middle leg lift the body it wont hold
because other instruction were executed.how do i maintain the program that were already executed???
' {$STAMP BS2}
' {$PBASIC 2.5}
'===============return to normal position==================
temp VAR Word
DO
FOR temp=650 TO 750
PULSOUT 15,temp
PAUSE 1 '==============
NEXT '====='= = ======
'= =
FOR temp=550 TO 750 '= =
PULSOUT 14,temp '====='= ======
PAUSE 1 '= =
NEXT '= =
'= =
FOR temp=550 TO 750 '====='= ======
PULSOUT 13,temp '==============
PAUSE 1
NEXT
'=========================
PAUSE 3000
FOR temp=750 TO 650
PULSOUT 15,temp
PAUSE 1 '==============
NEXT ''= '= = ==
'= '= = =
FOR temp=750 TO 1000 '='= = =
PULSOUT 15,650 '====='= ======
PAUSE 1 '= =
PULSOUT 14,temp '= '= =
PAUSE 1 '= '= =
NEXT '='= ==
'============== =
FOR temp=750 TO 1000 '=
PULSOUT 15, 650
PAUSE 1
PULSOUT 13,temp
PAUSE 1
NEXT
'===========================
PAUSE 10
FOR temp=850 TO 750
PULSOUT 15,temp '==============
PAUSE 1 '====='= = ======
NEXT '= =
'= =
FOR temp=1000 TO 750 '====='= ======
PULSOUT 14,temp '= =
PAUSE 1 '= =
NEXT '= =
'====='= ======
FOR temp=1000 TO 750 '==============
PULSOUT 13,temp
PAUSE 1
NEXT
'============================
PAUSE 10
FOR temp=750 TO 850
PULSOUT 15,temp '==============
PAUSE 1 '='= = = =
NEXT '= '= = =
'= '= = =
FOR temp=750 TO 550 '====='= ======
PULSOUT 15,850 '= =
PULSOUT 14,temp '='= = =
PAUSE 1 '= '= = =
NEXT '= '= ==
'==============
FOR temp=750 TO 550
PULSOUT 15,850
PULSOUT 13,temp
PAUSE 1
NEXT
PAUSE 10
LOOP
'==================================
if somebody can help i really appreciate it...
[img]http://img252.imageshack.us/img252/3315/1001860le4.jpg<img src=[/img]
because other instruction were executed.how do i maintain the program that were already executed???
' {$STAMP BS2}
' {$PBASIC 2.5}
'===============return to normal position==================
temp VAR Word
DO
FOR temp=650 TO 750
PULSOUT 15,temp
PAUSE 1 '==============
NEXT '====='= = ======
'= =
FOR temp=550 TO 750 '= =
PULSOUT 14,temp '====='= ======
PAUSE 1 '= =
NEXT '= =
'= =
FOR temp=550 TO 750 '====='= ======
PULSOUT 13,temp '==============
PAUSE 1
NEXT
'=========================
PAUSE 3000
FOR temp=750 TO 650
PULSOUT 15,temp
PAUSE 1 '==============
NEXT ''= '= = ==
'= '= = =
FOR temp=750 TO 1000 '='= = =
PULSOUT 15,650 '====='= ======
PAUSE 1 '= =
PULSOUT 14,temp '= '= =
PAUSE 1 '= '= =
NEXT '='= ==
'============== =
FOR temp=750 TO 1000 '=
PULSOUT 15, 650
PAUSE 1
PULSOUT 13,temp
PAUSE 1
NEXT
'===========================
PAUSE 10
FOR temp=850 TO 750
PULSOUT 15,temp '==============
PAUSE 1 '====='= = ======
NEXT '= =
'= =
FOR temp=1000 TO 750 '====='= ======
PULSOUT 14,temp '= =
PAUSE 1 '= =
NEXT '= =
'====='= ======
FOR temp=1000 TO 750 '==============
PULSOUT 13,temp
PAUSE 1
NEXT
'============================
PAUSE 10
FOR temp=750 TO 850
PULSOUT 15,temp '==============
PAUSE 1 '='= = = =
NEXT '= '= = =
'= '= = =
FOR temp=750 TO 550 '====='= ======
PULSOUT 15,850 '= =
PULSOUT 14,temp '='= = =
PAUSE 1 '= '= = =
NEXT '= '= ==
'==============
FOR temp=750 TO 550
PULSOUT 15,850
PULSOUT 13,temp
PAUSE 1
NEXT
PAUSE 10
LOOP
'==================================
if somebody can help i really appreciate it...
[img]http://img252.imageshack.us/img252/3315/1001860le4.jpg<img src=[/img]
Comments
DO
FOR temp=650 TO 750
PULSOUT 15,temp
PAUSE 1
NEXT
FOR temp=550 TO 750
PULSOUT 14,temp
PAUSE 1
NEXT
FOR temp=550 TO 750
PULSOUT 13,temp
PAUSE 1
NEXT
PAUSE 3000
FOR temp=750 TO 650
PULSOUT 15,temp
NEXT
FOR temp=750 TO 1000
PULSOUT 15,650 'middle leg
PULSOUT 14,temp 'left leg
NEXT
did u mean like this
For temp = 650 to 750
PULSOUT 13, temp
PULSOUT 14, 750
PULSOUT 15, 750
PAUSE 17 '17 because you have three ~1 ms pulses and execution times.
NEXT
This will properly refresh the servos, and hold the unmoving servos in place. This would constitute one "step", or movement. It looks like your walking sequence has about 6 sequences, so you'll need to repeat this six times (or however many).
DO
=============SERVO RETURN TO NORMAL POSITION==============
FOR temp=650 TO 750
PULSOUT 15,temp
PAUSE 1
NEXT
FOR temp=550 TO 750
PULSOUT 14,temp
PAUSE 1
NEXT
FOR temp=550 TO 750
PULSOUT 13,temp
PAUSE 1
NEXT
PAUSE 3000 'HOLD FOR 3 SEC THEN MOVE
======================================
For temp = 750 to 1000
PULSOUT 13, 850 'MIDDLE SERVO LIFT BODY
PULSOUT 14, TEMP 'LEFT LEG MOVES FORWARD
PULSOUT 15, TEMP 'RIGHT LEG MOVES BACKWARD
PAUSE 17 'WILL IT BE LIKE THIS???
NEXT
LOOP
DO THE SERVO ON P13 HOLD ITS POSITION BECAUSE OF THE WEIGHT AND THE OTHER INSTRUCTION ARE RUNNING???
PULSOUT 13, 850 'MIDDLE SERVO LIFT BODY
near the end. The servo holds it's position because you are refreshing it ~20ms with a constant value. The weight has nothing to do with it, and neither do the other instructions. That's one of the double edged swords about servos: you have enough time to do other stuff between refreshes, but you can't forget about them.
You first three loops are still wrong. You have a ~2 ms refresh rate (PAUSE 1 + execution time). You need 20 ms. Also, you might as well combine the first three loops. It will get the servos to the normal position faster (they all move together, rather than wait for one to move, then the next). It's a good habit to do all your servo refresh work at the same time. (AKA, always group the PULSOUTs together unless you have a really good reason.)
FOR temp=550 TO 750
PULSOUT 14,temp
PULSOUT 13,temp
PULSOUT 15,temp
PAUSE 20
NEXT
PAUSE 3000 'HOLD FOR 3 SEC THEN MOVE
======================================
For temp = 750 to 1000
PULSOUT 13, 850 'MIDDLE SERVO LIFT BODY
PULSOUT 14, TEMP 'LEFT LEG MOVES FORWARD
PULSOUT 15, TEMP 'RIGHT LEG MOVES BACKWARD
PAUSE 20
NEXT
LOOP
it is like this??
when i try this command,the middle servo lift it leg but then return back when left leg moving, when i check the volts, at first it receive 6 volt, then when left leg moves the middle servo show 0 volts making it goes to original position,so that why i assume the weight of robot making it return after lift it.
and i see that my servo moves very slow.my servo type is Cytron C40S (180 degree type)
My guess is that either your battery pack needs a charge, or it isn't large enough for your hexapod.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When all else fails, try inserting a new battery.
the sequence like this..
midle servo move = 6v left leg 0v
left leg move=6v middle 0v
middle move again=6v left leg 0v
It sounds more likely that the legs have too much resistance in their moving, and this is "browning out" the supply.
From looking at earlier posts, it does seem that you're stopping "refresh" of one of your servo's, which means it won't "hold position".
It's better to have three variables: Servo1Pos, Servo2Pos, Servo3Pos
Then:
RefreshServo:
· PULSOUT Servo1Pin, Servo1Pos
· PULSOUT Servo2Pin, Servo2Pos
· PULSOUT Servo3Pin, Servo3Pos
· RETURN
On 'return', you have 20 milliseconds before you MUST call RefreshServo again.
Post Edited (allanlane5) : 10/30/2008 3:00:18 PM GMT
i do realize that if there is a resistance in servo movement it will draw more current.
i want the middle servo to lift the body and hold its current position while the other leg moving
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
middleright CON 850
middleleft CON 650
leftfwd CON 1000
leftback CON 550
rightfwd CON 550
rightback CON 1000
do
GOTO RefreshServo
pause 20
PULSOUT 13, rightfwd
PULSOUT 14, leftfwd
PULSOUT 15, middleleft
GOTO Refresh Servo
pause 20
loop
RefreshServo:
PULSOUT 13, rightback
PULSOUT 14, leftback
PULSOUT 15, middleright
RETURN
Servo1Pos = leftfwd
GOSUB RefreshServos
Pause 20
Also, note that you want to call the RefreshServo method with GOSUB, not GOTO. Take a look in the BS manual to see why.
how to do the variables??
servo1 VAR Word
servo2 VAR Word
servo3 VAR Word
In your refresh servos method, simply use these variables in place of a constant number or CON. Since the variables are global, there shouldn't be any visibility problems. When you want to change where a servo is, just change (for example) servo1 = 850.
servo1 VAR Word 'here is where i declare
servo2 VAR Word
servo3 VAR Word
do
pulsout servo1,750 'all the in normal position
pulsout servo2,750
pulsout servo3,750
pause 20
pulsout servo1,850 'lift left body while left leg forward,right leg backward
pulsout servo2,1000
pulsout servo3,1000
pause 20
pulsout servo1,650 'lift right body while left leg backward,right leg forward
pulsout servo2,550
pulsout servo2,550
pause 20
loop
it is like this..for simple walking only???
this is just sample of code...later i put it into subroutine...if i put RETURN command, do i still need the PAUSE 20??
PULSOUT SERVO1,750
PAUSE 20
PULSOUT SERVO2,750
PAUSE 20
or
PULSOUT SERVO1,750
PULSOUT SERVO2,750
PAUSE 20