November 22, 2024, 10:22:01 PM

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.


Servo RC4 PIR Scary terry combo all thru Prop1

Started by chuckb0004, September 03, 2008, 02:28:04 PM

Previous topic - Next topic

chuckb0004

I'm using a Prop1, RC4, PIR trigger, a Scary Terry board and a picoboo.  The scary terry will control 1 servo mounted in a Bucky skull that will be driven by an audio track from a picoboo unit from last Halloween. The picoboo will play ambient audio until it is triggered by the prop1. The prop 1 will be triggered by a PIR.  The scare audio is a narration that will require lighting effects and movement of the skull (i.e. head turns). The lighting will be controlled by the RC4 board and the head turns by a servo controlled by the prop1.  All will need to be orchestrated by the prop1. HELP!!! I have just started this adventure into micro controllers in the past I have used electro mechanical relays and agastat timing relays to create my props. I know nothing about servos and very little about electronics I am howerver eager to learn and will read anything and everthing I need to.

JonnyMac

Okay, this is not a beginner's program, but after some study you should be able to put it to use.  Since you have an RC-4 we're kind of forced to use the time needed for its update.  This means our unit of timing is 33 milliseconds; this should be okay for servo updating.

' =========================================================================
'
'   File...... Servo_RC-4.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 03 SEP 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Starts an external audio player and then controls the simultaneous
' movement of a servo and the output channels of an RC-4  Servo movement
' and RC-4 outputs are stored in a EEPROM table with a "repeats" value
' for timing at the positions specified in the record (last byte).  The
' timing is approximately:
'
' 33 milliseconds x (repeats + 1)
'
' Mimimum: ~0.033 seconds
' Maximum: ~8.448 seconds
'
' Note that servos are mechanical and move slowly, so very small "repeats"
' values may expire before the servos reaches their target positions.


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  AudioStart      = 5                     ' use OUT5 terminal
SYMBOL  Servo           = 0                     ' use P0 header


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  RecLen          = 3                     ' record length
SYMBOL  EOS             = 255                   ' End Of Show indicator

SYMBOL  Baud            = OT2400


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

SYMBOL  timer           = B2                    ' debounce timer
SYMBOL  record          = B3                    ' movement record
SYMBOL  pntr            = B4                    ' table byte pointer
SYMBOL  svoPos          = B5                    ' servo position
SYMBOL  relays          = B6                    ' RC-4 outputs
SYMBOL  repeats         = B7                    ' repeats for record data


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

Reset:
  PINS = %00000000                              ' clear local outputs
  DIRS = %00100001                              ' set output pins

  record = 0
  GOSUB Get_Record                              ' get "home" positions


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

Main:
  timer = 0

Check_Trigger:
  GOSUB Refresh_Outputs                         ' update servo & RC-4
  timer = timer + 33 * Trigger
  IF timer < 200 THEN Check_Trigger

Start_Audio:
  PULSOUT AudioStart, 2500                      ' 25 ms blip on audio pin

Reset_Moves:
  record = 1                                    ' point to start of moves

Move_Engine:
  GOSUB Get_Record                              ' get servo & RC-4 bits
  IF svoPos = EOS THEN Reset                    ' abort if at end

Servo_Hold:
  GOSUB Refresh_Outputs
  IF repeats = 0 THEN New_Record                ' time left at this pos?
    repeats = repeats - 1                       ' yes, decrement timing
    GOTO Servo_Hold

New_Record:
  record = record + 1
  GOTO Move_Engine


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

' Call with "record" set to table line to read

Get_Record:
  pntr = record * RecLen                        ' point into table
  READ pntr, svoPos                              ' read servo 1 value
  pntr = pntr + 1                               ' point to servo 2
  READ pntr, relays                              ' read servo 2 value
  pntr = pntr + 1                               ' point to repeats
  READ pntr, repeats                            ' read repeats
  RETURN

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

' Update outputs -- time consumed is about 33 milliseconds

Refresh_Outputs:
  PULSOUT Servo, svoPos                         ' refresh servo position
  SEROUT  Sio, Baud, ("!RC4", %00, "S", relays) ' update RC-4 outputs
  PAUSE 2                                       ' pad for loop timing
  RETURN


' -----[ EEPROM Data ]-----------------------------------------------------

' Note on servo movement record timing:
'
' Time spent on each record is 33 ms x (repeats + 1) so a repeats value
' of 0 is ~33 ms and a repeats value of 255 (max) is ~8.4 sseconds at that
' position.
'
'         svo   RC-4  rpts
'
Home_Position:
  EEPROM (150, %0000, 255)                      ' home position

Move_Table:
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)
  EEPROM (150, %0000, 255)                      ' last available record

  EEPROM (EOS, %0000, 255)                      ' end of show
Jon McPhalen
EFX-TEK Hollywood Office

chuckb0004

Jon I want to thank you for the program. I studied it piece by piece until I understood how all the parts worked together. I then added some VM code to it and manipulated the eeprom table.  I just put the entire scene together and after working a couple of bugs out it is working better than I could have imagined. Thanks again for all your help and now onto my first pneumatic prop using a Prop1 controller.

JonnyMac

I rule!   ;D

Well done you for taking the time to study the program, make updates, and then debug your updates -- this is the only real way to learn.  We may have watched out parents walk but at some point we had to let go of their hands and trek across the living room on wobbly legs.  You're ready to run, man.
Jon McPhalen
EFX-TEK Hollywood Office