November 23, 2024, 04:04:06 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Pushing the limits of the prop-1 with Beast program

Started by BigRez, October 05, 2009, 05:14:11 PM

Previous topic - Next topic

BigRez

Hi all -

Been fiddling with a program for a couple of days and cannot get it to fit.  I'm either running out of space or hitting too many GOSUBs.  Really want to run this from a prop-1 though so thought I'd ask for help with the program here.

Here's what I've got:
' Power Source: 12vdc, 5A  (5A needed for pump only)
' Devices: Prop-1, RC-4, uMP3
' ===========================================================
' prop1.PIN7 = Serial IO to RC-4       | No ULN; Address %00
' prop1.PIN6 = PIR                     |
' prop1.PIN5 = uMP3 Tx                 | No ULN
' prop1.PIN4 = uMP3 Rx  (may not need) | No ULN
' prop1.3 =                            |
' prop1.OUT2 = Pump                    | OUT2/V+;  using high-current add-on
' prop1.OUT1 = Bump                    | OUT1/V+; single-action, spring return
' prop1.OUT0 = Lid                     | OUT0/V+; single action, spring return
' -------------------------------------+
' rc4.00.1 = Fog                       |
' rc4.00.2 = Light                     |
' rc4.00.3 = Doors                     | double-acting cylinder
' rc4.00.4 = Beast                     | double-acting cylinder


So here's what I would like to have happen, but could settle for something less robust:

1) Trigger wakes beast
   a) Start sound file 1.mp3 (5 seconds duration); do not wait for completion
   b) Lid and Bump begin random slow firing for approx 3 seconds
      (Slow firing means a delay of .4 to .8 seconds between firing)

2) At next trigger, but at least (approx) 5 seconds
   a) Start sound file 2.mp3 (8 seconds duration) but do not wait for completion
   b) Burst the fog machine for 3 seconds
   c) Lid and Bump begin random medium firing for approx 5 seconds
      (Medium firing means a delay of .3 to .5 seconds between firing)
   d) Start sound file 3.mp3 (4 seconds) - no wait for completion

3) At next trigger, but at least (approx) 5 seconds
   a) Start sound file 4.mp3 (14 seconds duration) - do not wait for completion
   b) Turn on light
   c) fire fog for 3 seconds
   d) Lid and Bump begin random fast firing for approx 7 seconds
      (Medium firing means a delay of approx .2 to .3 seconds between firing)
   e) pause for 3 seconds
   f) start sound 5.mp3
   g) Open doors
   h) pause 500ms (will be adjusted)
   i) activate beast
   j) sleep 5 seconds
   k) decativate beast
   l) sleep 1 second
   m) start sound 6.mp3
   n) close doors
   o) sleep for 5 minutes and go back to 1

There seems to be some repetition in the three areas that could be used to save some program space.  Again the above is what I'd like to do to simulate wakening, disturbing, and then angering the beast, but I can cut some out if needed to make it fit.

Any help/suggestions on the above would be greatly appreciated.

Thanks!

mike   

JonnyMac

What are you using as a trigger?  A button?  It seems like to get through the whole show you will have to press the button 3 times.  Am I missing something, Mike?  If not, you have to construct this as a state-machine.   I'll start working on something in that direction in case I am right about my assumption.
Jon McPhalen
EFX-TEK Hollywood Office

BigRez

Sorry - forgot to include that in the heading...  It's a Parallax PIR.  The thought being someone enters the area which wakes the beast.  If they remain after the first actions, he gets angry and the secodn portion acts. Finally if they aren't scared away and trigger the PIR again, he attacks.

If not too much, I'd also like to say if there was 30 seconds delay (or so) between the first and second trigger that it would just repeat the first event (and again same condition betwen second and third).

Thanks in advance!

JonnyMac

October 05, 2009, 05:56:27 PM #3 Last Edit: October 05, 2009, 06:01:20 PM by JonnyMac
It doesn't matter what the trigger is now, you've got five pounds of groceries that you're trying to put into a three-pound bag -- there's just not enough code space to do what you want to do.  I tried....

