November 23, 2024, 10:25:47 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


servo squencing with pneumatic

Started by vista, June 27, 2009, 06:11:54 PM

Previous topic - Next topic

vista

June 27, 2009, 06:11:54 PM Last Edit: June 28, 2009, 04:57:04 PM by vista
Hi Jon, been a while...

I can't find the program I referenced below so I'm starting this as a new topic. 

I was working with one of your many sample programs and modded it (as seen below). In it I have a servo fitted between the radius and ulna of a bucky arm and it is meant to simulate the hand going back and forth, writing a note. (I'll post a video when I finish him up) It is meant to run in conjunction with a pneumatic that moves the arm out and back which in and of itself is just a simple high/low code... (I think)

(note I'm not getting the variable code for the Valve right so it runs servo only right now)

Now to my question.. based on the code below I want the pneumatic (P) to slowly go from the low position (I plan on slow speed based on low psi 5-10) and as it is going to the high (extended) position, I want the hand to be run by the servo. then the arm will pause for a second and then return to the low position.

I guess more to the point is once the command to go from low to high is given the prop I can run the servo for (x) many times and then when the arm has reached the high position it (the hand servo) would return to the beginning position as the arm returns to the low (start) pos.

The main effect is to give the illusion that he is writing a letter.

Any pointers on the correct sequence so it all works together would be appreciated.

;D  well this is the third rewrite on the original code and the counter works and the servo is perfect. Now i'm trying to get the valve inserted. I'm going to need a hand.
I have a DC12v solenoid (4 way) that I think will plug into the output of the prop 1 without the need for the RC4. If I can find the correct parameters I'll plug them in. but right now I have the hand only working and the valve code is inop...

Thanks

Jeff
Vistaphotography


' =========================================================================
'
'   File...... Capt twitchy writing
'   Purpose... Bucky prop
'   Author.... Jeff Folger from modifed sources (mostly Jon)
'   E-mail.... jeff@vistaphotos.net
'   Started... 27 June 2009
'   Updated... 28 June 2009
'
'   {$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  Servo           = 0

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

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0
'SYMBOL  Valve           = 0                     'define variable for arm valve
SYMBOL  Baud            = OT2400


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


SYMBOL  pos             = B2                    ' position, 100 to 200
SYMBOL  tix             = B3                    ' for servo timing
SYMBOL  timer           = B4
SYMBOL  counter         = B5                    'define a variable called counter
SYMBOL  Valve           = B6                    'define variable for arm valve

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

Reset:
  DIRS = %01111111                              ' make P0-P6 outputs

  PINS = %00000000                              ' clear all outputs
  ' DIRS = %00000001                              ' make servo an output


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

Main:
  timer = 0                                     ' reset timer

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

FOR counter = 0 TO 9                           'tell the program to loop 10 times


  Valve LOW                                     ' valve starts in the low position
  valve PAUSE 500                               ' valve waits .5 sec before starting
  valve HIGH                                    ' arm extends
  valve PAUSE 1000                              ' valve waits one sec before returning
                                                ' execute commands in the loop
  pos = 150
  tix = 30                                      ' hold one second
  GOSUB Servo_Hold


FOR pos = 50 TO 150 STEP 1                      ' rotate back
    tix = 4                                     ' increase to slow movement
    GOSUB Servo_Hold


  NEXT
    NEXT

      GOTO Main




' -----[ Subroutines ]-----------------------------------------------------
  Servo_Hold:
  PULSOUT Servo, pos
  PAUSE 1
  IF tix = 0 THEN Hold_Done
    tix = tix - 1
    GOTO Servo_Hold

Hold_Done:
  RETURN

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


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


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


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


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


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

JonnyMac

Jeff,

You'll need to re-craft the program such that the servo gets refreshed every 20ms or so; if you don't then the servo will start to move on its own under the load of the arm (not what you want).  There are several demos here in the forums that show how to do "state machine" type programs on the Prop-1/2 in order to keep your servo(s) refreshed while seeming to do other things at the same time.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Okay, after looking at your program again I got really confused so I decided to port it to a state-machine -- this is not easy; it took me a couple tries to get it working.

Note that you have syntax errors in the program you listed and the editor would have flagged them had you actually tried to run the program.

This version shows how to interleave servo processing with other activities; tricky business -- this is why dedicated servo controllers are still such popular accessories.

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


' -----[ Program Description ]---------------------------------------------
'
' Trigger :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'            -- connect N.O. button between P6.W and P6.R


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Valve           = PIN5                  ' use V+/OUT5
SYMBOL  Servo           = 0                     ' use P0 (WRB)


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  state           = B2
SYMBOL  subState        = B3

SYMBOL  pos             = B4
SYMBOL  counter         = B5

SYMBOL  timer           = W5


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

Reset:
  PINS = %00000000                              ' preset IO
  DIRS = %00100001                              ' define ins & outs

  pos = 100


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

Main:
  PULSOUT Servo, pos
  PAUSE 18
  timer = timer + 20

  BRANCH state, (Wait_Trigger, Arm_Ctrl)
  state = 0


Wait_Trigger:
  Valve = IsOff
  IF timer >= 100 THEN Has_Trigger              ' valid input
  IF Trigger = IsOn THEN Main                   ' input active?
    timer = 0                                   '  no, reset
    GOTO Main

Has_Trigger:
  timer = 0                                     ' restart for next state
  state = 1                                     ' update state pointer
  subState = 0
  counter = 0
  GOTO Main


Arm_Ctrl:
  BRANCH subState, (Arm_0, Arm_1, Arm_2)
  substate = 0

Arm_0:                                          ' valve off
  pos = 100
  Valve = IsOff
  IF timer < 500 THEN Main
    timer = 0
    subState = 1
    GOTO Main

Arm_1:                                          ' valve on
  Valve = IsOn
  IF timer < 2000 THEN Main
    timer = 0
    subState = 2
    GOTO Main

Arm_2:                                          ' slow servo rotation
  pos = pos + 1
  IF pos < 200 THEN Main
    timer = 0
    subState = 0
    counter = counter + 1
    IF counter < 10 THEN Main
      state = 0
      GOTO Main


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


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


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

vista

Thanks Jon,
The original program ran as long as (the one I put together from your other posts) it was without the valve portion since I was having trouble finding something to be able to reference. (Though I need to check and make sure the posted version is the final working version)

I'll grab another Bucky and try your code out on that since the hand on the current Bucky makes it's writing motion  perfectly. (just minus the valve high/low statements).
I've got the parallax book with uses the BS-2 homework board and I've been playing with the statements there and I assume if I change out the header from BS-2 to BS-1 and save it as a BS-1 pgm then it should work... The book doesn't talk about that...

Anyway You're a life saver as always and I promise to work harder to learn this so as not to have to lean on you so much. I know you have other things you need to be doing.

Your guidance is always appreciated though..

Jeff  ;D