November 22, 2024, 05:04:47 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.


Attacking spider

Started by youngti, October 25, 2014, 05:09:09 PM

Previous topic - Next topic

youngti

October 25, 2014, 05:09:09 PM Last Edit: October 25, 2014, 05:10:48 PM by youngti
I am hoping that you guys can help me.  My attacking sider prop is just about done but the code I wrote is doing something funny.

Boards are Prop 1 and AP16+ 

Connections are;
AP16+ on pin 7, Pin clipped on ULN, set-up up
PIR on Pin 6, set-up DN
12v valve on pin 1, scissor arm
12v valve on Pin 0, spider jump

Prop 1 connected to AP16 via serial on AP16 serial 3 pin header, all AP16 switches off
Valves are connect Red wire to V+ and blacks to out0 and out1


What this prop does is has two modes, Chewing and attacking

In Chew mode it is at rest and the ap16 plays SFX01, loop mode
Then when activated jumps out and back and moves up and down repeatedly for 10 seconds, AP16 plays SFX02.

So what is happening is the second I turn on the boards the prop is immediately in attack mode.  Then it goes into chew mode and seems to operate okay from there.  Except it will not trigger just plays the chew section and then after a while plays the attack section.  I can hear the valves going (yeah I have not hooked air up to it yet, just testing)

Also I want to figure out how to modify to just have the scissor arm go out maybe 2 to 3 times, while the sider jumps much more frequently.

I have looked and looked and cant see if there is something I am dong wrong.  Hope one of you guys can see what I don't.  Thank you for your help, code below.

' =========================================================================
'
'   File...... Spider_Attack_V1.BS1
'   Purpose...
'   Author.... Tim Young
'   E-mail....
'   Started... 10-13-14
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'This prop does is has two modes, Chewing and attacking
'
'In Chew mode it is at rest and the ap16 plays SFX01, loop mode
'Then when activated jumps out and back and moves up and down repeatedly for 10 seconds, AP16 plays SFX02
'
' -----[ Revision History ]------------------------------------------------


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

SYMBOL  Sio             = 7                     ' SETUP = UP, no ULN AP16
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  arm             = PIN1                  ' sissor arm
SYMBOL  jump            = PIN0                  ' spider

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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0
SYMBOL  showrun        = 10000                 ' audio is 10s


SYMBOL  MinJump         =   100                 ' timing for sissor/spider jumps
SYMBOL  MaxJump         =   250


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

SYMBOL  timer           = W3                    ' event timer
SYMBOL  delay           = W4                    ' run delay
SYMBOL  lottery         = W5                    ' random #
SYMBOL   lottoLo        =  B10
SYMBOL   lottoHi        =  B11

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

Reset:
  PINS = %00000000                              ' clear IOs
  DIRS = %00000011                              ' define output pins

  SEROUT Sio, Baud, ("!AP16", %00, "PS", 1, 0)  ' SFX01 in loop mode

  timer = timer * 120                           ' make 0 to ~30s
  PAUSE timer

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

Main:
  timer = 0

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

SEROUT Sio, Baud, ("!AP16", %00, "PS", 2, 0)  ' SFX02 loop

sissorarm:
  RANDOM lottery                                ' re-stir
  delay = MaxJump - MinJump + 1                 ' get span
  delay = lottery // delay + MinJump            ' calc jump timing
  arm = IsOn - arm                              ' toggle cylinder


spider:
  RANDOM lottery                                ' re-stir
  delay = MaxJump - MinJump + 1                 ' get span
  delay = lottery // delay + MinJump            ' calc jump timing
  jump = IsOn - jump                            ' toggle cylinder

  PAUSE delay                                   ' hold
  timer = timer + delay                         ' update run timer
  IF timer < showrun THEN spider               ' if not done, go again
    GOTO Reset




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


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


bsnut

Tim,

Here's your modified program to try out

' =========================================================================
'
'   File...... Spider_Attack_V1.BS1
'   Purpose...
'   Author.... Tim Young
'   E-mail....
'   Started... 10-13-14
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'This prop does is has two modes, Chewing and attacking
'
'In Chew mode it is at rest and the ap16 plays SFX01, loop mode
'Then when activated jumps out and back and moves up and down repeatedly
'for 10 seconds, AP16 plays SFX02
'
' -----[ Revision History ]------------------------------------------------


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