You know, those Prop-2s we carry are pretty snazzy!
Jon McPhalen
EFX-TEK Hollywood Office

BigRez

I did pick up a prop-2 earlier in the year but have other plans for it.

So, what if I were to put back about 2lb. of groceries?  I'd need to know how much each weighs, but I'm thinking the multiple trigger part is one of them.  So, I was already thinking about the following:

1) Trigger wakes beast
   a) Start sound file 1.mp3 (5 seconds duration); do not wait for completion
   b) Lid and Bump begin random slow firing for approx 3 seconds
      (Slow firing means a delay of .4 to .8 seconds between firing)
   c) sleep for 2 seconds
   d) Start sound file 2.mp3 (8 seconds duration) but do not wait for completion
   e) Burst the fog machine for 3 seconds
   f) Lid and Bump begin random medium firing for approx 5 seconds
      (Medium firing means a delay of .3 to .5 seconds between firing)
   g) Start sound file 3.mp3 (4 seconds) - wait for completion
   h) Start sound file 4.mp3 (14 seconds duration) - do not wait for completion
   i) Turn on light and fog for 3 seconds
   j) Lid and Bump begin random fast firing for approx 7 seconds
      (Medium firing means a delay of approx .2 to .3 seconds between firing)
   e) pause for 4 seconds
   f) start sound 5.mp3
   g) Open doors
   h) pause 500ms (will be adjusted)
   i) activate beast
   j) sleep 5 seconds
   k) decativate beast
   l) sleep 1 second
   m) start sound 6.mp3
   n) close doors
   o) sleep for 5 minutes and go back to 1

Would that trim enough?  I'll give the programming an attempt, but if you have some time to give it a try or suggest other areas to cut/make more efficient, that'd be appreciated.

Thanks!

JonnyMac

Sorry, Mike, you're still trying to enter a VW in the Indy 500 -- just not enough car for the race.  Here's what I have, maybe it will inspire some ideas (like ordering another Prop-2!).

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Sio     :: Serial IO to EFX-TEK accessories (RC-4, FC-4, etc.)
'            -- clip pin 1 of ULN2803 or replace with ULN2003
'
' Trigger :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'            -- connect N.O. button between P6.W and P6.R


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


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

SYMBOL  Sio             = 7                     ' for DC-16, RC-4; no ULN
SYMBOL  Trigger         = PIN6                  ' setup = DN
SYMBOL  TX              = 5                     ' to UMP3.R; no ULN
SYMBOL  RX              = 4                     ' to UMP3.T; no ULN

SYMBOL  Pump            = PIN2
SYMBOL  Bump            = PIN1
SYMBOL  Lid             = PIN0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsOpen          = 1
SYMBOL  IsClosed        = 0

SYMBOL  EfxBaud         = OT2400                ' B/R jumper removed
SYMBOL  Mp3Baud         = T2400                 ' do not us OT!

SYMBOL  FogOn           = %0001
SYMBOL  LighOn          = %0010



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

SYMBOL  relays          = B0
SYMBOL   Fog            =  BIT0
SYMBOL   Light          =  BIT1
SYMBOL   Doors          =  BIT2
SYMBOL   Beast          =  BIT3

SYMBOL  char            = B1
SYMBOL  mp3             = B2
SYMBOL  temp            = B3

SYMBOL  dlyMin          = B4
SYMBOL  dlyMax          = B5

SYMBOL  delay           = W3
SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Power_Up:
  PAUSE 2500                                    ' let uMP3 start

Reset:
  SEROUT TX, OT2400, ("PC S", 13)               ' stop if playing
  GOSUB Set_RC4

  PINS = %00000000                              ' preset IOs
  DIRS = %00000111                              ' set output pins (1s)


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

