May 20, 2024, 06:43:00 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.


Drop Prop code please help

Started by Natashead, October 08, 2015, 11:43:11 PM

Previous topic - Next topic

Natashead

Does anyone know why I keep getting errors from this older code?

' {$STAMP BS1}
' {$PBASIC 1.0}

' **************************************************************
' *          Scary Prop Dropper - Prop-1  Version              *
' *  Program to operate 2 servo motors to drop and retrieve    *
' *   a small "scare" item like a rubber bat or spider         *
' *     (c) By Vern Graner SSE, Texas Information Services     *
' **************************************************************
' * Created: 8/2/09 Vernon Graner v1.0h                        *
' **************************************************************

' ************************
' * Pin Definitions      *
' *************************************************************************
  SYMBOL  ServoWinch    = 0    ' Winch Servo 1
  SYMBOL  ServoPosition = 1    ' Position Servo 1
  SYMBOL  TRIGGER       = PIN7 ' PIR, dry contact or other momentary switch

' ************************
' * Constants            *
' *************************************************************************
  SYMBOL Drop     = 200 ' Value to move Position Servo to"dump" position
  SYMBOL Retrieve = 120 ' Value to move Position Servo to "hoist" position

  SYMBOL Hold     = 150 ' Value to cause Winch Servo to stop moving
  SYMBOL Hoist    = 100 ' Value to cause Winch Servo to start moving

  SYMBOL False    = 0   ' \Used for logic comparisons
  SYMBOL True     = 1     /

' ************************
' * Variables            *
' *************************************************************************
SYMBOL  cntI     = W0 ' Increment Counter, Used in "FOR" loops etc.

' ************************
' * Program Begin        *
' *************************************************************************
    Main:
'     DEBUG "Waiting for Trigger",CR
     WaitForTrigger:
       PULSOUT ServoPosition,Retrieve '\ While waiting for a trigger, these
       PULSOUT ServoWinch,Hold        '| lines "hold" all servo positions to
       PAUSE 20                       '/ keep prop from "drooping".
      IF Trigger = False THEN WaitForTrigger


     StartDropSequence:  'We get to here when the "trigger" is detected
     DEBUG "Trigger Detected, begining drop sequence:",CR
     GOSUB Drop          ' Go to subroutine that "drops" the prop

     DEBUG "Drop Complete. Waiting to retrieve",CR
     PAUSE 3000          ' This controls how long we let the prop "dangle" before retrieving it

     DEBUG "Wait complete.",CR
     GOSUB Retract       ' Got to subroutine that retracts the prop

     DEBUG "Hoist Complete. Wait a bit..",CR
     PAUSE 12000          ' holdoff a bit before we trigger again

     DEBUG "Wait complete. Next Victim please!",CR,CR
     GOTO MAIN           ' Reset complete, go back to begining

' **************************
' * Subroutines            *
' *************************************************************************

Drop:
  ' **************************
  ' * Move Servo             *
  ' **************************
  DEBUG " -Move Position Servo to 'drop' position",CR
   FOR cntI=1 TO 35 ' ~35 times to allow the servo to reach its target position
    PULSOUT ServoPosition,Drop
    PAUSE 20
   NEXT
  RETURN

Retract:
  ' **************************
  ' * Move Servo             *
  ' **************************
  DEBUG "-Moving Position Servo to 'Retrieve' position",CR
   FOR cntI=1 TO 25
    PULSOUT ServoPosition,Retrieve
    PAUSE 20
   NEXT

  DEBUG "-Activating Hoist",CR
   FOR cntI=1 TO 640   ' Adjust for hoist time (i.e. more time for longer string)
    PULSOUT ServoPosition,Retrieve
    PULSOUT ServoWinch,Hoist
    PAUSE 20
   NEXT
  RETURN

JackMan

There's so many things wrong in this code that it needs to be re-written. Tell us EXACTLY what you want the program to do and someone will write you a new one.

Natashead

I want it to do what this one does minus the sound, I have everything I need to make it, thanks for the help.
http://www.nutsvolts.com/magazine/article/the_halloween_prop_dropper

JackMan

Cleaned this up a bit, it compiles OK now but not sure if it will work for you.


' {$STAMP BS1}
' {$PBASIC 1.0}

' **************************************************************
' *          Scary Prop Dropper - Prop-1  Version              *
' *  Program to operate 2 servo motors to drop and retrieve    *
' *   a small "scare" item like a rubber bat or spider         *
' *     (c) By Vern Graner SSE, Texas Information Services     *
' **************************************************************
' * Created: 8/2/09 Vernon Graner v1.0h                        *
' **************************************************************

' ************************
' * Pin Definitions      *
' *************************************************************************
  SYMBOL  ServoWinch    = 0    ' Winch Servo 1
  SYMBOL  ServoPosition = 1    ' Position Servo 1
  SYMBOL  TRIGGER       = PIN7 ' PIR, dry contact or other momentary switch

