November 01, 2024, 02:35:46 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Working on an elevator Simulator...

Started by Ryanm0085, January 31, 2009, 01:21:53 PM

Previous topic - Next topic

Ryanm0085

So my last experience with the Prop-2 turned out very well thanks to Jon's help.  I have started a new project, the elevator simulator.  This gives the effect of going up or down, without actually being in a elevator.  I'm still in the planning process but have some questions. I will be using the Prop-2 with the DC-16, the FC-4, and the VMusic Player.  I need the prop-2 to give feedback of what state its in.  We have a control room where we monitor our haunted walk as well as watchover our computer animated scenes.  I've heard of the Debug mode, but i'm not sure if that is what i think it is.  I just need to know when the simulator is "waiting" and "running" and other parts of the sequence.  Also, is there anyway to get the Vmusic player to fade in and out, giving the effect of actually going down a floor.  I want to play music outside they can hear as there getting in, and have it fade out as they are going down?  Any info would be great!!! Once i get building and start the programming aspect, i'm sure i will have plenty more questions...

JonnyMac

First: Take it slowly -- this is a "big" prop, code-wise.

The DEBUG window, as you can read about in the help file (hint, hint) allows you to send data to a terminal built into the editor; it's not useful when running a production program.

Based on your note your simulator has two states: waiting (0) and running (1) -- this can easily be monitored with an IO pin.

You're going to have to create faded files for the VMUSIC to play; there is no fade-in command and doing it though code is not workable as you'll get clicks and pops.  Since the audio is on a thumb drive space is not an issue; create the faded files from your master and play those -- makes things simple and more reliable.
Jon McPhalen
EFX-TEK Hollywood Office

Ryanm0085

I know i can use outputs to show the "Running" state and "waiting" state.  But i plan on using infrared beams to make sure the area is clear before it kicks on.  Also some other steps like when the doors are closed and stuff like that.  Mainly its to help give us a better idea of where its at in its program without being there since everythings controlled from a small room, this way we can keep better flow of our patrons.  I have seen small lcd displays and stuff like that.  But it would be great to monitor it from a computer.  Any Ideas or am i barking up the wrong tree?

Ryanm0085

Oh yeah...i also need to know if i can use 2 VMusic Players...  I want to be able to play the different outside noises, but i also need one to play the sound effects.  i thought about over-laying the sound effects into the audio track, but i would like to be able to have the music playing as they walk up...otherwise it would have to start at the exact same time everytime. 

Ryanm0085

can you tell me if i can use two VMusic players on one prop 2

JonnyMac

You can, but you'll only be able to keep track of one at a time.  If one is just for ambient then you won't have a problem other than you'll need the extra connections (two per VMUSIC player if you want to do it right).
Jon McPhalen
EFX-TEK Hollywood Office

Ryanm0085

ok jon...you ready.  i just recieved all my goodies in the mail and im ready to start programming...  i only want you to help me get started so i can see if i can do the rest myself.  im better at learning that way.  im not sure exactly how im gonna connect everything up yet but i have a basic idea.  i need help with setting up the two Vmusic players and the dc-16.  Inititial:  Elevator lights on.  I'd like the elevator to have two inputs to start it, needing both inputs to be pushed to start the sequence.  this way two actors can make sure there clear inside and outside before any motion. Once both are pressed, the door closes.  The solenoid valve turns on for 5 seconds, then off.  Then the Dump Valve turns on for 5 seconds and then off.  I'm not sure exactly the music setting yet, but if you can, just throw some random codes in there for a random play for each Vmusic player just so i know how to distinguish between the two.  My set-up will be much more elabortate but i dont want you to help me to much yet.  i really wanna understand this stuff.  i want to keep the Vmusic players and inputs on the prop 2 and all outputs on the dc-16.  this is what i figured, you can correct me.

Prop 2
Channel 0 = Trigger 1A
Channel 1 = Trigger 2B
Channel 4/5= VMusic 1
Channel 6/7= Vmusic 2

Dc-16
Channel 0 = Elevator Lights
Channel 1 = Solenoid
Channel 2 = Dump Valve
Channel 3 = Door

I need to know which chips to use and what jumpers to set as well.  i ordered 10 of each chip so i have room for error, hopefully not though.  Once i am fnished and have everything figured out, id like to post the full program and maybe even post a video of it.  i am very excited for this project.  hopefully everything will work out.  Thanks Again. 



Ryanm0085


JonnyMac

