November 17, 2024, 08:31:59 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


faster servo

Started by lester, July 16, 2008, 08:33:39 PM

Previous topic - Next topic

lester

 I am intagrading the prop 1 in to my pieces.  Not having time to program the board I just got one off of the forum.  just random six servo.  But the servos move so slow. It seems in the forum I read about people saying they where to fast and to have it pause each step.  Who do I contact to have a program devoloped that will fit my needs. Generaly I only use two or three servos but might as well hav six channels set up.  maybe about twice as fast, I know the servos can handel it cuz when you power it up they move fast to zero then go into a slow routine.  Even if it is commanded to go to four or five set positions then loop is fine as long as its faster. 
                Thanks Troy

JonnyMac

Troy,

Can you post the code you're using so I don't have to go hunting -- there are a few random servo programs about.  Servos can only move so fast; the way we slow them down is to hold them at intermediate positions; we just have to adjust that part of the code.
Jon McPhalen
EFX-TEK Hollywood Office

lester

I think this is it.

' {$STAMP BS1}
' {$PBASIC 1.0}

'------------------------------------------------------
' HEX Servo Random Movement Generator
' By Vern Graner April 29th, 2005
' Any questions to vern@graner.com
' R-04.29f
'------------------------------------------------------
' -First attempt for Prop-1 controller
'------------------------------------------------------
' Hardware setup:
' Servos connected to pins 0-5


'Declare Variables
'------------------------------------------------------
SYMBOL RESULT = W0 ' value can be 0 to 65535
SYMBOL  DEST1 = B2 ' value can be 0 to 255
SYMBOL   CUR1 = B3 ' value can be 0 to 255
SYMBOL  DEST2 = B4 ' value can be 0 to 255
SYMBOL   CUR2 = B5 ' value can be 0 to 255
SYMBOL  DEST3 = B6 ' value can be 0 to 255
SYMBOL   CUR3 = B7 ' value can be 0 to 255
SYMBOL  DEST4 = B8 ' value can be 0 to 255
SYMBOL   CUR4 = B9 ' value can be 0 to 255
SYMBOL  DEST5 = B10 ' value can be 0 to 255
SYMBOL   CUR5 = B11 ' value can be 0 to 255
SYMBOL  DEST6 = B12 ' value can be 0 to 255
SYMBOL   CUR6 = B13 ' value can be 0 to 255


'Pre set values in variables
'------------------------------------------------------
RESULT  = 11010     ' set initial "seed" value
'CUR1    = 50        ' Set all current and destination values to match
'DEST1   = 50        ' to force the cur=dest routines to generate a random
'CUR2    = 50        ' destination for all servos on first pass
'DEST2   = 50
'CUR3    = 50
'DEST3   = 50
'CUR4    = 50
'DEST4   = 50
'CUR5    = 50
'DEST5   = 50
'CUR6    = 50
'DEST6   = 50
'------------------------------------------------------

'Main loop begin
LOOP:

IF CUR1=DEST1 THEN FetchNewDest1   'If the servo has reached it's destination fetch a new one
  GOTO NextTest1                   ' if not, skip to next test
FetchNewDest1:
  RANDOM RESULT                    'Use RANDOM to find a new destination
  RESULT=RESULT // 200             'Cut it down to a usable size
  DEST1=RESULT                     'Stuff the new destination into DEST variable
  DEST1=DEST1 MIN 50               'Set limits so servos do not exceed positional
  DEST1=DEST1 MAX 200              ' requiremenmts
'  DEBUG "Cur1=",#CUR1," Dest1=",#DEST1,CR
NextTest1:

IF CUR2=DEST2 THEN FetchNewDest2
  GOTO NextTest2:
FetchNewDest2:
  RANDOM RESULT
  RESULT=RESULT // 200
  DEST2=RESULT
  DEST2=DEST2 MIN 50
  DEST2=DEST2 MAX 200
'  DEBUG "Cur2=",#CUR2," Dest2=",#DEST2,CR
NextTest2:

IF CUR3=DEST3 THEN FetchNewDest3
  GOTO NextTest3
FetchNewDest3:
  RANDOM RESULT
  RESULT=RESULT // 200
  DEST3=RESULT
  DEST3=DEST3 MIN 50
  DEST3=DEST3 MAX 200
