November 22, 2024, 12:41:30 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.


Simulation Ride

Started by nightmarez, September 24, 2007, 10:45:37 AM

Previous topic - Next topic

nightmarez

 ??? Got my Prop 2 Controller and  :-\ Now I need to know how to get started.
I will have 3 air bags w/ EP's and 2 more EP's blasting air at the face or feet within the ride itself.  I have a MP3 that will tie in and play either my background ambiance when it is just sitting, and the show track. 

Any help or pushes for the right direction!?!  ???

Thanks in Advance,
Newb... :P

JonnyMac

I'll actually write a starter program for you -- but you have to assume that I don't know what you know.  For example, I have no idea what an "EP" is (remember, I'm an electronics engineer who helps prop builders). 

What kind of MP3 player to you have?  Can it be remotely controlled (like the Rogue uMP3).

How will the ride be started?

What is the sequence of events -- how are things timed relative to each other.

For general BASIC Stamp (our prop controllers are built on the BASIC Stamp) programming training our friends at Parallax have create tons of material:

* What's A Microcontroller?
* StampWorks  (written by me)

Jon McPhalen
EFX-TEK Hollywood Office

nightmarez

October 04, 2007, 05:36:50 AM #2 Last Edit: October 04, 2007, 05:42:05 AM by nightmarez
I have the MP3 player you recommended  ::)  ;D Rogue... yep.

It will start w/ a push button.  *Simple right?* Ambient music will play until the button is pressed and the show will start -

There will be 3 outputs for the "air bags" to move the ride up and down, sound inside, and 2 more outputs that will activate more internal air blast and movement inside the ride. 
When the show stops, I want it to go back to the ambient music. 
Plus I would like to add another input (from a button as a panic button) that would shut it down in case someone 'freaks out!'

Simple for me to say, but is the programming a bear?

Thanks John!

gadget-evilusions

What voltage are your valves and how much power do the coils draw?
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

October 04, 2007, 10:02:20 AM #4 Last Edit: October 17, 2007, 09:16:15 AM by JonnyMac
Okay, Nightmarez, let me just start by saying this is ABSOLUTELY NOT the best place for you to start.  Please, I'm begging you, download our Prop-2 Programming Basics document and go through it until you're conformable with blinky lights, etc.  It would be unfair to guage the ease-of-use of the Prop-2 with this program; for me, it's easy -- but I've written a few [thousand] programs before this one.  You don't need that much experience to understand it, but you should have some experience before working with something this sophisticated.

Still, it is my place to serve, and as you asked for a starter program -- here it is.  It's not nearly as complicated as it looks, but I can only say that because I have a bit of experience.

This program takes a "player piano" approach where the output bits are set in a table, along with a timing value for those bits.  The timing subroutine monitors the panic button and will stop everything if that button gets pressed.


' =========================================================================
'
'   File...... Simu_Ride.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

TX              PIN     15                      ' to UMP3.R; no ULN/SETUP
RX              PIN     14                      ' to UMP3.T; no ULN/SETUP
Trigger         PIN     13                      ' setup = DN
Panic           PIN     12                      ' setup = DN

Blaster2        PIN     4
Blaster1        PIN     3
Bag3            PIN     2
Bag2            PIN     1
Bag1            PIN     0


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

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T4800       CON     188
    T9600       CON     84
    T19K2       CON     32
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T4800       CON     500
    T9600       CON     240
    T19K2       CON     110
    T38K4       CON     45
#ENDSELECT

Inverted        CON     $4000
Open            CON     $8000
EfxBaud         CON     Open | T38K4            ' for DC-16, RC-4, etc.
uMP3Baud        CON     Open | T9600            ' for uMP3 player

Yes             CON     1
No              CON     0

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

EventDelay      CON     100                     ' timing is 0.1 secs


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

char            VAR     Byte                    ' character I/O
pos             VAR     Word                    ' uMP3 file position
loopNum         VAR     Byte                    ' file loop # in cycle
lottery         VAR     Word                    ' random value

showBits        VAR     Word                    ' output + control bits
endOfShow       VAR     showBits.BIT15          ' 1 = stop when timer done
record          VAR     Word                    ' current sequence record
tix             VAR     Byte                    ' timing for record

lVol            VAR     Byte                    ' left channel volume
rVol            VAR     Byte                    ' right channel volume


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

Start_Up:
  PAUSE 2000                                    ' let uMP3 start

Prod_uMP3:
  DO
    SEROUT TX, uMP3Baud, [CR]                   ' send CR
    SERIN  RX, uMP3Baud, [char]                 ' get response
  LOOP UNTIL (char = ">")                       ' wait for ">"

Reset:
  OUTS = %0000000000000000                      ' clear I/O pins
  DIRS = %0000000000011111                      ' configure outputs

  SEROUT TX, uMP3Baud, ["PC S", CR]             ' stop anything playing
  PAUSE 3000
  SEROUT TX, uMP3Baud, ["ST O 0", CR]           ' set to infinite looping
  SEROUT TX, uMP3Baud, ["PC F /ambient.mp3", CR]


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

Main:
  RANDOM lottery                                ' stir random value
  IF (Trigger = IsOff) THEN Main                ' wait for trigger

Start_Audio:
  SEROUT TX, uMP3Baud, ["ST O 1"]               ' play once
  SEROUT TX, uMP3Baud, ["PC F /ride.mp3", CR]   ' start ride audio

  record = 0                                    ' start of show

