November 21, 2024, 05:38:43 PM

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.


Newbee with Servo trouble

Started by Shmedley, June 17, 2007, 10:04:43 AM

Previous topic - Next topic

Shmedley

I am new to the world of Servos and Basic stamp stuff (enough to be dangerous).  I am just trying to get a servo to move so I can validate basic working knowledge and understanding.  I don't have a problem with BS1 making lights go on and on/off function but I can't seem to create a basic script that moves a servo back and forth (again just playing/testing).  I cheated by downloading a working random movement scripts to see the servos move and study the script to understand how the programing works.  With this program, the servos randomly move but has very choppy slow movement.  So I guess I have two questions.  Can you share a basic script that moves a servo to a position (I can build from there) and any ideas why the servos are choppy with a known working script?

Any assistance is greatly appreciated....

ED

JonnyMac

June 17, 2007, 01:09:41 PM #1 Last Edit: June 17, 2007, 01:13:18 PM by JonnyMac
Here's the quick skinny on servos: they want a high-going pulse of 1.0 to 2.0 milliseconds every 20 milliseconds or so (if a standard servo is not refreshed appropriately it can loose its position, especially if under load; only [expensive] digital servos are "set and forget").  With the Prop-1 you will use LOW to preset the servo output pin(s) so that subsequent commands, issued with PULSOUT have the proper polarity.  PULSOUT on the Prop-1 has a resolution of 10 microseconds; 1.0 milliseconds is 1000 microseconds so a 1.0 millisecond pulse with PULSOUT is 100 units.

This little demo should help get you started -- it simply wags a servo back and forth.  You can speed up the movement by bumping the position loop STEP size, or slow it down by creating an inner loop to refresh the current position multiple times.

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


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


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


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

SYMBOL  Servo           = 0


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


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

SYMBOL  pos             = B2


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

Reset:
  LOW Servo                                     ' make pin output


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

Main:
  DEBUG "Servo to...", CR
  FOR pos = 100 TO 200
    PULSOUT Servo, pos                          ' move servo
    PAUSE 18                                    ' update delay
  NEXT

  DEBUG "Servo fro...", CR
  FOR pos = 200 TO 100 STEP -1
    PULSOUT Servo, pos                          ' move servo
    PAUSE 18                                    ' update delay
  NEXT

  GOTO Main


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


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


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


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


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


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


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

JonnyMac

I guess I didn't address the choppiness issue.  Servos move at their own speed.  If you tell the servo to move through a series of positions and the delay between positions is slower than the servo can move on its own it will stop at each position, giving a choppy appearance.  There's no getting around this -- you have to do a lot of fine-tuning to  smooth things out, and that's not easy in any programming language, hence popularity of PC-driven servo control (VSA, Vixen, etc.).
Jon McPhalen
EFX-TEK Hollywood Office