April 27, 2009, 09:46:50 AM #8 Last Edit: April 27, 2009, 09:50:57 AM by JonnyMac
Okay.  First... you realize, of course, that what you want to do is quite involved, so... TAKE YOUR TIME.  I'm going to give you a big head start with the template program below.  It will take care of checking for the VMUSIC players (I have verified that this works with the one player I have), sending song commands to either, scanning the inputs, and updating the DC16.  Be very careful not to modify my code -- just put your working code in the Main section.  Once you have a good grasp of what I'm doing, go crazy and modify everything; that's the best way to learn.

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2009 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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

' For serial comms: Cut pins 1-5 from the ULN in the P8-P15 socket.  Move
' P12-P15 SETUP jumpers to the UP position.


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


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

RX2             PIN     15                      ' no ULN, SETUP = UP
TX2             PIN     14                      ' no ULN, SETUP = UP
RX1             PIN     13                      ' no ULN, SETUP = UP
TX1             PIN     12                      ' no ULN, SETUP = UP
Sio             PIN     11                      ' no ULN

Tr2             PIN     1                       ' Trigger #2
Tr1             PIN     0                       ' Trigger #1


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

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

Yes             CON     1
No              CON     0

T2400           CON     396
T38K4           CON     6
SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000

Baud            CON     Open | T38K4            ' for VMUSIC + DC-16


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

flags           VAR     Byte
vm1Error       VAR      flags.BIT0
vm2Error       VAR      flags.BIT1

player          VAR     Byte                    ' VMUSIC player, 1 or 2
port            VAR     Byte                    ' TX or RX por for player

timer           VAR     Word
triggers        VAR     Byte
trigger1       VAR     triggers.BIT0
trigger2       VAR     triggers.BIT1

idx             VAR     Byte                    ' loop controller
eePntr          VAR     Word                    ' EE pointer for DATA
char            VAR     Byte                    ' character out

dc16            VAR     Word
ELights        VAR      dc16.BIT0
Solenoid       VAR      dc16.BIT1
DumpValve      VAR      dc16.BIT2
Door           VAR      dc16.BIT3
VmError        VAR      dc16.BIT15             ' problem with 1 or both


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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000000           ' set outputs

  dc16 = IsOff
  GOSUB Set_DC16                                ' clear DC16 outputs

  flags = %00000000                             ' assume all okay
  PAUSE 3000                                    ' let VM players power up

  player = 1                                    ' look for VM #1
  GOSUB VM_Check
  GOSUB VM_Stop

  player = 2                                    ' look for VM #2
  GOSUB VM_Check
  GOSUB VM_Stop

Check_Players:
  IF vm1Error = Yes THEN
    DEBUG "VMUSIC #1 not detected", CR
    VmError = IsOn
    GOSUB Set_DC16
  ENDIF

  IF vm2Error = Yes THEN
    DEBUG "VMUSIC #2 not detected", CR
    VmError = IsOn
    GOSUB Set_DC16
  ENDIF


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

Main:
  timer = 0
  triggers = %00000011                          ' assume active
  FOR idx = 1 TO 20                             ' 100ms scan
    triggers = triggers & INL                   ' scan P0 & P1
    PAUSE 5
  NEXT
  IF (triggers = %00000000) THEN Main           ' wait if no input


Check_Tr1:
  IF (trigger1 = IsOn) THEN
    ' do something
  ENDIF


Check_Tr2:
  IF (trigger2 = IsOn) THEN
    ' do something
  ENDIF

  GOTO Main


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

' Set "player" to 1 or 2 before calling
' -- will set error flag if no response in 2 seconds

VM_Check:
  player = player MIN 1 MAX 2                   ' fix bad player #
  port = ((player - 1) * 2) + 12                ' set for TX port

  idx = 0

VM_Check_Again:
  idx = idx + 1
  IF idx > 5 THEN
    flags.LOWBIT(player-1) = 1                  ' set error flag
    GOTO VM_Check_Exit
  ENDIF

  SEROUT port, Baud, [CR]
  SERIN (port+1), Baud, 400, VM_Check_Again, [WAIT(">")]

VM_Check_Exit:
  RETURN

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

' Set "player" to 1 or 2 before calling

VM_Stop:
  player = player MIN 1 MAX 2                   ' fix bad player #
  port = ((player - 1) * 2) + 12                ' set for TX port
  SEROUT port, Baud, ["VST", CR]
  RETURN

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

' Set "player" to 1 or 2 before calling
' Set "eePntr" to DATA statement label with MP3 name

VM_Play:
  player = player MIN 1 MAX 2                   ' fix bad player #
  port = ((player - 1) * 2) + 12                ' set for TX port
  SEROUT port, Baud, ["VPF "]                   ' send play command
  DO                                            ' send name (from DATA)
    READ eePntr, char
    IF char = 0 THEN EXIT
    SEROUT port, Baud, [char]
    eePntr = eePntr + 1
  LOOP
  SEROUT port, Baud, [".mp3", CR]               ' send extension
  RETURN

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