Play_Show:
  READ Show_Data + (record * 3), Word showBits, tix
  OUTS = showBits & $0FFF

Timer:
  IF (Panic = Yes) THEN Reset                   ' stop show on Panic input
  IF (tix = 0) THEN Next_Step                   ' timer expired?
    PAUSE EventDelay                            ' no, time one "tic"
    tix = tix - 1                               ' decrement timer
    GOTO Timer                                  ' check again

Next_Step:
  IF (endofShow = IsOn) THEN Reset              ' done?
    record = record + 1                         ' no, point to next
    GOTO Play_Show                              ' and keep going


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

' Hold until current file in uMP3 is finished

Wait_For_Stop:                                  ' let song finish
  DO
    GOSUB Get_Status
  LOOP UNTIL (char = "S")
  RETURN

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

' Gets status from uMP3
' -- "P" = playing, "D" = paused, "S" = stopped
' -- also gets file position and loop number of play cycle

Get_Status:
  SEROUT TX, uMP3Baud, ["PC Z", CR]
  SERIN  RX, uMP3Baud, [char, DEC pos, DEC loopNum]
  RETURN

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

' Sets uMP3 volume
' "lVol" (left) and "rVol" are from 0 (loudest) to 254 (muted)

Set_Volume:
  SEROUT TX, uMP3Baud, ["PC V ", DEC lVol, DEC rVol, CR]
  RETURN

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


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


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

'                           +-------------------- end of show bit
'                           |
'                           |   +---------------- OUT11
'                           |   |
'                           |   |
'                           |   |      +--------- Blaster 2
'                           |   |      |
'                           |   |      |+-------- Blaster 1
'                           |   |      ||
'                           |   |      ||+------- Airbag #3
'                           |   |      |||
'                           |   |      |||+------ Airbag #2
'                           |   |      ||||
'                           |   |      ||||+----- Airbag #1
'                           |   |      |||||
'                           |   |      |||||  +-- timing multiplier (1 to 255)
'                           |   |      |||||  |
Show_Data       DATA  Word %0000000000000000, 1
                DATA  Word %0000000000000000, 1
                DATA  Word %0000000000000000, 1
                DATA  Word %0000000000000000, 1
                DATA  Word %0000000000000000, 1
                DATA  Word %0000000000000000, 1
                DATA  Word %0000000000000000, 1
                DATA  Word %0000000000000000, 1
                DATA  Word %0000000000000000, 1
                DATA  Word %1000000000000000, 0
Jon McPhalen
EFX-TEK Hollywood Office

nightmarez

 :o ;D Thanks John...
I agree a simple program may have been better, but I like difficult plus we have some experience in the HVAC industry doing controls on HVAC and programming, so maybe we have an edge  ???

I appreciate it, and I might have another question, but looking forward to shooting you results!  ;D

Eelem

I'm helping nightmarez on this project, but when I try to load the sample program I got a syntax error on this line.

Quote
READ Show_Data + (record * 3), Word showBits, tix
Error - Undefined symbol

I've had some experience working with a Parallax BOE but that was years ago so I'm a little rusty on the coding.

JonnyMac

October 17, 2007, 08:47:36 AM #7 Last Edit: October 17, 2007, 09:18:48 AM by JonnyMac
Darn me, I did it again: after getting a program to work I "prettied it up" and introduced an error -- I moved the Show_Data label off a line with a DATA directive; the compiler doesn't like this.  Grab the updated data section from the [modified] listing above.  This removes the error and allows other DATA statements to be mixed into the program without worrying about the absolute address of the outputs table.
Jon McPhalen
EFX-TEK Hollywood Office

Eelem

Ok, I've got everyhing working except for the sound I'm not getting any response from the ump3 board. Any suggestions?

JonnyMac

Test the uMP3 is isolation -- that's always a good idea.  I've posted lots of very specific information on using the uMP3 in the Audio forum, you may want to review it.
Jon McPhalen
EFX-TEK Hollywood Office

steveo

I was playing around with writing and reading to the EPROM the other night. I came across this thread and it's been very helpful in terms of figuring all this out. I did have a question though.

In the line:
READ Show_Data + (record * 3), Word showBits, tix

Which referenced one of these statements:

Show_Data       DATA  Word %0000000000000000, 1

So...
In this example, is Show Data a label of sorts for the DATA table? I don't see a colon after it. In prop1 there was no label needed, it just read whatever byte sized block it was told to based on the value for the pointer.

Why is the record value (which i think acts as a pointer to the next block of memory to store each 2 byte sequence in right?) updated in multiples of three?

I'm getting there Jon. I think I've hit the point where every night practicing just leads to (hopefully) better questions.

JonnyMac

DATA labels are special -- they don't use a colon because you cannot jump to them.  Their purpose is to allow the compiler to resolve the address of the DATA, because READ needs an address.

If you look at the READ line, it actually picks up two elements: a word-sized (two bytes) variable called showBits, and a byte sized variable called tix; the grand total read on the line is three bytes, hence the multiplier used..
Jon McPhalen
EFX-TEK Hollywood Office

steveo

Ahh.. all of a sudden that makes sense...

I wish I had taken the time to learn techniques like this last year. They're a little more complex up front but seem to be a much more "elegant" solution.

Plus it's wicked cool!