October 31, 2024, 08:23:07 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.


8 random servos

Started by gadget-evilusions, February 17, 2008, 10:01:10 PM

Previous topic - Next topic

gadget-evilusions

I have a new project. I need to build a prop that will use 8 servos (what, me mr pneumatic using servos, i know, it's weird). When triggered, I need the 8 servos to randomly operate for a specified time (probably 10 seconds, might change later). The movement of the servos would be simulating birds or other small animals devouring a human.

Is 8 servos too much to ask for on a prop-2?

I do not have any experience programming servos, but i am sure this is a tall order. Any help is of course helpful, please steer me in the right direction.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

February 17, 2008, 11:25:21 PM #1 Last Edit: February 17, 2008, 11:33:48 PM by JonnyMac
If you use byte values for the servo position and target position then you can do it -- give this a try (it compiles, but I am unable to test as I'm away from home without a Prop-2).

' =========================================================================
'
'   File...... Random_Servos8.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'              (elements based on work by Vern Graner)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Trigger         PIN     15

Servo8          PIN     7
Servo7          PIN     6
Servo6          PIN     5
Servo5          PIN     4
Servo4          PIN     3
Servo3          PIN     2
Servo2          PIN     1
Servo1          PIN     0


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

Center          CON     150


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

lottery         VAR     Word                    ' random value
timer           VAR     Word

pos             VAR     Byte ( 8 )              ' present position
target          VAR     Byte ( 8 )              ' target position
idx             VAR     Byte                    ' loop counter


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

Reset:
  DIRL = %11111111                              ' make servos outputs

  FOR idx = 0 TO 7                              ' center servos
    pos(idx) = Center
    target(idx) = Center
  NEXT

  timer = 0                                     ' clear trigger timer


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

Main:
  RANDOM lottery                                ' stir random value
  GOSUB Refresh_Servos
  timer = timer + 20 * Trigger                  ' update trigger timer
  IF timer < 250 THEN Main                      ' wait for valid trigger

  timer = 0                                     ' reset for movement

Eat_The_Flesh:
  FOR idx = 0 TO 7                              ' loop though servo pins
    RANDOM lottery
    IF pos(idx) = target(idx) THEN              ' at target?
      target(idx) = lottery // 101 + 100        ' yes, set new target
    ELSE                                        ' no, update position
      IF pos(idx) < target(idx) THEN
        pos(idx) = pos(idx) + 1
      ELSE
        pos(idx) = pos(idx) - 1
      ENDIF
    ENDIF
  NEXT
  GOSUB Refresh_Servos
  timer = timer + 20
  IF timer < 10000 THEN Eat_The_Flesh

  GOTO Reset


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

' Refresh time between 16 and 24 milliseconds
' -- assume 20 ms average

Refresh_Servos:
  FOR idx = 0 TO 7
    PULSOUT idx, pos(idx) * 5
  NEXT
  PAUSE 8
  RETURN

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

gadget-evilusions

Thank you sir, I had better order a prop-2 to be able to test it.

That is the best name i have ever seen in a program, Eat_The_Flesh:
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Program labels can be anything up to 32 characters -- why not have fun with them?!
Jon McPhalen
EFX-TEK Hollywood Office