Set_DC16:
  SEROUT Sio, Baud, ["!DC16", %00, "S", dc16.BYTE0, dc16.BYTE1]
  RETURN

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


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


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

File1           DATA    "file01", 0
File2           DATA    "file02", 0
File3           DATA    "file03", 0
File4           DATA    "file04", 0
File5           DATA    "file05", 0
Jon McPhalen
EFX-TEK Hollywood Office

Ryanm0085

alright now im totally confused...is there any site or anyway you can show me what each section of the program is for.  The program you sent me last year i understood, but this one is very complex.  I confused mostly on the initialization section. not sure what it all means.  i've gotten to the point where i can right a code, but the initilization the variables are all confusing to me.  also, i wanted to know if i add a serial lcd display, how much trouble would it be to put in the program.  haha i really wish you were my next door neighbor or something.  it would make things alot easier, but id probably never spend any time at home.  also i was wondering if theres a good site or a book that i can get.  i've read so much stuff online with coding, but not really into much of the layouts.  thanks jon

JonnyMac

April 29, 2009, 11:48:56 PM #10 Last Edit: April 29, 2009, 11:52:15 PM by JonnyMac
What you want for your prop is advanced, hence advanced code.  Don't fret as that never helps.  Just take it one line at a time and follow the flow.  I've provided comments to tell you what the program is doing along the way, these will help.  Remember, I've been coding in some form or another for nearly 30 years -- I have a head start on you.  It will come but you have to treat new, complex programs like eating an elephant: one bite -- uh... byte -- at a time.   ;)

You may want to review the variable section of the manual as I have a byte called "flags" that is being used as a group of bits (only two at the moment).  Once you understand the program I'll help you add a serial display; it's just more SEROUT statements.

I recommend "StampWorks" written by, ahem... yours truly.  You can download it as a PDF from the Parallax web site.  You won't be able to run all of the experiments on the Prop-2 but reading through the code explanations will do you a lot of good.
Jon McPhalen
EFX-TEK Hollywood Office

Ryanm0085

ok jon, im just gonna give you want i need and go from there.  Ill tell you how everything is connected and you can let me know what to change.  i decided to use only one VMusic player

Prop-2
0-Input 1
1-Input 2
2-Elevator up
3-elevator down
4-door open
5-door close
6-elevator lights
7-black lights
8-divider open
9-divider close
11-dc-16
12-Tx1
13-Rc1

Dc-16
0-Floor One
1-Floor two
2-Floor three
3-Up Arrow
4-Dn Arrow

the sound files are elevator1.mp3 and elevator2.mp3

On initialization, floor 3 will be on, the divider closed, the door closed, the elevator down, the elevator lights on and elevator1.mp3 playing at full volume.  trigger 1 will start the first sequence.  Once pushed, the down arrow will turn on, the floor levels will count down from 3,2,1 with approx.  a second bewtween each.  once floor one lights up the down arrow turns off and the door opens. 

Trigger 2-  When pressed, the up arrow turns on and the door closes.  wait 2 seconds then elevator up.  once the elevatorgoes up, the floors will count back up to 3 then the arrow goes off.  as the elevator goes up, i need elevator1.mp3 to fade out, then play elevator2.mp3 and fade in.  wait a few seconds then elevator down.  then the divider opens, the elevator lights go off, and the black lights come on.  wait 20 seconds then the elevator doors open.  after 2 minutes, everything should reset back to the initialization

This is basically what i need.  the timing and everything im pretty sure i can do once i get the program down.  i would like to add an emergeny stop somehow, either just using a relay to kill the power(which i can rig up) or if you can do it in the program so when its pushed the elevator drops, the doors open, and the lights come on and stop everything else.  right now im mainly concerned about the main program i can deal with that later.   and then eventually i want to add an lcd but thats down the road.  once again thanks for your time and your fast replys.  im not giving up.  i have a prop-1 and another prop-2 besides the one for this and im determined to program them myself.  they should be easier and not as complex....


Ryanm0085


JonnyMac

I'm back in action and will write some code.  One thing will not happen, however: fade out of one mp3 file while fading in another.  This is not supported in the VMUSIC (which has become my least favorite mp3 product) and attempting to do it with looped code will cause it to hiccup because of all the data interrupting the mp3 stream.  Sorry.  You can have the second mp3 fade in before stopping the first.
Jon McPhalen
EFX-TEK Hollywood Office

Ryanm0085

actually i wanna fade the first one completely out....then start fading the second one in...and if that wont work what other mp3 player do u recommend