'  DEBUG "Cur3=",#CUR3," Dest3=",#DEST3,CR
NextTest3:

IF CUR4=DEST4 THEN FetchNewDest4
  GOTO NextTest4
FetchNewDest4:
  RANDOM RESULT
  RESULT=RESULT // 200
  DEST4=RESULT
  DEST4=DEST4 MIN 50
  DEST4=DEST4 MAX 200
'  DEBUG "Cur4=",#CUR4," Dest4=",#DEST4,CR
NextTest4:

IF CUR5=DEST5 THEN FetchNewDest5
  GOTO NextTest5
FetchNewDest5:
  RANDOM RESULT
  RESULT=RESULT // 200
  DEST5=RESULT
  DEST5=DEST5 MIN 50
  DEST5=DEST5 MAX 200
'  DEBUG "Cur4=",#CUR4," Dest4=",#DEST4,CR
NextTest5:

IF CUR6=DEST6 THEN FetchNewDest6
  GOTO NextTest6
FetchNewDest6:
  RANDOM RESULT
  RESULT=RESULT // 200
  DEST6=RESULT
  DEST6=DEST6 MIN 50
  DEST6=DEST6 MAX 200
'  DEBUG "Cur4=",#CUR4," Dest4=",#DEST4,CR
NextTest6:


IF CUR1<DEST1 THEN PlusCur1        'Check to see if CUR is less than DEST
CUR1=CUR1-1                        'If NOT the decrement CUR
GOTO TestDone1                     'Jump out of the test
PlusCur1:
CUR1=CUR1+1                        'If SO then increment CUR
TestDone1:

IF CUR2<DEST2 THEN PlusCur2
CUR2=CUR2-1
GOTO TestDone2
PlusCur2:
CUR2=CUR2+1
TestDone2:

IF CUR3<DEST3 THEN PlusCur3
CUR3=CUR3-1
GOTO TestDone3
PlusCur3:
CUR3=CUR3+1
TestDone3:

IF CUR4<DEST4 THEN PlusCur4
CUR4=CUR4-1
GOTO TestDone4
PlusCur4:
CUR4=CUR4+1
TestDone4:

IF CUR5<DEST5 THEN PlusCur5
CUR5=CUR5-1
GOTO TestDone5
PlusCur5:
CUR5=CUR5+1
TestDone5:

IF CUR6<DEST6 THEN PlusCur6
CUR6=CUR6-1
GOTO TestDone6
PlusCur6:
CUR6=CUR6+1
TestDone6:


'DEBUG CLS
'DEBUG "CUR1=",#CUR1," DEST1=",#DEST1,CR
'DEBUG "CUR2=",#CUR2," DEST2=",#DEST2,CR
'DEBUG "CUR1=",#CUR1," CUR2=",#CUR2,"CUR3=",#CUR3," CUR4=",#CUR4,CR

PULSOUT 0,CUR1  'send a pulse to the servo on P0 (eyes)
PULSOUT 1,CUR2  'send a pulse to the servo on P1 (head tilt)
PULSOUT 2,CUR3  'send a pulse to the servo on P2 (head pan)
PULSOUT 3,CUR4  'send a pulse to the servo on P3 (wrist)
PULSOUT 4,CUR5  'send a pulse to the servo on P4 (elbow)
PULSOUT 5,CUR6  'send a pulse to the servo on P5 (thumb)

PAUSE 20        'Use a value of 20 for slow servo motion, comment out for fastest motion
GOTO LOOP       'lets do it agai

JonnyMac

Give this version a try.  Note that it looks different from Vern's program (on which it's based) because I'm using some sneaky programming tricks to minimize code space.

' =========================================================================
'
'   File....... Random_6_Servos.BS1
'   Purpose....
'   Author..... Jon Williams -- EFX-TEK
'               (based on work by Vern Graner)
'   E-mail..... jwilliams@efx-tek.com
'   Started....
'   Updated.... 17 JUL 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Servo6          = 5                     ' servo pins
SYMBOL  Servo5          = 4
SYMBOL  Servo4          = 3
SYMBOL  Servo3          = 2
SYMBOL  Servo2          = 1
SYMBOL  Servo1          = 0


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


