November 23, 2024, 10:58:48 PM

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.


Program to operate double acting cylinder.

Started by pbronson, March 06, 2008, 09:51:02 AM

Previous topic - Next topic

JonnyMac

You need to find a receiver that is intended for key fobs -- Parallax no longer carries them; the receiver they have is for serial communications and that will complicate things.  Standard key fob receivers have an active-high output so they look exaclty like a button press.  I don't know what Parallax doesn't carry these any more, but I'm sure other companies do.
Jon McPhalen
EFX-TEK Hollywood Office

pbronson

Jon,

It has been awhile but I am still learning. I would like to add a PIR to the system to prevent the door from closing in the event that someone is in the doorway. I will be placing the sensor from Parallax where it would only see the door area and would like to see how you would modify the program to place the close command into a loop until the PIR sees no movement. THen signal for the close.

Thanks for any help.

Pete

JonnyMac

You didn't tell me how long to scan the PIR, so I set the "no movement" timer to one second (1000ms).

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


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


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


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

SYMBOL  DelaySet        = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  PIR             = PIN5                  ' ULN acts as pull-down
SYMBOL  Retract         = PIN2
SYMBOL  Extend          = PIN1
SYMBOL  Servo           = 0


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

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

SYMBOL  ExtendOn        = %00000010             ' extender active
SYMBOL  RetractOn       = %00000100             ' retracter active

SYMBOL  ClosureTime     = 10000                 ' door closure time


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

SYMBOL  state           = B2                    ' program state
SYMBOL  pos             = B3                    ' door latch servo position

SYMBOL  delay           = W4                    ' door open delay
SYMBOL  timer           = W5                    ' timer for states


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

Reset:
  PINS = RetractOn                              ' clear all except retract
  DIRS = %00111111                              ' make P0-P5 outputs

  state = 0                                     ' look for trigger
  pos = 150                                     ' center servo
  timer = 0                                     ' reset timer


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

Main:
  PULSOUT Servo, pos                            ' refresh servo
  PAUSE 15                                      ' trimmed for 20 ms loop

  BRANCH state, (Get_Trigger, Get_Delay, Open_Latch, Extend_It, Check_PIR, Retract_It)
  GOTO Reset

Get_Trigger:
  pos = 150                                     ' at center
  PINS = RetractOn                              ' door is closed
  timer = timer + 20 * Trigger                  ' update timer
  IF timer < 200 THEN Main                      ' wait for 0.2 sec input
    state = 1
    timer = 0
    GOTO Main

Get_Delay:
  POT DelaySet, 109, delay                      ' read pot, 5..255
  delay = delay / 5 + 9 * 1000                  ' scale to 10000 to 60000
  state = 2
  timer = 0
  GOTO Main

Open_Latch:
  pos = 200                                     ' relase latch
  PINS = RetractOn
  timer = timer + 20                            ' update timer
  IF timer < 1000 THEN Main                     ' 1 second elapsed?
    state = 3                                   '  yes, next state
    timer = 0                                   '  reset the timer
    GOTO Main

Extend_It:
  pos = 200
  PINS = ExtendOn                               ' open door
  timer = timer + 20
  IF timer < delay THEN Main
    state = 4
    timer = 0
    GOTO Main

Check_PIR:
  IF timer = 1000 THEN PIR_Okay                 ' 1s no movement?
    timer = timer + 20                          ' not yet, update timer
    IF PIR = IsOff THEN Main                    ' if off, back to loop
      timer = 0                                 ' else reset timer
      GOTO Main

PIR_Okay:
  state = 5
  timer = 0
  GOTO Main


Retract_It:
  pos = 150                                     ' relase latch
  PINS = RetractOn                              ' close door
  timer = timer + 20
  IF timer < ClosureTime THEN Main

  GOTO Reset                                    ' reset everything


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


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


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


pbronson

Jon,

I am back to update my project that you helped me with and need a little help. I ended up finding an actuator that would work and have been using the program with the POT control. I would like to incorporate the PIR at this time and ask if you would replace the code to reflect my using the actuator and not the servo as in the code listed. I would like the PIR to scan for 2 seconds and if there is no movement then the door can close.

Thanks for the help.

Pete

JonnyMac

Please start a new thread so we all have a clean start and don't have to wade through pages of past information to create a program.  Your prop changed and you have new requirements, so this makes sense.  Please list the new requirements, in total, in the new thread (that is, don't assume that I or anyone else knows anything).

Happy New Year!
Jon McPhalen
EFX-TEK Hollywood Office