November 27, 2024, 02:41:21 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.


Program for AP-8 and Prop-1

Started by dbauer1080, October 24, 2007, 09:41:44 AM

Previous topic - Next topic

dbauer1080

Jon,

I am using my new Prop-1, RC-4, and AP-8 for a moving head sequence. PIR will trigger Prop-1 that controls AP-8 and RC-4
Could you possibly whip up(hopefully this process is very quick for you) a program to do the following?

Here is the sequence:

PIR triggers Prop-1
AP-8 starts immediately with one 30 second sound segment
After 5 seconds, Prop-1 turns on AC strobe light for 25 seconds
Also after 5 seconds servo is activated to move back and forth through full range(standard servo) continuously for 25 seconds,   which will move the head
Then PIR is inactive for 2 minutes.

If any connection quirks please let me know. Thanks so much.

JonnyMac

This one isn't trivial and I'm going to be out of the office quite a bit today -- I'll have it to you no later than tomorrow.  Be sure you record your audio into slot zero of the AP-8, and then open all the selection switches (like selecting slot 7) before connecting to the Prop-1.  The RC-4 will be connected to the Prop-1 first, then the AP-8 to it.
Jon McPhalen
EFX-TEK Hollywood Office

dbauer1080

Thanks Jon, I'll do what you stated.

JonnyMac

Here's your program -- as I stated earlier: not trivial.  Why?, you wonder.  Because servos have to be refreshed every 20 milliseconds, that means you cannot have a PAUSE statement in the program greater than 20 or you risk the servo losing its position.  This forces one into a "state machine" design.

' =========================================================================
'
'   File....... DBauer1080.BS1
'   Purpose....
'   Author..... Jon Williams, EFX-TEK
'   Started....
'   Updated.... 24 OCT 2006
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

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


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400                ' remove B/R jumper


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

SYMBOL  relays          = B0                    ' RC-4 outputs
SYMBOL   Strobe         =  BIT0
SYMBOL   K2             =  BIT1
SYMBOL   K3             =  BIT2
SYMBOL   K4             =  BIT3

SYMBOL  moveDivider     = B1                    ' to control servo speed
SYMBOL   div2           =  BIT8
SYMBOL   div4           =  BIT9
SYMBOL   div8           =  BIT10
SYMBOL   div16          =  BIT11

SYMBOL  state           = B2                    ' program state
SYMBOL  pirCount        = B3                    ' for PIR debouncing
SYMBOL  pos             = B4                    ' head servo position
SYMBOL  dest            = B5                    ' head servo destination
SYMBOL  timer           = W4                    ' stage/event timing
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000
  DIRS = %00000001

  SEROUT Sio, Baud, ("!!!!!!AP8", %00, "X", "!RC4", %00, "X")

  pos = 150                                     ' force servo to center
  dest = 150

  timer = 6000                                  ' two-miniute PIR delay
  state = 0


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

Main:
  RANDOM lottery
  PAUSE 15                                      ' tuned for 20 ms loop

  BRANCH state, (Hold, Check, Audio_On, Str_Wait, Str_On, Str_Hold)


' hold program for 'pirDelay'

Hold:                                           ' inter-event delay
  timer = timer - 1                             ' update timer
  IF timer > 0 THEN Refresh_Servo               ' skip if not expired
    state = 1                                   '   else, update state
    pirCount = 0                                '   clear debounce timer
    GOTO Refresh_Servo


' debounce PIR

Check:
  pirCount = pirCount + 1 * PIR                 ' update/clear PIR count
  IF pirCount < 10 THEN Refresh_Servo           ' skip until valid signal
    state = 2                                   '   else, next state
    GOTO Refresh_Servo


' start AP-8; reset timer for 5 seconds

Audio_On:
  SEROUT Sio, Baud, ("!AP8", %00, "P", 0)
  state = 3                                     ' point to next state
  timer = 250                                   ' 250 x 20 ms = 5 sec
  GOTO Refresh_Servo


' hold 5 seconds for strobe

Str_Wait:
  timer = timer - 1                             ' update timer
  IF timer > 0 THEN Refresh_Servo               ' hold servo until expired
    state = 4                                   ' point to next state
    GOTO Refresh_Servo


' activate strobe and set strobe timer for 25 seconds

Str_On:
  Strobe = IsOn
  GOSUB Set_RC4
  state = 5
  timer = 1250                                  '  1250 x 20 ms = 25 sec
  GOTO Move_Servo


' hold strobe on and randomly move servo

Str_Hold:
  timer = timer - 1                             ' update  timer
  IF timer > 0 THEN Move_Servo                  ' move servo until expired
    GOTO Reset                                  ' else start over


' =========================
' Servo Movement Processing
' =========================

Move_Servo:
  moveDivider = moveDivider + 1                 ' update move divider
  IF div4 = 0 THEN Refresh_Servo                ' time for position update?
    moveDivider = 0                             ' yes, reset divider

  IF pos <> dest THEN Update_pos                ' at destination?
    dest = lottery // 151 + 75                  ' yes, reset (75 to 225)

Update_pos:
  IF pos < dest THEN Go_CW1                     ' check direction
  pos = pos - 2                                 ' Move servo CCW

Go_CW1:
  pos = pos + 1                                 ' Move servo CW


' ===============
' Update Servo(s)
' ===============