' -----[ Variables ]-------------------------------------------------------

SYMBOL  lottery         = W0                    ' random seed/value

SYMBOL  S1Data          = W1
SYMBOL   pos1           =  B2                   ' current1 position
SYMBOL   dest1          =  B3                   ' target1 position

SYMBOL  S2Data          = W2
SYMBOL   pos2           =  B4
SYMBOL   dest2          =  B5

SYMBOL  S3Data          = W3
SYMBOL   pos3           =  B6
SYMBOL   dest3          =  B7

SYMBOL  S4Data          = W4
SYMBOL   pos4           =  B8
SYMBOL   dest4          =  B9

SYMBOL  S5Data          = W5
SYMBOL   pos5           =  B10
SYMBOL   dest5          =  B11

SYMBOL  S6Data          = W6
SYMBOL   pos6           =  B12
SYMBOL   dest6          =  B13


' -----[ EEPROM Data ]-----------------------------------------------------


' -----[ Initialization ]--------------------------------------------------

Reset:
  DIRS = %00111111                              ' make servos outputs

  lottery = 1031                                ' seed RANDOM

  S1Data = $9696                                ' set to center
  S2Data = $9696
  S3Data = $9696
  S4Data = $9696
  S5Data = $9696
  S6Data = $9696


' -----[ Program Code ]----------------------------------------------------

Main:
  PULSOUT Servo1, pos1                          ' update servos
  PULSOUT Servo2, pos2
  PULSOUT Servo3, pos3
  PULSOUT Servo4, pos4
  PULSOUT Servo5, pos5
  PULSOUT Servo6, pos6
  PAUSE 10


' --( Servo 1 )--------------------------------
'
Check1:
  IF pos1 <> dest1 THEN Move1                   ' at destination?

New_Dest1:
  RANDOM lottery                                ' stir random value
  dest1 = lottery // 141 + 80 & %11111110       ' new position, 80 to 220
  GOTO Check2

Move1:
  IF pos1 > dest1 THEN Move1_CCW
    pos1 = pos1 + 4                             ' move position CW

Move1_CCW:
  pos1 = pos1 - 2                               ' move position CCW


' --( Servo 2 )--------------------------------
'
Check2:
  IF pos2 <> dest2 THEN Move2

New_Dest2:
  RANDOM lottery
  dest2 = lottery // 141 + 80 & %11111110
  GOTO Check3

Move2:
  IF pos2 > dest2 THEN Move2_CCW
    pos2 = pos2 + 4

Move2_CCW:
  pos2 = pos2 - 2


' --( Servo 3 )--------------------------------
'
Check3:
  IF pos3 <> dest3 THEN Move3

New_Dest3:
  RANDOM lottery
  dest3 = lottery // 141 + 80 & %11111110
  GOTO Check4

Move3:
  IF pos3 > dest3 THEN Move3_CCW
    pos3 = pos3 + 4

Move3_CCW:
  pos3 = pos3 - 2


' --( Servo 4 )--------------------------------
'
Check4:
  IF pos4 <> dest4 THEN Move4

New_Dest4:
  RANDOM lottery
  dest4 = lottery // 141 + 80 & %11111110
  GOTO Check5

Move4:
  IF pos4 > dest4 THEN Move4_CCW
    pos4 = pos4 + 4

Move4_CCW:
  pos4 = pos4 - 2


' --( Servo 5 )--------------------------------
'
Check5:
  IF pos5 <> dest5 THEN Move5

New_Dest5:
  RANDOM lottery
  dest5 = lottery // 141 + 80 & %11111110
  GOTO Check6

Move5:
  IF pos5 > dest5 THEN Move5_CCW
    pos5 = pos5 + 4

Move5_CCW:
  pos5 = pos5 - 2


' --( Servo 6 )--------------------------------
'
Check6:
  IF pos6 <> dest6 THEN Move6

New_Dest6:
  RANDOM lottery
  dest6 = lottery // 141 + 80 & %11111110
  GOTO Main

Move6:
  IF pos6 > dest6 THEN Move6_CCW
    pos6 = pos6 + 4

Move6_CCW:
  pos6 = pos6 - 2
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office