SYMBOL  Sio             = 7                     ' SETUP = UP, no ULN AP16
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  arm             = PIN1                  ' sissor arm
SYMBOL  jump            = PIN0                  ' spider

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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0
SYMBOL  showrun        = 10000                 ' audio is 10s


SYMBOL  MinJump         =   100                 ' timing for sissor/spider jumps
SYMBOL  MaxJump         =   250


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

SYMBOL  timer           = W3                    ' event timer
SYMBOL  delay           = W4                    ' run delay
SYMBOL  lottery         = W5                    ' random #
SYMBOL  sissors         = B10


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

Reset:
  PINS = %00000000                              ' clear IOs
  DIRS = %00000011                              ' define output pins

  SEROUT Sio, Baud, ("!AP16", %00, "PS", 1, 0)  ' SFX01 in loop mode

  timer = timer * 120                           ' make 0 to ~30s
  PAUSE timer

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

Main:
  timer = 0

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  SEROUT Sio, Baud, ("!AP16", %00, "PS", 2, 0)  ' SFX02 loop

sissorarm:
  timer = 0
  FOR sissors = 0 TO 2                           ' run sissors 3 times
    RANDOM lottery                               ' re-stir
    delay = MaxJump - MinJump + 1                ' get span
    delay = lottery // delay + MinJump           ' calc jump timing
    PAUSE delay
    TOGGLE arm                                   ' toggle cylinder
  NEXT
    HIGH arm
    delay = 0

spider:
  RANDOM lottery                                ' re-stir
  delay = MaxJump - MinJump + 1                 ' get span
  delay = lottery // delay + MinJump            ' calc jump timing
  TOGGLE jump                                   ' toggle cylinder

  PAUSE delay                                   ' hold
  timer = timer + delay                         ' update run timer
  IF timer < showrun THEN spider               ' if not done, go again
    GOTO Reset




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


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

William Stefan
The Basic Stamp Nut

JonnyMac

Here's my take on it. I added a couple of variables to allow for the randomization of arm extensions and spider jumps. The timing is controlled in the jumping loop. After each jumping loop the arm toggles. Time through the run is monitored so you can control the maximum length of the run.

' =========================================================================
'
'   File...... Spider_Attack_V1.BS1
'   Purpose...
'   Author.... Tim Young
'   E-mail....
'   Started...
'   Updated... 26 OCT 2014 (JM)
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This prop does is has two modes, Chewing and attacking
'
' In Chew mode it is at rest and the ap16 plays SFX01, loop mode
'
' Then when activated jumps out and back and moves up and down repeatedly
' for 10 seconds, AP16 plays SFX02


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP, no ULN AP16
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Arm             = PIN1                  ' sissor arm
SYMBOL  Jumper          = PIN0                  ' spider


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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0
SYMBOL  ShowRun         = 10000                 ' audio is 10s

SYMBOL  MinJump         =   100                 ' timing for sissor/spider jumps
SYMBOL  MaxJump         =   250


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

SYMBOL  extends         = B2                    ' # of times to extend
SYMBOL  jumps           = B3                    ' for jumping

SYMBOL  timer           = W3                    ' event timer
SYMBOL  delay           = W4                    ' run delay
SYMBOL  lottery         = W5                    ' random #


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

Reset:
  PINS = %00000000                              ' clear IOs
  DIRS = %00000011                              ' define output pins

  SEROUT Sio, Baud, ("!AP16", %00, "PS", 1, 0)  ' SFX01 in loop mode

  RANDOM lottery
  delay = lottery // 26 + 5                     ' delay = 5 to 30
  delay = delay * 1000                          ' convert to ms
  PAUSE delay


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

Main:
  timer = 0

Check_Trigger:
  RANDOM lottery                                ' stir random #
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  SEROUT Sio, Baud, ("!AP16", %00, "PS", 2, 0)  ' SFX02 loop

  timer = 0                                     ' reset event timer

  RANDOM lottery                                ' stir random #
  extends = lottery // 3 + 2                    ' randomize extensions, 2 - 4

Scissor_Arm:
  Arm = IsOn - Arm                              ' toggle extension

  RANDOM lottery                                ' stir random #
  jumps = lottery // 6 + 5                      ' jumps = 5 to 10

