Help programming servos, pls
Archiver
Posts: 46,084
Hi all
Thanks to those (esp. Duncan!) who have attempted to help this PBasic newbie
on getting my 5 servos running off a single BS1. Here's what I have as
working 'units' but haven't the foggiest idea how to put them into a one
loop. Any suggestions welcome!
Here's a general idea of what I need to do listed by servo motor:
1. Motor1 - just slowly rotates
motor1:
pulsout 1, 151 'slowly rotates
pause 20
goto motor1
2. Motor2 - makes a quick movement every 15 seconds or so, jerking an object
on a cord.
Symbol loop2 = w2
jerk:
for b2 = 170 to 190
pulsout 2, b2
pause 20
next
for loop2 = 1 to 1000
pulsout 2, 150
pause 20
next
goto jerk
3. Motors 3, 4 and 5 all spool cord through pulleys lifting and lowering
objects slowly with pauses at both extremes. The distances traveled are
different for each motor and I would like to have different "pauses" for
each motor. This code works for one motor...
Motor3:
SYMBOL loops = w3
FOR loops = 1 to 4000
pulsout 1, 149 'slowly turning
pause 20
NEXT
FOR loops = 1 to 2000
pulsout 1, 150 'stopped
pause 20
NEXT
FOR loops = 4000 to 1 STEP -1
pulsout 1, 155 'faster return
pause 20
NEXT
FOR loops = 1 to 2000
pulsout 1, 150 'stopped
pause 20
NEXT
goto motor3
Thanks,
John
////////
'''''''' John Phillips / sound artist: http://terragizmo.net
Thanks to those (esp. Duncan!) who have attempted to help this PBasic newbie
on getting my 5 servos running off a single BS1. Here's what I have as
working 'units' but haven't the foggiest idea how to put them into a one
loop. Any suggestions welcome!
Here's a general idea of what I need to do listed by servo motor:
1. Motor1 - just slowly rotates
motor1:
pulsout 1, 151 'slowly rotates
pause 20
goto motor1
2. Motor2 - makes a quick movement every 15 seconds or so, jerking an object
on a cord.
Symbol loop2 = w2
jerk:
for b2 = 170 to 190
pulsout 2, b2
pause 20
next
for loop2 = 1 to 1000
pulsout 2, 150
pause 20
next
goto jerk
3. Motors 3, 4 and 5 all spool cord through pulleys lifting and lowering
objects slowly with pauses at both extremes. The distances traveled are
different for each motor and I would like to have different "pauses" for
each motor. This code works for one motor...
Motor3:
SYMBOL loops = w3
FOR loops = 1 to 4000
pulsout 1, 149 'slowly turning
pause 20
NEXT
FOR loops = 1 to 2000
pulsout 1, 150 'stopped
pause 20
NEXT
FOR loops = 4000 to 1 STEP -1
pulsout 1, 155 'faster return
pause 20
NEXT
FOR loops = 1 to 2000
pulsout 1, 150 'stopped
pause 20
NEXT
goto motor3
Thanks,
John
////////
'''''''' John Phillips / sound artist: http://terragizmo.net
Comments
something like this:
(this is off the top of my head, so you may need to jiggle it a bit).
' phase is a word variable
phase=0
phase1=0
toploop:
phase=phase+1
phase1=phase1+1
pulsout 1,151 ' every time
if phase1>=20 then m2k
pulsout 2,phase1+169 ' 170 to 190
goto m2n
m2k:
pulsout 2, 150
if phase1<>1020 then m2n
phase1=0
m2n:
if phase>4000 then m3b
pulsout 1,149
goto nxtloop
m3b: ' you mean pulseout 3 here right?
if phase>6000 then m3c
pulsout 3,150
goto nxtloop
m3c:
if phase>10000 then m3d
pulsout 3,155
goto nxtloop
m3d:
if phase>12000 then m3z
pulsout 3,150
goto nxtloop
m3z:
phase=0
nxtloop:
pause 20 ' might be <20 to compensate for the extra execution time of
other instructions
goto toploop
You'd have to add code for the other two motors in a similar way. If you
want the pause to be different, you'd have to use the smallest pause and
recode the others in terms of that puase. For example, you might set 10mS
and do most of the above only on every other phase count.
Of course, the pulses will not be synchronized because each one has to
finish before the next one can start.
Regards,
Al Williams
AWC
* 8 simultaneous pulse outputs: http://www.al-williams.com/awce/pak8.htm
P.S. Speaking of which, setting up this kind of thing with a PAK-VIII should
be simple. You can specify the on and off time (and an optional count) and
let it go. This would solve a lot of problems very easily. You can use the
PAKs with a Stamp I even though it doesn't have SHIFTIN and SHIFTOUT -- you
just have to simulate the shifts (examples are in the manuals).