Main:
  timer = 0                                     ' reset timer

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

  mp3 = 1
  GOSUB Play_MP3                                ' (a)
  timer = 0
  dlyMin = 4                                    ' 0.4
  dlyMax = 8                                    ' 0.8
  timer = 3000                                  ' 3 seconds
  GOSUB Bumps                                   ' (b)

  PAUSE 2000                                    ' (c)

  mp3 = 2
  GOSUB Play_MP3                                ' (d)
  Fog = IsOn                                    ' (e)
  GOSUB Set_RC4
  PAUSE 3000
  Fog = IsOff
  GOSUB Set_RC4

  dlyMin = 3                                    ' 0.3
  dlyMax = 5                                    ' 0.5
  timer = 4000                                  ' 5 seconds
  GOSUB Bumps                                   ' (f)

  mp3 = 3
  GOSUB Play_MP3                                ' (g)
  PAUSE 4000                                    ' adjust as required

  mp3 = 4
  GOSUB Play_MP3                                ' (h)

  relays = %0011                                ' (i) fog + light
  GOSUB Set_RC4
  PAUSE 3000
  relays = IsOff
  GOSUB Set_RC4

  dlyMin = 2                                    ' 0.3
  dlyMax = 3                                    ' 0.5
  timer = 7000                                  ' 5 seconds
  GOSUB Bumps                                   ' (j)

  PAUSE 4000

  mp3 = 5
  GOSUB Play_MP3

  Doors = IsOpen
  GOSUB Set_RC4
  PAUSE 500






  FOR timer = 1 TO 5
    PAUSE 60000
  NEXT

  GOTO Reset


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

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

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

' Put file # to play in "mp3"
' -- files on uMP3 are named "0.MP3" to "255.MP3"

Play_MP3:
  SEROUT TX, Mp3Baud, ("PC F /", #mp3, ".MP3", 13)
  RETURN

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

' set min time (0.1s units) in dlyMin
' set max time (0.1s units) in dlyMax
' set bump timing in timer (ms)

Bumps:
  timer = 0

Bump_Again:
  RANDOM lottery
  temp = lottery & %00000011                    ' isolate lower bits
  PINS = PINS &/ %00000011 | temp               ' update P0 and P1
  delay = dlyMax - dlyMin * 100 + 1
  delay = lottery // delay
  delay = delay + dlyMin
  PAUSE delay
  IF timer < delay THEN Bump_Exit
    timer = timer - delay
    GOTO Bump_Again

Bump_Exit:
  PINS = PINS &/ %00000011                      ' clear P0 and P1
  RETURN


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

BigRez

That actually has been a great help.  Thanks Jon!

I've taken the above and heavily modified it to include the majority within a FOR loop with a couple of added IF statements.  I think this will work and allow me to get closer to the original requirement.  At least everything is there and I still have 30 bytes of program space.  I'll do some more tweaking and then post the final code if I get it right.

BigRez

October 06, 2009, 11:47:03 PM #7 Last Edit: October 06, 2009, 11:49:28 PM by bigrez
OK, had some time to rework the program (attached) and I think it's working fairly well.  I cannot hook it up to the prop yet as the uMP3 isn't config'd (c'mon Parallax - ship that thing!), but I've run some of the code through the trainer and it looks OK.  

I do think the following section can be made to perform better.  I'm looking for a reaistic lid pop and bounce where either or both can fire at a time with a variable delay between firing.  Also, this routine is called from the mail loop three different times. Each time, the intensity and duration is increased. They're both single-acting cylinders so I'm not sure what the minimum amount of time should be to open them but don't want them opened too long as to look mechanical.

Any suggestions on making this portion, or any other part of it for that matter, perform better?


' =========================================================================
' Using a JonnyMac trick for the dual valves; lottoHi and lottoLo determine
' if the valve should open or not. We'll shake the box for TIMER ms.
' We don't bump on the first time through (MAXBUMPS)
' -------------------------------------------------------------------------
Shake_Em_Up:
  RANDOM lottery
  delay = lottery // 81 + delayMin               ' calc time to keep valve open
  Lid = lottoHi                                       ' open Lid valve
  IF event = MAXLOOPS THEN No_Bump
     Bump =  lottoLo                             ' open bump valve if not on first iteration

No_Bump:
  PAUSE delay                                         ' leave 'em open a short while
  PINS = PINS &/ %00000011                       ' clear P0 and P1

  PAUSE delayMin
  delay = delay + delayMin                          ' calcualte delayed time
  IF timer < delay THEN Shake_Exit               ' determine if we've done this enough
     timer = timer - delay
     GOTO Shake_Em_Up                              ' if not, go do some more shakin'