Refresh_Servo:
  PULSOUT Servo, pos                            ' Move the servo

  GOTO Main                                     ' Start again


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

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN
Jon McPhalen
EFX-TEK Hollywood Office

dbauer1080

Jon, you're awesome. I'm going to give it a try tonight. Thanks so much

Jadams

Quote from: JonnyMac on October 24, 2007, 04:23:54 PM
Here's your program -- as I stated earlier: not trivial.  Why?, you wonder.  Because servos have to be refreshed every 20 milliseconds, that means you cannot have a PAUSE statement in the program greater than 20 or you risk the servo losing its position.  This forces one into a "state machine" design.

' =========================================================================
'
'   File....... DBauer1080.BS1
'   Purpose....
'   Author..... Jon Williams, EFX-TEK
'   Started....
'   Updated.... 24 OCT 2006
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

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


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400                ' remove B/R jumper


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

SYMBOL  relays          = B0                    ' RC-4 outputs
SYMBOL   Strobe         =  BIT0
SYMBOL   K2             =  BIT1
SYMBOL   K3             =  BIT2
SYMBOL   K4             =  BIT3

SYMBOL  moveDivider     = B1                    ' to control servo speed
SYMBOL   div2           =  BIT8
SYMBOL   div4           =  BIT9
SYMBOL   div8           =  BIT10
SYMBOL   div16          =  BIT11

SYMBOL  state           = B2                    ' program state
SYMBOL  pirCount        = B3                    ' for PIR debouncing
SYMBOL  pos             = B4                    ' head servo position
SYMBOL  dest            = B5                    ' head servo destination
SYMBOL  timer           = W4                    ' stage/event timing
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000
  DIRS = %00000001

  SEROUT Sio, Baud, ("!!!!!!AP8", %00, "X", "!RC4", %00, "X")

  pos = 150                                     ' force servo to center
  dest = 150

  timer = 6000                                  ' two-miniute PIR delay
  state = 0


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

Main:
  RANDOM lottery
  PAUSE 15                                      ' tuned for 20 ms loop

  BRANCH state, (Hold, Check, Audio_On, Str_Wait, Str_On, Str_Hold)


' hold program for 'pirDelay'

Hold:                                           ' inter-event delay
  timer = timer - 1                             ' update timer
  IF timer > 0 THEN Refresh_Servo               ' skip if not expired
    state = 1                                   '   else, update state
    pirCount = 0                                '   clear debounce timer
    GOTO Refresh_Servo


' debounce PIR

Check:
  pirCount = pirCount + 1 * PIR                 ' update/clear PIR count
  IF pirCount < 10 THEN Refresh_Servo           ' skip until valid signal
    state = 2                                   '   else, next state
    GOTO Refresh_Servo


' start AP-8; reset timer for 5 seconds

Audio_On:
  SEROUT Sio, Baud, ("!AP8", %00, "P", 0)
  state = 3                                     ' point to next state
  timer = 250                                   ' 250 x 20 ms = 5 sec
  GOTO Refresh_Servo


' hold 5 seconds for strobe

Str_Wait:
  timer = timer - 1                             ' update timer
  IF timer > 0 THEN Refresh_Servo               ' hold servo until expired
    state = 4                                   ' point to next state
    GOTO Refresh_Servo


' activate strobe and set strobe timer for 25 seconds

Str_On:
  Strobe = IsOn
  GOSUB Set_RC4
  state = 5
  timer = 1250                                  '  1250 x 20 ms = 25 sec
  GOTO Move_Servo


' hold strobe on and randomly move servo

Str_Hold:
  timer = timer - 1                             ' update  timer
  IF timer > 0 THEN Move_Servo                  ' move servo until expired
    GOTO Reset                                  ' else start over


' =========================
' Servo Movement Processing
' =========================

Move_Servo:
  moveDivider = moveDivider + 1                 ' update move divider
  IF div4 = 0 THEN Refresh_Servo                ' time for position update?
    moveDivider = 0                             ' yes, reset divider

  IF pos <> dest THEN Update_pos                ' at destination?
    dest = lottery // 151 + 75                  ' yes, reset (75 to 225)

Update_pos:
  IF pos < dest THEN Go_CW1                     ' check direction
  pos = pos - 2                                 ' Move servo CCW

Go_CW1:
  pos = pos + 1                                 ' Move servo CW


' ===============
' Update Servo(s)
' ===============

Refresh_Servo:
  PULSOUT Servo, pos                            ' Move the servo

  GOTO Main                                     ' Start again


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

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

Jim Adams

Jadams

Jon,

I'm learning a lot by going through some of these past post.  In this program, I'm confused as to how both the AP-8 and RC-4 are on address %00.  I think I have it right, AP-8 in plugged into the RC-4, RC-4 into the Prop-1 P6.  Also what is logic for the 2 minute delay after the program runs?


Thanks,

The kids are in for a surprise this Halloween,

J Adams
Jim Adams

livinlowe

Jadams-
Both the ap-8 and rc-4 are on address %00 because dbauer1080 only had one of each in his set up. If, for example, he had two RC-4's the first would be %00 and the second would be %01. This way you can have 4 of each board in any one setup.

As to the 2 minute wait, I imagine it was so the trick or treaters could have time to leave? I'm not sure. A PIR needs time to settle when you first activate it, but you would only need to do that once.

Hope this helps
Shawn
Scaring someone with a prop you built -- priceless!

Jadams

It does help.  Thank you.  I think I have it now.

Jadams
Jim Adams