November 22, 2024, 12:40:24 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.


Pygmys and State programing for true randomness on a prop 2

Started by Eric, February 19, 2008, 09:57:43 PM

Previous topic - Next topic

Eric

Hey Jon.... Lets try this with a prop2.....

Okay, Eric, I tried and there is no way to make the pygmies act completely independently (with a single Prop-1), i.e., start shooting while the others are still popping up.  There is just not enough memory or program space. 

To get complete independence you should switch to the Prop-2; this has enough variable RAM and programming space to run a proper state machine which would allow each pygmy to be wholly independent after the sequence is initiated.


So...how would this work?


Eric

JonnyMac

Give me a couple days to hammer this out; creating what is, in effect, a multi-tasking program is not one can bang out in a few minutes while drinking coffee!  ;D

My understanding thus far:
-- all pygmies will pop, in random order, with random delay in between
    * what kind of delay between one and the next?
-- pygmies will be loaded with 1 to 3 darts each
-- a pygmy takes 3000 ms to pop up; once popped, he shoots until he's out of ammo
   * what is the dart on and off time?
-- smell output is activated after last pygmy retracts
   * what is the retraction time?
   * how long show smell output be active?



Wednesday, 6 AM, Starbucks on the desk...

-- Can I rearrange the outputs to Pygmy1, Pygmy2, Pygmy3, Dart1, Dart2, Dart3, Smellovision?
   * this will help simplify some of the coding.

Jon McPhalen
EFX-TEK Hollywood Office

Eric

My understanding thus far:
-- all pygmies will pop, in random order, with random delay in between
    * what kind of delay between one and the next?

500 to 2000 ms would be great

-- pygmies will be loaded with 1 to 3 darts each
-- a pygmy takes 3000 ms to pop up; once popped, he shoots until he's out of ammo
   * what is the dart on and off time?

The dart valve on time is around 500 ms the off time can vary what ever seems natural less mechanical

-- smell output is activated after last pygmy retracts

   * what is the retraction time?

when a Pygmy retracts he should stay down---the valve just stays off until next trigger input- but if you want to know the retraction time is actually slower that the rise time to reduce mechanical wear on the pneumatics

   * how long show smell output be active?

The smell solenoid I am guessing  will spray the scent across the ride path for 5 seconds...I have not ran the ride with the scents working so this time may vary.


Please feel free to change any outputs in any order that would make it easy

Thanks,

Eric






JonnyMac

Can the smell output start activating as soon as the final pygmy has fired his last shot, or do I have to wait for him to be hidden first?
Jon McPhalen
EFX-TEK Hollywood Office

Eric

Yes that would be fine...the smell is in the next room after bump doors as a car goes thru....guests will not hear it but the ride car will pass thru it.


Eric

JonnyMac

There's a great scene in the movie, American Beauty, when Kevin Spacey's character says: "I rule!" -- that's how I feel right this moment because I have finally conquered the pygmies.  This will take some time to absorb, so give yourself the time.  I have a few more gray hairs for having written this program.

In short:
  -- it waits for a clean trigger
  -- arbitrary 2 second delay
  -- the pygmies are loaded with darts (1 to 3) and a pop-up hold-off time (0.5 to 1.5) seconds
  -- the first pygmy is selected; his hold-off timer gets zeroed
  -- the fun begins... a big ol' state machine at Attack process the pygmies until they're out of darts and hidden
      * each runs completely independently of the others -- as if they were running on independent controllers
      * when all are are out of ammo and completely hidden the Smellovision output is activated
  -- each pygmy gets to start first within a given cycle
  -- pygmy will not repeat 1st position between cycles (i.e., when play list is cleared)

If you see me at a trade show I'd appreciate a beer; Guinness is best -- I'm Irish! (JonnyMac = Jon McPhalen)

' =========================================================================
'
'   File...... Pygmies_3x.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 22 FEB 2008
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Trigger         PIN     15                      ' SETUP = DN

Smellovision    PIN     6
Dart3           PIN     5
Dart2           PIN     4
Dart1           PIN     3
Pygmy3          PIN     2
Pygmy2          PIN     1
Pygmy1          PIN     0


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

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

IsWaiting       CON     0                       ' waiting to pop up
IsStanding      CON     1                       ' popping
IsShooting      CON     2                       ' dart on
IsBreathing     CON     3                       ' dart off
IsCrouching     CON     4                       ' retracting
IsHiding        CON     5                       ' hiding until next cycle

ShootTime       CON     200
ShootDelay      CON     75

StinkTime       CON     5000


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

lottery         VAR     Word                    ' random value
timer           VAR     Word                    ' global timer

