November 23, 2024, 08:17:57 AM

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.


Altering program

Started by Indianaholmes, April 06, 2009, 05:07:53 PM

Previous topic - Next topic

Indianaholmes

Hello Jon, I have taken a program that was written by John Sbandi quite a while back and am trying to modify it for my needs. He is using a trigger and two pneumatic cylinders. I have changed the timing of the cylinders firing to my liking but want them to be independent of each other. Currently they alternate firing between each other, sometimes firing together. What I would like to see is occasionally, cylinder 1 will fire twice in a row. Same with cylinder two. I like that they fire together sometimes, but by random, I think they should not always fire alternately. I would also like for this to be triggered by a PIR, which I have just ordered from you guys. I will list both the original program by John Sbandi, and my butchered version with the correct timing between cylinder actuation's. I know the timing is correct because I've run it on a prop1 trainer. I cannot test my PIR version yet because I haven't received my PIR. I am also trying to get this prop to wait 10 seconds before it can be triggered again. Does it look right to you. I know, I know, look at the documentation. I have. But this stuff does not come easily to me. Please DO NOT be kind to me. A good raking over the coals is sometimes the best motivator.

John's program
' =========================================================================
'
'   File...... Couch_Props.BS1
'   Purpose... Animated couches
'   Author.... John Sbandi
'   E-mail.... john@thedevils-den.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Couch1          = PIN5
SYMBOL  Couch2          = PIN4


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  lottery         = W0
SYMBOL   c1Enable       =  BIT0
SYMBOL   c2Enable       =  BIT1

SYMBOL  delay           = W4
SYMBOL  timer           = W5


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00110000                              ' make P4-P5 outputs


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' stir random #
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF Trigger = IsOff THEN Main                  ' wait for trigger
    PAUSE  3000

  timer = 0                                     ' reset timer

Shake_Rattle_Roll:
  RANDOM lottery                                ' stir random #
  Couch1 = c1Enable                             ' update outputs
  Couch2 = c2Enable
  delay = lottery // 501 + 250                  ' 0.25 to 0.75 secs
  PAUSE delay
  timer = timer + delay                         ' update timer
  IF timer < 60000 THEN Shake_Rattle_Roll       ' done?
    GOTO Reset


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


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


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





Randy's butchered program;

' =========================================================================
'
'   File...... Couch_Props.BS1
'   Purpose... Animated couches
'   Author.... JohnSbandi./Randy
'   E-mail.... r.holmes2004@comcast.net
'   Started...
'   Updated...       4-3-09
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                        ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Couch1          = PIN5
SYMBOL  Couch2          = PIN4


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  lottery         = W0
SYMBOL   c1Enable       =  BIT0
SYMBOL   c2Enable       =  BIT1

SYMBOL  delay           = W4
SYMBOL  timer           = W5


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00110000                              ' make P4-P5 outputs


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

Main:
  timer = 0                                                    ' reset timer

Check_Trigger:
  RANDOM lottery                                          ' stir random value
  PAUSE 1                                                     ' loop pad
  timer = timer + 5 * PIR                              ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec.

  PAUSE  2000                                             ' wait 2 sec.

  timer = 0                                                  ' reset timer

Shake_Rattle_Roll:
  RANDOM lottery                                       ' stir random #
  Couch1 = c1Enable                                  ' update outputs
  Couch2 = c2Enable
  delay = lottery // 1201 + 150                  ' 0.15 to 1.35 secs
  PAUSE delay
  timer = timer + delay                                    ' update timer
  IF timer < 35000 THEN Shake_Rattle_Roll       ' done?
    GOTO Reset

  PAUSE 10000
' -----[ Subroutines ]-----------------------------------------------------


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


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


JonnyMac

First raking over the coals: one program per thread, please!  ;D 
Jon McPhalen
EFX-TEK Hollywood Office

Indianaholmes

Ouch!......That didn't hurt :P. OK. I was only trying to give credit to the original writer. His program was just a template for what I am after and I thought it would be beneficial to see the model from which my program will come from. Now I'm at a loss. Do you want me to start all over with a new thread? Or do you want me to continue with this one and post only my butchered program? I do know that you want things spelled out so here is the time line;
1) PIR detects victim.
2) pause 2 seconds before program starts
3) Two cylinders start to randomly fire every .95 to 1.35 seconds. Sometimes they are on at the same time, sometimes one will fire twice before the other cylinder fires. True random? This will go on for 35 seconds.
4) Program stops and waits 10 seconds before the PIR can be triggered again.

I may add a trigger for a dry switch later that will start at the beginning of the 2 second pause. If I can hack a cheap MP3 player, I'll need the dry switch. If the hack of the player is too tough, I'll loop the sound continuously. Haven't decided yet.

So, would you have me start a brand new thread and name it "Need Code"?  ;D

JonnyMac

I always love seeing code I wrote with another person's name on it -- I wrote that couch control code a long time ago....  It's nice to be appreciated for the support we provide.   ;D

You should, in theory, get the behavior you want from that code, perhaps an extra stirring of RANDOM will help.  I won't go into the boring technical details but RANDOM uses a process called LFSR and we've found that running it three times in the middle of the loop gives better randomness (we do this with candles).  Give this version a try before we attempt to write [complicated] code that forces the multiple outputs on the cylinders.

' =========================================================================
'
'   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... 07 APR 2009
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Cylinder2       = PIN1
SYMBOL  Cylinder1       = PIN0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  idx             = B2

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


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000011                              ' set outputs

  PAUSE 10000                                   ' show delay


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

Main:
  timer = 0                                     ' reset timer

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

  PAUSE 2000
  timer = 0

Jump_Loop:
  FOR idx = 1 TO 3                              ' really stir it up
    RANDOM lottery
  NEXT
  PINS = lottery & %00000011                    ' update cylinders
  RANDOM lottery
  delay = lottery // 401 + 950                  ' 0.95 to 1.35s
  PAUSE delay
  timer = timer + delay
  IF timer < 35000 THEN Jump_Loop

  GOTO Reset


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


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


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

Indianaholmes

Thank you very much Jon. I went back and looked at all the posts of this gentleman and in every instance, any code written in his threads have his name on them. I was really trying to get the author right when I posted his/your code. Please forgive me if I have plagerized something. I tried very hard to give credit where credit was due. Maybe I should have assumed that you were the author. Anyway, I'm sorry if I've done something wrong.

JonnyMac

I have a very district style so I can easily pick out my own code, even when others put their name on it (and I actually remember writing that program).  I'm not upset, I was teasing; most of what I write is for public consumption, anyway -- I'm just amused when someone says, "Hey, person X wrote a program for me..." and it turns out that person X didn't actually write the code, I did!
Jon McPhalen
EFX-TEK Hollywood Office