Spider:
  RANDOM lottery                                ' stir random #
  delay = MaxJump - MinJump + 1                 ' calc jump delay
  delay = lottery // delay + MinJump
  Jumper = IsOn - Jumper                        ' toggle jumper
  PAUSE delay                                   ' hold
  timer = timer + delay                         ' update event time

  IF timer >= ShowRun THEN Reset                ' if done, exit

  jumps = jumps - 1                             ' update jumps
  IF jumps > 0 THEN Spider                      ' continue if not done

  extends = extends - 1                         ' update extensions
  IF extends > 0 THEN Scissor_Arm               ' continue if not done

  GOTO Reset                                    ' reset everything
Jon McPhalen
EFX-TEK Hollywood Office

youngti

Thank you Jon.  I was just able to tried it out and now it is triggering and seems to work.  My only question is how I get the attacking part to be longer.  Currently it is trigger and run for about 3 to 4 seconds then go back to the chew.  I would like it to go at least 6 or 8 seconds.  Thanks again for your help.


JackMan

October 27, 2014, 06:17:28 AM #4 Last Edit: October 27, 2014, 06:19:27 AM by JackMan
You can either increase the MinJump and MaxJump times under Constants, or increase the number of jumps in this line in the Scissor_Arm section: jumps = lottery // 6 + 5                      ' jumps = 5 to 10


For instance, jumps = lottery // 11 + 10             


This would give you 10 to 20 jumps.

JonnyMac

Overall program timing is based on the number in extends and the number in jumps. If you're happy with the jumping behavior between extension positions, then increase the range in the extends calculation -- as Jack pointed out.
Jon McPhalen
EFX-TEK Hollywood Office

youngti

As always you guys are the best.  Thanks!

JonnyMac

Here's a variation that makes it easier to control the length of show -- plus or minus a few milliseconds.

' =========================================================================
'
'   File...... Spider_Attack_V1.BS1
'   Purpose...
'   Author.... Tim Young
'   E-mail....
'   Started...
'   Updated... 27 OCT 2014 (JM)
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This prop does is has two modes, Chewing and attacking
'
' In Chew mode it is at rest and the ap16 plays SFX01, loop mode
'
' Then when activated jumps out and back and moves up and down repeatedly
' for 10 seconds, AP16 plays SFX02


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP, no ULN AP16
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Arm             = PIN1                  ' sissor arm
SYMBOL  Jumper          = PIN0                  ' spider


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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  MinJump         =   100                 ' timing for sissor/spider jumps
SYMBOL  MaxJump         =   250


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

SYMBOL  jumps           = B2                    ' for jumping

SYMBOL  showtime        = W2
SYMBOL  timer           = W3                    ' event timer
SYMBOL  delay           = W4                    ' run delay
SYMBOL  lottery         = W5                    ' random #


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

Reset:
  PINS = %00000000                              ' clear IOs
  DIRS = %00000011                              ' define output pins

  SEROUT Sio, Baud, ("!AP16", %00, "PS", 1, 0)  ' SFX01 in loop mode

  RANDOM lottery
  delay = lottery // 26 + 5                     ' delay = 5 to 30
  delay = delay * 1000                          ' convert to ms
  PAUSE delay


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

Main:
  timer = 0

Check_Trigger:
  RANDOM lottery                                ' stir random #
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  SEROUT Sio, Baud, ("!AP16", %00, "PS", 2, 0)  ' SFX02 loop

  timer = 0                                     ' reset event timer

  RANDOM lottery
  showtime = lottery // 2001 + 6000             ' 6 to 8s show timing

Scissor_Arm:
  Arm = IsOn - Arm                              ' toggle extension

  RANDOM lottery                                ' stir random #
  jumps = lottery // 6 + 5                      ' jumps = 5 to 10

Spider:
  RANDOM lottery                                ' stir random #
  delay = MaxJump - MinJump + 1                 ' calc jump delay
  delay = lottery // delay + MinJump
  Jumper = IsOn - Jumper                        ' toggle jumper
  PAUSE delay                                   ' hold
  timer = timer + delay                         ' update event time

  IF timer => showtime THEN Reset               ' show over?

  jumps = jumps - 1                             ' update jumps
  IF jumps > 0 THEN Spider                      ' continue if not done

  GOTO Scissor_Arm
Jon McPhalen
EFX-TEK Hollywood Office