November 22, 2024, 07:01:10 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.


need a program written

Started by lester, September 19, 2008, 06:59:41 PM

Previous topic - Next topic

lester

All right the animatronics I am producing are fairly basic.  Not what you would see in theme parks more like the ones in store fronts. Some movements will be controlled via separate controllers.  What I would like to control with the prop 1 or 2 is as follows.

4 Random servo movements.  The code below Is the one I'm using now"you changed it for me so servos would move faster"I realize I may have to use external  power for servos.  Let me know if you think this is necessary.

This would be
Head A
Head B
eyes A
eyes B

And three solenoids 24v

eye lids- 20 seconds off 2 seconds on -cycle tell loop
ear A- 30 seconds off  1 sec on 1 sec off 1 sec on
ear B- 25 sec off 2 sec on 1 sec off 2 sec on (optional if its a hassle don't worry with this one)

I need it to auto start and loop over and over.

Also since I'm here I've been checking out the Eurgle High Torque  servos  4.8V DC ~6.0V DC Should I use an external power supply if I'm only running two of them.   

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


' =========================================================================
'
'   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 ]-----------------------------------------------------

Thanks Troy

JonnyMac

September 19, 2008, 07:03:09 PM #1 Last Edit: September 19, 2008, 07:06:38 PM by JonnyMac
I think you may need a Prop-2 and a state-machine design, but let me look see if I can squeeze it into a Prop-1 (don't hold your breath, though....).  Let me look into it.

[Edit] Okay, that didn't take long; you're going to need a Prop-2 -- not for connections, but for variable space.  And what do you want to call this prop?
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Here you go -- though it has no name so I won't save it on my hard drive (in future, please give me a name to use when requesting custom code).

Yes, use external power for servos.

This program uses some advanced PBASIC2 tricks and may take a little time to understand.  One important note -- this line:

  timer(idx) = timer(idx) + 33

The 33 is not arbitrary.  Ideally, that would have been 20 but all the code of the program takes time to run.  I determined through testing with a stopwatch that the loop takes 33 milliseconds, so don't change this number.  Let me know how this works out for you.

' =========================================================================
'
'   File......
'   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... 19 SEP 2008
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Lids            PIN     6                       ' OUT6

EarB            PIN     5                       ' OUT5
EyesB           PIN     4                       ' P4 - servo
HeadB           PIN     3                       ' P3 - servo

EarA            PIN     2                       ' OUT2
EyesA           PIN     1                       ' P1 - servo
HeadA           PIN     0                       ' P0 - servo


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

IsOn            CON     1
IsOff           CON     0


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

lottery         VAR     Word                    ' random value
idx             VAR     Byte                    ' loop, control index

pos             VAR     Byte(4)                 ' present position
target          VAR     Byte(4)                 ' destination
timer           VAR     Word(3)                 ' for ears and lids


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

Reset:
  OUTS = $0000
  DIRS = $007F                                  ' P0-P6 are outputs

  FOR idx = 0 TO 3                              ' center servos
    pos(idx) = 150
    target(idx) = 150
  NEXT

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

Main:
  PULSOUT HeadA, pos(0) * 5                     ' refresh servos
  PULSOUT EyesA, pos(1) * 5
  PULSOUT HeadB, pos(2) * 5
  PULSOUT EyesB, pos(3) * 5

  FOR idx = 0 TO 2
    timer(idx) = timer(idx) + 33                ' update timers
  NEXT


Move_Servos:
  FOR idx = 0 TO 3                              ' loop though servo pins
    RANDOM lottery
    IF pos(idx) = target(idx) THEN              ' at target?
      target(idx) = lottery // 141 + 80         ' yes, set new target
      target(idx) = target(idx) & %11111110     ' make even (divisible by 2)
    ELSE                                        ' no, update position
      IF pos(idx) < target(idx) THEN
        pos(idx) = pos(idx) + 2
      ELSE
        pos(idx) = pos(idx) - 2
      ENDIF
    ENDIF
  NEXT


Update_Ear_A:
  idx = 99
  LOOKDOWN timer(0), >=[33000, 32000, 31000, 30000], idx
  IF (idx <> 99) THEN
    LOOKUP idx, [IsOff, IsOn, IsOff, IsOn], EarA
    IF (idx = 0) THEN
      timer(0) = 0
    ENDIF
  ENDIF


Update_Ear_B:
  idx = 99
  LOOKDOWN timer(1), >=[30000, 28000, 27000, 25000], idx
  IF (idx <> 99) THEN
    LOOKUP idx, [IsOff, IsOn, IsOff, IsOn], EarB
    IF (idx = 0) THEN
      timer(1) = 0
    ENDIF
  ENDIF


Update_Lids:
  idx = 99
  LOOKDOWN timer(2), >=[22000, 20000], idx
  IF (idx <> 99) THEN
    LOOKUP idx, [IsOff, IsOn], Lids
    IF (idx = 0) THEN
      timer(2) = 0
    ENDIF
  ENDIF


  GOTO Main


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


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


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

lester

Sorry I meant to put it in prop 2 just clicked the wrong link I guess.  But I gotta say you guys are great.  I didn't expect this tell at least Monday.  I'm sure It will work well.  And now I will simply build the next character to fit the controller,  I know it sounds backwards but I've made these a long time and already know the approach I'll take. Just looking for a controller to fit my needs and I think you guys have it.   Now with the prop 2 do I have more room or is it basically full.  I may want to add more solenoids in the future and can probably just add on to this base program.  I would assume if I run external power to the servos I can run eight solenoids if there not on at the same time.  This is over kill I would never use that many but an example.   Thanks again Troy Oh and I gotta name it right.

JonnyMac

There's plenty of code space and plenty of connections.  That said, this is a very tricky program because it is basically a servo controller plus three independent threads running the other things.  I know that the listing looks easy, and it was for me, but I have 14 years of BASIC Stamp programming and 28 years of programming in total so I know lots of tricks. 

This is not a trivial program.  Advanced animatronics requires advanced programming skills and this program is pushing the practical limits of this kind of animatronic control on the Prop-2 because the servo processing takes a lot of bandwidth.  I would be more inclined to go with a Prop-SX for this kind of application but that is another level of sophistication altogether.

Sometimes it's harder than it looks, and if you want to control these kinds of characters with low-cost controllers like ours you're going to need to spend some time learning to program.  Of course, we're always here to help.
Jon McPhalen
EFX-TEK Hollywood Office

lester

Yes I know, now i can keep generating income as I learn to program.  what would you recommend as the best programing info,  for pbasic.

JonnyMac

Parallax has a TON of information on the BS2.  My favorite, of course, is StampWorks (written by me).  None of the Parallax information is related to prop building per se, but it does cover programming.  All joking aside, StampWorks takes a more professional approach (i.e., the right way, not always the easy way) so I do recommend that.
Jon McPhalen
EFX-TEK Hollywood Office