nDarts          VAR     Byte (3)                ' number of darts
pState          VAR     Byte (3)                ' pygmy state
pTimer          VAR     Word (3)                ' state timer

idx             VAR     Byte
last            VAR     Byte                    ' last who popped 1st
playList        VAR     Byte                    ' popped 1st list

pygmy           VAR     Byte                    ' for testing


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

Reset:
  OUTL = %00000000                              ' clear all outputs
  DIRL = %01111111                              ' make P0-P5 outputs

  timer = 0                                     ' reset timer


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

Main:
  DO
    RANDOM lottery                              ' stir random value
    PAUSE 5                                     ' loop pad
    timer = timer + 5 * Trigger                 ' update timer
  LOOP UNTIL (timer >= 200)                     ' wait for 0.2 sec input
  PAUSE 2000                                    ' pre-attack delay

Pre_Load:
  FOR idx = 0 TO 2
    pState(idx) = IsWaiting                     ' initialize state
    RANDOM lottery
    nDarts(idx) = lottery // 3 + 1              ' load darts, 1 to 3
    RANDOM lottery
    pTimer(idx) = lottery // 1001 + 500         ' 0.5 to 1.5 sec delay
    pTimer(idx) = pTimer(idx) / 25 * 25         ' fix for loop timing
  NEXT

Set_First_Pygmy:
  RANDOM lottery
  idx = lottery // 3                            ' select, 0..2
  IF idx = last THEN
    GOTO Set_First_Pygmy                        ' no repeats between cycles
  ELSE
    last = idx
    IF playList.LOWBIT(idx) = 1 THEN            ' already played?
      GOTO Set_First_Pygmy                      ' yes, try again
    ELSE
      playList.LOWBIT(idx) = 1                  ' mark (has been first)
      pTimer(idx) = 0                           ' clear delay for this one
    ENDIF
  ENDIF

Attack:
  idx = 0

Check_State_Timer:
  IF (pTimer(idx) = 0) THEN                     ' timer expried?
    GOTO Update_Pygmy_State                     ' yes, new state
  ELSE                                          ' no
    pTimer(idx) = pTimer(idx) - 25              ' update timer
    GOTO Next_Pygmy
  ENDIF

  ' pygmy timer has expired
  ' -- update state, timer, and outputs as required

Update_Pygmy_State:
  IF (pState(idx) = IsWaiting) THEN
    pState(idx) = IsStanding
    pTimer(idx) = 3000                          ' set pop-up timer (3s)
    OUTL.LOWBIT(idx) = IsOn                     ' start standing
    GOTO Next_Pygmy
  ENDIF

  IF (pState(idx) = IsStanding) THEN
    pState(idx) = IsShooting
    pTimer(idx) = ShootTime                     ' set shoot timer
    OUTL.LOWBIT(idx+3) = IsOn                   ' activate dart
    GOTO Next_Pygmy
  ENDIF

  IF (pState(idx) = IsShooting) THEN
    OUTL.LOWBIT(idx+3) = IsOff                  ' dart output off
    nDarts(idx) = nDarts(idx) - 1               ' update dart count
    IF nDarts(idx) > 0 THEN                     ' ammo left?
      pState(idx) = IsBreathing                 ' yes, take a breath
      pTimer(idx) = ShootDelay
    ELSE
      OUTL.LOWBIT(idx) = IsOff                  ' pygmy output off
      pState(idx) = IsCrouching                 ' out of ammo, hide!
      pTimer(idx) = 3000
    ENDIF
    GOTO Next_Pygmy
  ENDIF

  IF (pState(idx) = IsBreathing) THEN
    OUTL.LOWBIT(idx+3) = IsOn                   ' dart output on
    pState(idx) = IsShooting
    pTimer(idx) = ShootTime
    GOTO Next_Pygmy
  ENDIF

  IF (pState(idx) = IsCrouching) THEN
    pState(idx) = IsHiding                     ' hide until next trigger
    GOTO Next_Pygmy
  ENDIF

Next_Pygmy:
  idx = idx + 1
  IF idx < 3 THEN Check_State_Timer
    PAUSE 23                                    ' pad for 25 ms loop

Attack_Complete:
  FOR pygmy = 0 TO 2
    IF (pState(pygmy) <> IsHiding) THEN         ' any still standing?
      GOTO Attack
    ENDIF
  NEXT

Stink_It_Up:
  Smellovision = IsOn
  PAUSE StinkTime
  Smellovision = IsOff

  IF (playList = %00000111) THEN                ' has each been 1st?
    playList = %000000                          ' yes, new list
  ENDIF
  GOTO Reset


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


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


' -----[ User Data ]-------------------------------------------------------


Jon McPhalen
EFX-TEK Hollywood Office