' ************************
' * Constants            *
' *************************************************************************
  SYMBOL Drop     = 200 ' Value to move Position Servo to"dump" position
  SYMBOL Retrieve = 120 ' Value to move Position Servo to "hoist" position

  SYMBOL Hold     = 150 ' Value to cause Winch Servo to stop moving
  SYMBOL Hoist    = 100 ' Value to cause Winch Servo to start moving

  SYMBOL False    = 0   ' Used for logic comparisons
  SYMBOL True     = 1

' ************************
' * Variables            *
' *************************************************************************
SYMBOL  cntI     = W0 ' Increment Counter, Used in "FOR" loops etc.

' ************************
' * Program Begin        *
' *************************************************************************
Main:
    WaitForTrigger:
       PULSOUT ServoPosition, Retrieve ' While waiting for a trigger, these
       PULSOUT ServoWinch, Hold        ' lines "hold" all servo positions to
       PAUSE 20                        ' keep prop from "drooping".
      IF Trigger = False THEN WaitForTrigger

StartDropSequence:       ' We get to here when the "trigger" is detected
     GOSUB Drop_Prop     ' Go to subroutine that "drops" the prop
     PAUSE 3000          ' This controls how long we let the prop "dangle" before retrieving it
     GOSUB Retract       ' Got to subroutine that retracts the prop
     PAUSE 12000         ' holdoff a bit before we trigger again
     GOTO MAIN           ' Reset complete, go back to begining

Drop_Prop:
   FOR cntI = 1 TO 35    ' ~35 times to allow the servo to reach its target position
    PULSOUT ServoPosition, Drop
    PAUSE 20
   NEXT
  RETURN

Retract:
   FOR cntI = 1 TO 25
    PULSOUT ServoPosition, Retrieve
    PAUSE 20
   NEXT

   FOR cntI = 1 TO 640      ' Adjust for hoist time (i.e. more time for longer string)
    PULSOUT ServoPosition, Retrieve
    PULSOUT ServoWinch, Hoist
    PAUSE 20
   NEXT
  RETURN


JonnyMac

October 09, 2015, 10:30:55 AM #4 Last Edit: October 09, 2015, 10:34:33 AM by JonnyMac
Vern is a veteran prop builder with a lot of Prop-1 experience -- I'm not sure what happened with this code.

Here's my version. It is stylistically different, but does the same thing. I try to write in a clear, concise manner without a lot of busy characters cluttering up the listing. Note, too, that I always refresh the servos using a subroutine that replaces PAUSE of long durations with Servo_Pause (in my opinion it's a very bad habit to use long PAUSE durations and not refresh servos -- it will bite you [as it did our friends at Legoland before we showed them the Servo_Pause trick]).

There are many roads that lead to Rome. This is mine for this particular prop.

Interesting Note: The text inside a DEBUG statement is not stored in the EEPROM, so you don't have to worry about it taking up valuable code space.


' =========================================================================
'
'   File...... Prop_Dropper.BS1
'   Purpose...
'   Author.... Vern Graner (modified & reformatted by JonnyMac)
'   E-mail....
'   Started...
'   Updated... 09 OCT 2015
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Position        = 1                     ' moves device
SYMBOL  Winch           = 0                     ' spools prop


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

SYMBOL  Dump            = 200                   ' position servo
SYMBOL  Retrieve        = 120

SYMBOL  Hold            = 150                   ' winch servo
SYMBOL  Hoist           = 100

SYMBOL  HoistCount      = 640                   ' will require adjustment

SYMBOL  False           = 0
SYMBOL  True            = 1


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

SYMBOL  svoPos          = B2                    ' servo position values
SYMBOL  svoWinch        = B3

SYMBOL  delay           = W4
SYMBOL  timer           = W5


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

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00000011                              ' P1..P0 are outputs

  svoPos = Retrieve                             ' initialize servo values
  svoWinch = Hold

  DEBUG "Inter-show delay", CR
  delay = 10000                                 ' inter-show delay
  GOSUB Servo_Pause

  DEBUG "Ready for trigger", CR


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  delay = 20
  GOSUB Servo_Pause                             ' refresh servos
  IF Trigger = False THEN Main                  ' check trigger input
    timer = timer + 20                          ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

  DEBUG "Dropping prop", CR
  svoPos = Dump                                 ' drop the prop
  delay = 35 * 20
  GOSUB Servo_Pause

  DEBUG "Drop complete -- wait to retrieve", CR
  delay = 3000
  GOSUB Servo_Pause                             ' hold in drop position

  DEBUG "Wait complete -- retracting", CR
  svoPos = Retrieve                             ' move to retrieve position
  delay = 25 * 20
  GOSUB Servo_Pause
  svoWinch = Hoist                              ' hoist up prop
  delay = HoistCount * 20                       ' loops to millis
  GOSUB Servo_Pause

  GOTO Reset


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

' Put duration to hold in "delay" before calling
' -- servos will hold current positions
' -- best if "delay" value multiple of 20

Servo_Pause:
  IF delay < 20 THEN SD_Exit
    PULSOUT Position, svoPos
    PULSOUT Winch, svoWinch
    PAUSE 17                                    ' account for servo pulses
    delay = delay - 20
    GOTO Servo_Pause

