November 22, 2024, 11:13:58 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.


prop1 programming help...

Started by mortiseman, October 09, 2008, 11:48:55 AM

Previous topic - Next topic

mortiseman

Hello! I am having some problems with writing some code for my props. I may be trying to do too much with the prop1 but I really have no clue. Here is what I am trying to accomplish...

-First I have a Dummy with a Futaba servo in the head. I want the eyes to move constantly back and forth (without being activated with a PIR).

-Second, I have a Futaba servo in the Neck of my Dummy to move the head. I would like this to activate by the TOT's with a PIR.

-Next I have a Trash Can Trauma with a 18" Stroke Air Cylinder and a 12VDC 4 Way Air Valve. This should activate after a short delay (10 sec) after the head turn.

-Finally (and this is what I am having problems with), Inside my TCT I have a pumpkin with 2 WickLED eyes. The eyes should turn on before the upstroke up the Cylinder and turn off after the downstroke.

Everything should then "reset" (except of the eyes in my dummy) and wait for the next TOT.

Here is how things are setup on my prop1

PIN6 = PIR
PIN5 = Head Servo
PIN4 = Neck Servo

OUT0 = Valve
OUT1 = 2 WickLED

I don't have any real useful code to post but the real problem I am having is with the loop that needs to be run to control the WickLED eyes...

Any help you could provide would be greatly appreciated!!!!

JonnyMac

The WickLeds are going to be the sticky bit.  Give me some time (a day or so) and I'll see what I can do.  Please understand, though, that this won't be an easy program -- managing servos with the Prop-1 or Prop-2 requires some advanced trickery; I can do it, but the program that I give you might not make sense at first or be as easy to update as most of our other programs.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

October 09, 2008, 02:13:16 PM #2 Last Edit: October 09, 2008, 02:32:22 PM by JonnyMac
Okay, here you go -- another one of these tricky "state machine" type programs.  Yes, this is the only [correct] way to do it on the Prop-1; you're wanting to interleave functionality (walk and chew gum at the same time) and that takes some programming finesse.

You didn't tell me how long to leave the valve extended so it is presently set to 10 seconds.  Also, it's not a good idea to move servos with big masses (e.g., the head) attached quickly, so there are states that move the head back and forth slowly to prevent servo breakage.  Finally, I updated the code so that the eyes go straight ahead when triggered; after reset they go back to wandering.

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


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN (PIR)
SYMBOL  Eyes            = 5                     ' P5 (servo)
SYMBOL  Neck            = 4                     ' P4 (servo)
SYMBOL  WickLed         = PIN1                  ' OUT1
SYMBOL  Valve           = PIN0                  ' OUT0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  state           = B0                    ' program state
SYMBOL  pirTimer        = B1                    ' debounce for PIR

SYMBOL  eyesPos         = B2
SYMBOL  eyesTarget      = B3
SYMBOL  eyeSpeed        = B4

SYMBOL  neckPos         = B5
SYMBOL  neckTarget      = B6

SYMBOL  timer           = W4                    ' show timer
SYMBOL  lottery         = W5                    ' random #


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

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

  eyesPos = 100                                 ' one side
  eyesTarget = 200                              ' other side

  neckPos = 100                                 ' rest position

  state = 0


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

Main:
  RANDOM lottery
  PULSOUT Eyes, eyesPos
  PULSOUT Neck, neckPos
  PAUSE 11                                      ' pad for ~20 ms

  IF timer = 0 THEN Check_Eyes                  ' skip if expired
    timer = timer - 1                           '  update timer


' ------------------
' Update moving eyes
' ------------------

Check_Eyes:
  IF state <> 0 THEN Check_Wick                 ' don't move when active

  eyeSpeed = eyeSpeed + 1                       ' update speed divider
  IF eyeSpeed < 2 THEN Check_Wick               ' check
    eyeSpeed = 0                                ' reset speed control

  IF eyesPos <> eyesTarget THEN Move_Eyes       ' at target?
    IF eyesPos = 200 THEN Target_100            '  yes, check side
      eyesTarget = 200
      GOTO Run_State

Target_100:
  eyesTarget = 100
  GOTO Run_State

Move_Eyes:
  IF eyesPos > eyesTarget THEN Move_Back
    eyesPos = eyesPos + 1
    GOTO Run_State

Move_Back:
  eyesPos = eyesPos - 1
  GOTO Run_State


' ---------------
' Update WickLeds
' ---------------

Check_Wick:
  WickLed = IsOff                               ' assume off
  IF state < 3 THEN Run_State                   ' abort if yes
    WickLed = lottery                           ' else use random bit


' ---------------------
' Process program state
' ---------------------

Run_State:
  IF state = 0 THEN Check_PIR
  IF state = 1 THEN Neck_To
  IF state = 2 THEN Head_Delay
  IF state = 3 THEN Valve_On
  IF state = 4 THEN Neck_Back

  state = 0


Check_PIR:
  pirTimer = pirTimer + 20 * Trigger
  IF pirTimer < 100 THEN Main
    state = 1
    eyesPos = 150                               ' center eyes
    neckTarget = 200                            ' turn neck
    GOTO Main


Neck_To:                                        ' takes about 1 sec
  neckPos = neckPos + 2
  IF neckPos <> neckTarget THEN Main
    state = 2
    timer = 9000 / 20                           ' delay 9 secs
    GOTO Main


Head_Delay:
  IF timer > 0 THEN Main
    state = 3
    Valve = IsOn
    timer = 10000 / 20                          ' on for 10 secs
    GOTO Main


Valve_On:
  IF timer > 0 THEN Main
    state = 4
    Valve = IsOff
    neckTarget = 100
    GOTO Main


Neck_Back:
  neckPos = neckPos - 2
  IF neckPos <> neckTarget THEN Main
    state = 0
    pirTimer = 0
    GOTO Main


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


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