November 23, 2024, 10:35:25 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Servo program HELP

Started by imagineerdan, December 16, 2011, 04:32:48 PM

Previous topic - Next topic

imagineerdan

I created the below program to shutter a small projector and need the servo to move faster. in the below code is there any way I can make the servo swing left to right with more speed? thanks!

' {$STAMP BS1}
SYMBOL temp = W0


start:


IF PIN6 = 1 THEN Back2:
IF PIN7 = 1 THEN forward:
IF PIN7 = 0 THEN Back:


GOTO start:


                                   'Put louver up to shutter projector
Forward:
FOR temp = 200 TO 100
PULSOUT 0,temp
PAUSE 1
NEXT


GOTO start:


Back:                             'Retract louver to allow projection to be visable
FOR temp = 100 TO 200 STEP - 1
PULSOUT 0,temp
PAUSE 1
NEXT


GOTO start:



Back2:                             'Put louver up to shutter projector
FOR temp = 200 TO 100
PULSOUT 0,temp
PAUSE 1
NEXT

GOTO wait:


wait:                              'leave louver up and wait for screen to return home  for 1 second +
PAUSE 1050
GOTO start:






JackMan

December 16, 2011, 08:16:03 PM #1 Last Edit: December 16, 2011, 08:20:56 PM by JackMan
Increase the STEP value in your FOR lines. Start with a step value of 2 and try it, increase it until you get the speed you want. You have your (-) STEP value in the wrong line. When the start value is smaller than the end value you don't use the (-). A (-) step value is used when the start value is larger than the end value. You should also change your PAUSE to 19.

Example:

FOR temp = 100 TO 200 STEP  4

FOR temp = 200 TO 100 STEP -4


JonnyMac

December 17, 2011, 01:19:13 PM #2 Last Edit: December 17, 2011, 01:20:57 PM by JonnyMac
The easiest way to get more speed out of your servo is to go directly to the desired position.  If that's too fast then do as Jack suggests and use a STEP value with your move loops.

As ever, I remind everyone that servos must be refreshed every 20ms if you want them to work reliably.  With that, here's a commercial grade version of your program.  It debounces the inputs (while refreshing the servo) and moves the servo according to your button logic.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Btn2            = 7
SYMBOL  Btn1            = 6

SYMBOL  Servo           = 0


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

SYMBOL  FWD             = 200                   ' servo output valus
SYMBOL  BACK            = 100


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

SYMBOL  btns            = B2
SYMBOL  idx             = B3
SYMBOL  pos             = B4
SYMBOL  last            = B5


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

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00000001                              ' P0 is output

  GOTO Back1                                    ' preset servo
  last = %00


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

Main:
  btns = %11000000                              ' arm both buttons
  FOR idx = 1 TO 5
    PULSOUT Servo, pos                          ' refresh servo
    PAUSE 19
    btns = btns & PINS                          ' scan inputs
  NEXT

  btns = btns / 64                              ' shift bits right

  IF btns = last THEN Main                      ' no change
    last = btns                                 '  save change

  BRANCH btns, (Back1, Back2, Forward)          ' handle button

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

Forward:
  pos = FWD
  PULSOUT Servo, pos
  PAUSE 18
  GOTO Main


' -------------------------------------------------------------------------

Back1:
  pos = BACK
  PULSOUT Servo, pos
  PAUSE 19
  GOTO Main

' -------------------------------------------------------------------------

Back2:
  pos = BACK
  FOR idx = 1 TO 55                             ' ~1.1s delay
    PULSOUT Servo, pos
    PAUSE 19
  NEXT
  GOTO Main

' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office