Shop OBEX P1 Docs P2 Docs Learn Events
Dispensing Capsules — Parallax Forums

Dispensing Capsules

RGR_EngineerRGR_Engineer Posts: 18
edited 2009-12-04 07:14 in BASIC Stamp
I am trying to program a machine to dispense 2 halves (Male and Female) of plastic capsules after a button is pressed. I have an arm that pushes the stack of capsules which opens the connection of the tabs that are keeping the capsules in place. Once a single capsule is released, the tabs close and the motors stop until the button is pressed again. If the pusher arm reaches the bottom it hits a limit switch and backs off. I have the hardware working correctly, the emergency (limit) switch working correctly, and I can get it to dispense the male half, but then it just turns the motor for the female half on and off really quickly without dispensing. I have gotten the program to work successfully with just the male capsule or just the female capsule. My code is attached as well a a picture of the system. I am not very experienced with programming, so any advice would be great!

Also, is there any way to get these two subroutines to execute simultaneously? Maybe using a different method than I have used?

Thanks!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Tara

Post Edited (RGR_Engineer) : 12/2/2009 11:07:20 PM GMT
1896 x 995 - 131K

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-12-02 23:20
    It would help you a lot if you could draw a state transition diagram for your system. From there it's a simple matter to convert it to PBASIC code using CASE statements.

    -Phil
  • RGR_EngineerRGR_Engineer Posts: 18
    edited 2009-12-02 23:25
    I'm sorry, I am still new at this; What exactly is a state transition diagram?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Tara
  • RGR_EngineerRGR_Engineer Posts: 18
    edited 2009-12-03 00:08
    Oh, ok. I'm just not familiar with the terminology. I created the diagram that's attached prior to writing the code, but it doesn't seem to be helping.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Tara
  • LeonLeon Posts: 7,620
    edited 2009-12-03 00:27
    That's a flowchart, not a state transition diagram.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
  • SRLMSRLM Posts: 5,045
    edited 2009-12-03 01:23
    First, you cannot have a line split into two lines. A line ('state transition') must go from one state to another without splitting. Second, all outputs are associated with a particular state (or state transition in a different type IIRC). I notice that you only have it once, at the start. Unless that is the only time that you control an output you need to add some more. Secondly, you don't have "decisions" in states. Instead, the state transition lines should be labeled with the condition on which they are followed. Each state ('bubble') should have only one path be true at any time.

    Don't worry if it takes a while to learn state diagrams. They are generally take a couple of lectures to introduce (in my experience).
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-12-03 07:12
    Tara,

    Don't be deterred. Your flowchart/transition diagram is a good start. Here's how I would suggest structuring your program. It will make a lot more sense to you, I think, if you look at it in these terms:

    START     CON 0
    MALE_ON   CON 1
    MALE_OFF  CON 2
    FEM_ON    CON 3
    FEM_OFF   CON 4
    
    State     VAR Nib
    
    State = Start
    
    DO
      SELECT State
        CASE  START:
          IF (Trigger) THEN
            'Motor on
            State = MALE_ON
        CASE MALE_ON:
          IF (Limit) THEN
            'Reverse direction
          ELSEIF (Closed) THEN
            State = MALE_OFF
        CASE MALE_OFF:
          '...
      ENDSELECT
    LOOP
    
    
    


    -Phil
  • RGR_EngineerRGR_Engineer Posts: 18
    edited 2009-12-03 16:24
    So I tried this (see attached) and instead it just turns on while the trigger is being held down instead of starting the process when the trigger is pressed. I'm not familiar with using CASES, did I do this correctly?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Tara
  • RGR_EngineerRGR_Engineer Posts: 18
    edited 2009-12-03 16:45
    Thanks for all your help. I was actually able to get it working with the original code I posted, I had just switched "goto push4" and "goto push5". But can anyone tell me how to get these two functions (male and female dispensing) to run simultaneously?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Tara
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-12-03 17:33
    I would try to get one working using the state transition method first. Then you can have two states: MState and FState, with a SELECT CASE section for each inside your DO LOOP. That way both units can run simultaneously.

    -Phil
  • RGR_EngineerRGR_Engineer Posts: 18
    edited 2009-12-03 17:38
    Ok. I will work on that. Thank you for your help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Tara
  • skylightskylight Posts: 1,915
    edited 2009-12-04 04:12
    Not sure if it will make a difference or not but noticed in your program you have a capital R for rev in the I/O connections assignment for pin 10 but you dont use capital R elsewhere, whether this mismatch affects labelling of the pin i'm not sure?

    Post Edited (skylight) : 12/4/2009 4:17:56 AM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-12-04 04:29
    No. PBASIC is case-insensitive.

    -Phil
  • skylightskylight Posts: 1,915
    edited 2009-12-04 07:14
    Phil Pilgrim (PhiPi) said...
    No. PBASIC is case-insensitive.

    -Phil
    Thanks Phil, I wasn't aware of that
Sign In or Register to comment.