SD_Exit:
  PAUSE delay
  RETURN


Jon McPhalen
EFX-TEK Hollywood Office

Natashead

Thanks for doing this, I will try them both when I get home next weekend.

JackMan

Just wanted to add that I didn't mean to imply Vern's program wasn't correct, as Jon pointed out, some things must have gotten changed that caused errors.

Jeff Haas

There were two spots that kept it from compiling:

    SYMBOL True     = 1     /

This line somehow lost the apostrophe that commented out the slash.

And I couldn't get the Gosub to work with the section labelled "Drop:", but renaming "Drop" (same thing as JackMan did) fixed that.

Once you change both of these then the code compiles, and if you change the trigger to PIN6 you can test it with the Trainer.

FYI, the Prop-2 version compiled fine.

JackMan

October 09, 2015, 02:43:14 PM #8 Last Edit: October 09, 2015, 02:45:02 PM by JackMan

In addition to those 2 errors, most of the code in post #1 didn't have spaces after commas or before and after "=" signs. I've never really tried to load a program written that way so I'm not sure if that works or not. At the very least it's confusing without the spaces, and there are a lot of "errors" that the compiler won't pick up.

Natashead

JonnyMac I like your version better, it has a faster retrieve but when it is not in retrieve mode my winch servo is constantly spinning slowly through the entire run, can you tell me what I need to adjust?

Natashead

Nevermind I had to adjust the servos potentiometer. Your code ROCKS!!! Thanks man.
Is their anyway to trigger this strobe light trough out the whole run of code and then it turns off waiting for the next trigger? I don't need the flicker adjustment knob as it will be set to the fastest flicker all the time. Where would I plug it in as well? The strobe light runs on 3 AA batteries.

JackMan

I added the strobe to Jon's program. Remove the 3 batteries from the strobe, take the red wire that's attached to the circuit board and connect it to any "R" pin on the PROP-1 (those pins are constant 5V). Connect the black wire from the strobe to OUT2 of the PROP-1. Make sure the PROP-1 switch is in position 2.


' =========================================================================
'
'   File...... Prop_Dropper.BS1
'   Purpose...
'   Author.... Vern Graner (modified & reformatted by JonnyMac)(Battery Strobe function added by JackMan)
'   E-mail....
'   Started...
'   Updated... 09 OCT 2015
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Strobe          = PIN2                  ' Battery Strobe positive lead to any "R" pin, negative lead to OUT2
SYMBOL  Position        = 1                     ' moves device
SYMBOL  Winch           = 0                     ' spools prop

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

SYMBOL  Dump            = 200                   ' position servo
SYMBOL  Retrieve        = 120

SYMBOL  Hold            = 150                   ' winch servo
SYMBOL  Hoist           = 100

SYMBOL  HoistCount      = 640                   ' will require adjustment

SYMBOL  False           = 0
SYMBOL  True            = 1
SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

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

SYMBOL  svoPos          = B2                    ' servo position values
SYMBOL  svoWinch        = B3

SYMBOL  delay           = W4
SYMBOL  timer           = W5

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

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00000111                              ' P2..P0 are outputs

  svoPos = Retrieve                             ' initialize servo values
  svoWinch = Hold

  DEBUG "Inter-show delay", CR
  delay = 10000                                 ' inter-show delay
  GOSUB Servo_Pause

  DEBUG "Ready for trigger", CR


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  delay = 20
  GOSUB Servo_Pause                             ' refresh servos
  IF Trigger = False THEN Main                  ' check trigger input
    timer = timer + 20                          ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer


  DEBUG "Dropping prop", CR
  Strobe = IsOn
  svoPos = Dump                                 ' drop the prop
  delay = 35 * 20
  GOSUB Servo_Pause

  DEBUG "Drop complete -- wait to retrieve", CR
  delay = 3000
  GOSUB Servo_Pause                             ' hold in drop position

  DEBUG "Wait complete -- retracting", CR
  svoPos = Retrieve                             ' move to retrieve position
  delay = 25 * 20
  GOSUB Servo_Pause
  svoWinch = Hoist                              ' hoist up prop
  delay = HoistCount * 20                       ' loops to millis
  Strobe = IsOff
  GOSUB Servo_Pause

  GOTO Reset


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

' Put duration to hold in "delay" before calling
' -- servos will hold current positions
' -- best if "delay" value multiple of 20

Servo_Pause:
  IF delay < 20 THEN SD_Exit
    PULSOUT Position, svoPos
    PULSOUT Winch, svoWinch
    PAUSE 17                                    ' account for servo pulses
    delay = delay - 20
    GOTO Servo_Pause

SD_Exit:
  PAUSE delay
  RETURN

Natashead

Thanks JackMan it is working perfect, the strobe shuts off when the retrieve begins, but I like that better.

JackMan

If you want the strobe to stay on for the retrieve, just omit the line "Strobe = IsOff". When the program goes to "reset" it will turn off the strobe automatically.

Natashead

OK Thanks, this is my first prop build and you guys have been so helpful  8)