November 22, 2024, 04:34:13 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.


Servo Confused

Started by chuckb0004, September 02, 2008, 02:12:37 PM

Previous topic - Next topic

chuckb0004

 I need to understand the basics on how to program a servo to move from 0 position to 90 degrees and hold that position for a specified amount of time then return to the original position. I will be using a prop 1 controller. I have read the on line manual Prop-1 Programming Basics on servo control and I'm still confused.

JonnyMac

How fast do you want it to move?  Does it snap from one position to another, or move slowly?
Jon McPhalen
EFX-TEK Hollywood Office

chuckb0004

It is going to move slowly as if looking at what it will be talking about.

JonnyMac

Here's a program that does what you want and is fairly flexible.

' =========================================================================
'
'   File...... Servo_Move.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Servo           = 0


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

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  pos             = B2                    ' position, 100 to 200
SYMBOL  tix             = B3                    ' for servo timing


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00000001                              ' make servo an output


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

Main:
  pos = 100
  tix = 50                                      ' hold one second
  GOSUB Servo_Hold

  FOR pos = 100 TO 200 STEP 1
    tix = 1                                     ' increase to slow movement
    GOSUB Servo_Hold
  NEXT

  pos = 200
  tix = 50
  GOSUB Servo_Hold

  FOR pos = 200 TO 100 STEP -1                  ' rotate back
    tix = 0                                     ' increase to slow movement
    GOSUB Servo_Hold
  NEXT

  GOTO Main


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

' Refresh servo and hold for "tix" units
' -- 1 tix = 0.02 seconds; 50 tix = 1 second

Servo_Hold:
  PULSOUT Servo, pos
  PAUSE 19
  IF tix = 0 THEN Hold_Done
    tix = tix - 1
    GOTO Servo_Hold

Hold_Done:
  RETURN


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


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


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

chuckb0004

Thanks Jon for the quick reply Ill plug this in to see how it works.  I have a couple of questions.
1. What is the baud ot2400 for?
2. What is Sio stand for?
3. The step1 and step-1 is this allways used in servo control?

JonnyMac

1. OT2400 means "Open True" communications at 2400 baud; this is what the Prop-1 uses to communicate with external devices like the AP-8, RC-4, etc.

2. Sio is just a name; to me means "Serial Input and Output"

3. You must use -1 when going backward; you can change the step size to change the speed of the loop.  Experimenting (hint, hint) will go a long way to answer your questions more clearly that what I can explain by typing.
Jon McPhalen
EFX-TEK Hollywood Office

chuckb0004

 Thanks again Jon I will begin to experiment now that I have some solid direction to start in.  Also thanks for the quick delivery of the second prop1 ,PIR and RC4 plus 4.