PDA

View Full Version : Dispensing Capsules



RGR_Engineer
12-03-2009, 06:34 AM
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

Phil Pilgrim (PhiPi)
12-03-2009, 07:20 AM
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_Engineer
12-03-2009, 07:25 AM
I'm sorry, I am still new at this; What exactly is a state transition diagram?

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

Phil Pilgrim (PhiPi)
12-03-2009, 08:00 AM
Here are some references for state transition diagrams:

en.wikipedia.org/wiki/State_diagram (http://en.wikipedia.org/wiki/State_diagram)
en.wikipedia.org/wiki/Finite-state_machine (http://en.wikipedia.org/wiki/Finite-state_machine)
www.cs.unc.edu/~stotts/145/CRC/state.html (http://www.cs.unc.edu/~stotts/145/CRC/state.html)
yourdon.com/strucanalysis/wiki/index.php?title=Chapter_13 (http://yourdon.com/strucanalysis/wiki/index.php?title=Chapter_13)

-Phil

RGR_Engineer
12-03-2009, 08:08 AM
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

Leon
12-03-2009, 08:27 AM
That's a flowchart, not a state transition diagram.

Leon

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM

SRLM
12-03-2009, 09:23 AM
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)
12-03-2009, 03:12 PM
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_Engineer
12-04-2009, 12:24 AM
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_Engineer
12-04-2009, 12:45 AM
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)
12-04-2009, 01:33 AM
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_Engineer
12-04-2009, 01:38 AM
Ok. I will work on that. Thank you for your help.

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

skylight
12-04-2009, 12:12 PM
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)
12-04-2009, 12:29 PM
No. PBASIC is case-insensitive.

-Phil

skylight
12-04-2009, 03:14 PM
Phil Pilgrim (PhiPi) said...
No. PBASIC is case-insensitive.

-Phil
Thanks Phil, I wasn't aware of that