November 23, 2024, 10:12:17 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.


Can I run servos and 24v solenoids off same Prop 1

Started by dacostasr, September 21, 2009, 07:12:22 PM

Previous topic - Next topic

dacostasr

I am using the following program to run 3 servos randomly (downloaded from Halloween forum)...I want to also run 2 solenoids for my pneumatics from the same Prop1...is this possible?  Do the PINs output 5volts while the OUTs provide 24 volts to the solenoids?

So basically this is what I want to do:

1.  PIR detects motion
2.  Servos will turn doll heads randomly (this can be constant)
3.  Solenoids random/alternately fire...bringing cabinet door in and out rattling doors

The code is just for the servo portion so far...

Thanks,

Dennis

' {$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 again! :)

JonnyMac

When you get a chance to read the Prop-1 docs (wink) you'll find that the OUTx terminals will supply what you power the board with; if you have 24v in you get 24v out.

You'll have to be more specific about what the program is supposed to do vis-a-vis timing.  Since you're running servos they have to be refreshed and this will create a time-base (20ms) for other timing.  And... how long is the whole event supposed to last?  And... after the program runs should the heads be reset to a neutral position or just left where they are?

The devil (me!) is in the details.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

September 21, 2009, 07:50:43 PM #2 Last Edit: September 21, 2009, 08:08:20 PM by JonnyMac
Here's something I whipped up from other program code that is very close -- if not right on -- to what you want.

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


' -----[ Program Description ]---------------------------------------------
'
' Trigger :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'            -- connect N.O. button between P6.W and P6.R


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Valve2          = 4
SYMBOL  Valve1          = 3
SYMBOL  Servo3          = 2
SYMBOL  Servo2          = 1
SYMBOL  Servo1          = 0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  pos1            = B0
SYMBOL  dest1           = B1
SYMBOL  pos2            = B2
SYMBOL  dest2           = B3
SYMBOL  pos3            = B4
SYMBOL  dest3           = B5

SYMBOL  temp            = B6

SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00011111                              ' set output pins

  pos1 = 150 : dest1 = 150
  pos2 = 150 : dest2 = 150
  pos3 = 150 : dest3 = 150

  timer = 0

Program_Delay:
  GOSUB Update_Servos
  timer = timer + 20
  IF timer < 30000 THEN Program_Delay


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' stir random value
  GOSUB Update_Servos                           ' refresh current positions
  timer = timer + 20 * Trigger                  ' update timer
  IF timer < 200 THEN Check_Trigger             ' wait for 0.2 sec input

  timer = 0

Prop_Loop:
  GOSUB Update_Servos
  GOSUB Update_Servos


Check1:
  RANDOM lottery                                ' stir random value
  IF pos1 <> dest1 THEN Move1                   ' at destination?
    dest1 = lottery // 101 + 100                ' create new destination
    dest1 = dest1 / 3 * 3                       ' make divisible by 3
    GOTO Check2

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

Move1_CCW:
  pos1 = pos1 - 3                               ' move position CCW

Check2:
  RANDOM lottery
  IF pos2 <> dest2 THEN Move2
    dest2 = lottery // 101 + 100
    dest2 = dest2 / 3 * 3
    GOTO Check3

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

Move2_CCW:
  pos2 = pos2 - 3

Check3:
  RANDOM lottery
  IF pos3 <> dest3 THEN Move3
    dest3 = lottery // 101 + 100
    dest3 = dest3 / 3 * 3
    GOTO Check_Timer

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

Move3_CCW:
  pos3 = pos3 - 3

Rattle_Doors:
  RANDOM lottery
  temp = lottery & %00011000                    ' get new valve outs
  PINS = PINS &/ %00011000                      ' clear old valves
  PINS = PINS | temp                            ' update

Check_Timer:
  timer = timer + 1                             ' add 40ms loop
  IF timer < 3000 THEN Prop_Loop                ' run 2 minutes?

  GOTO Reset


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

Update_Servos:
  PULSOUT Servo1, pos1
  PULSOUT Servo2, pos2
  PULSOUT Servo3, pos3
  PAUSE 15
  RETURN

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


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

dacostasr

THanks...I read that the OUTs would be the voltage in but are the PINs still 5 volt...I think I read they are but I want to avoid a servo going "poof"...lol.

I'd like to run it for 2-4 minutes - just a walk by prop.  Resetting the heads would be great.

You probably hate this time of year...HALLOWEEN!!

You are working faster than I'm typing...I just saw your next reply

Thanks again,

Dennis

JonnyMac

September 21, 2009, 08:05:59 PM #4 Last Edit: September 21, 2009, 08:10:05 PM by JonnyMac
The OUTx terminals are buffered through the ULN2803 to provide switching for the input volage.  The servo headers provide the 5v signal.

Okay, I've adjusted the code to run two minutes.  Now... to do this "timer" no longer holds milliseconds during the run loop, it holds the number of loops.  Two minutes is 120 seconds or 120,000 milliseconds.  120,000 / 40 = 3000 -- this is the test value in the end of the main loop.  The '40' comes from calling the servo update twice which creates a 40ms delay; shorter delays seemed to run the valve outputs too quickly.  The program will delay 30 seconds before running again.

See updated listing, above.

No, I don't hate this time of year -- I just don't get a lot of sleep or personal time!
Jon McPhalen
EFX-TEK Hollywood Office

dacostasr

THANKS Jon!!  ;D

I really appreciate your help.

Dennis