Shake_Exit:
  RETURN

Tim-M


Bigrez,

Quote: (c'mon Parallax - ship that thing!)

Am I reading this right... Does your quote imply that Parallax is working on an audio player product?

Tim

JonnyMac

@Tim: I think Mike is waiting on a USB2SER so that he can configure the uMP3.  Rogue has developed new firmware that will eliminate the need to do serial configuration; you'll be able to do it via a text file on the SD card.

@Mike: If it works, fantastic.  I don't know that I could "improve" it; you clearly know what you're doing.  In the comments you ask why I called the Set_RC4 routine in the reset section.  The reason for this is that a power-up/reset of the Prop-1 does not affect the RC-4, so if that happens in the middle of a cycle you'd want to reset the RC-4 as well.  You could, of course, use the "X" command to do that, or just call the subroutine will all outputs cleared.

Suggestion: You have a very large FOR-NEXT loop; my opinion is that more than 7 or 8 lines inside any loop structure is too many, it becomes easy to lose track of the structure.  You have this....

  FOR event = MAXLOOPS to 1 STEP -1
   ' lots of code
 NEXT


In cases with that much code I would be inclined to handle the iterations manually:

  event = MAXLOOPS

Top:
 ' lots of code
 event = event - 1
 IF event > 0 THEN Top


Either way works, it's a matter of style.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

@Mike: Okay, just a thought... on "bumping" you might try toggling an output using random timing between the transitions instead of assigning a random bit; this gives more changes.  Using the random bit you could, within a series of random numbers, see no bit change in that position for a number of cycles which artificially stretches your current state timing.

Example of output toggling:

Bounce:
 Lid = 1 - Lid
 RANDOM lottery
 delay = lottery // 151 + 100
 PAUSE delay
 timer = timer + delay
 IF timer < 2000 THEN Bounce
   Lid = IsClosed


When using a PINx variable for the output you can toggle it by subtracting the current state from 1 (1 - 0 = 1; 1 - 1 = 0).  I've started using this strategy versus copying the "random" bit as it gives a more lively output.




 
Jon McPhalen
EFX-TEK Hollywood Office

Tim-M

Ahhh, waiting for a USB2SER makes sense.  Hope springs eternal!

Tim

BigRez

Yep, the darn thing (USB2SER) was on backorder.  Called today and they said it (and the other stuff)  should ship tomorrow when they get more in. So much for completing it this weekend  :(   Maybe I will while temporarily using the VMusic module.

Thanks for the suggestions Jon.  After watching the trainer for a while prior to the current version, I saw what you're referring to (using the random bit) and added the line to force the pins off between the two delays.  I'll give your suggestion a try to see how it looks though.

JonnyMac

October 07, 2009, 03:17:34 PM #13 Last Edit: October 07, 2009, 05:20:55 PM by JonnyMac
Once you get your USB2SER you should upgrade the uMP3 firmware so that you can use the text-based configuration file.  I just got my uMP3 test bed out and am going to try that now.

No need to wait -- you can configure your uMP3 with the BS1-SA!  Yes, I found a way:

http://www.efx-tek.com/php/smf/index.php?topic=1250.msg7015#msg7015

You'll still need the USB2SER for reloading the uMP3 firmware, though.
Jon McPhalen
EFX-TEK Hollywood Office

BigRez

Thanks again - I was able to configure the uMP3 with the BS1-SA and now also have the USB2SER.

The prop is looking good and the program runs well with only two bytes to spare, but I wanted to add a pair of LED lights to the beast. They'd go on at the same time the doors open (or anytime at the start of Attack: ) and could go off at Reset.  Eyes are connected to PIN3.

It should only take two bytes to add the     Eyes = IsOn    line to the code and I have two bytes left, but I get an eprom full message.

So, is there something I can do better in the attached program to free up some space?  I'm thinking the shaking routine could use some work to make it better/smaller.  Any ideas?

Thanks in advance,