09-10-2009 04:26 PM
Is it time to change strategies?
I've been controlling the sequence of testing with a state machine, but the branching is getting gnarly. Now if I have to add a facet (another test) I dread redoing the logic.
See attached screen capture.
So, there are a lot of posts about state machine control, and producer consummer. But not really knowing PC structure very well, I'm not clear which would be better.
I suppose I envision a revised (major) program which:
1) Loads the test part description and based on this description, creates a list of tests to be performed in the order of which they should be performed
2) Use queue/enqueu/dequeue (is that the same as PC?) paradigm to control a state machine
3) Use intermediate results to determine of the queue list needs to cleared replaced by an "abort the rest" kind of step (due to some intermediate test failure.
Does Producer Consumer style control fit that concept?
Is there some other wat to get the program branching under control?
09-10-2009 04:41 PM
One way is to wrap up your state machine conditional statements in a subVI.
I first read about this concept in Rick Bitter's "LabVIEW: Advanced Programming Techniques". The idea is that you basically have a state and an event that you look up in a 2-D array. That will tell you what the next state is and action to take. Some state/event combinations might not have anything associated with them. The next state might just be to go back to the current state.
If you are looking at various steps that may change, you can wrap them up in an action engine. So if the next state happens to be (Move on to next step), it could call the action engine and determine what the next step is in you test sequence and return that as the next state to execute.
I haven't used this technique in any formal way myself, so I may not be doing the description justice. But it was a good book that really got me thinking about different ways to have a more flexible programming architecture.
09-10-2009 06:32 PM
Thanks Ravens Fan,
I was thinking about putting the logic in a subvi. The current state and various paramters as input, the next state as output. It would clean up the diagram, but not necessarily avoid the logic creep as I add steps. I may poke around with this concept.
I was just reading about action engine in another post, but most of the terminolgy and concepts were not clear to me.
Do you have experience with queueing/enqueuing/dequeing to control a state machine? I've been thinking about that process list idea and was wondering if it has legs. I suppose I can start messing around with the examples and tutorials to see if its a fit.
09-10-2009 06:48 PM
Pablop wrote:Thanks Ravens Fan,
I was thinking about putting the logic in a subvi. The current state and various paramters as input, the next state as output. It would clean up the diagram, but not necessarily avoid the logic creep as I add steps. I may poke around with this concept.
I was just reading about action engine in another post, but most of the terminolgy and concepts were not clear to me.
Do you have experience with queueing/enqueuing/dequeing to control a state machine? I've been thinking about that process list idea and was wondering if it has legs. I suppose I can start messing around with the examples and tutorials to see if its a fit.
In case you haven't seen Ben's Action Engine Nugget.
Most of my state machines have been simpler. A couple of calculations in line, pass it into the shift register. There is one place where I have used an architecture similar to a queued state machine.
I have a separate loop that handles serial comms with another device. I provide the loop with a queue, and before running it, I preload it with a few commands, such as Get A, Get B, Get C, where I want to continually have the loop poll the device for values A, B, and C. In the case structure for those commands, they will re-enqueue the command. Other parts of my code have the ability to execute some actions by putting their own command sets in the queue, such as Set D, data, Get E, .... these commands don't reenqueue themselves.
This gives me the ability to continually poll the the device for the values A, B, C but also allow other parts of the code to get their turn to essentially communicate with the serial device in turn. Another key command is shutdown which will allow the VISA resource to close and to flush the queue, close the queue reference and exit the loop gracefully.
With any of these commands, if I need something to happen immediately, then I enqueue that command to be put at the front of the queue to be next up.
09-10-2009 07:16 PM
Hi,
One of the first medium scale applications I helped write in LabVIEW was originally based on stacked sequence structures and filled with global and local variables. What can I say... we just didn't know any better. Thanks to a well thought out design, we never ran into the race conditions that plague most similarly written apps. But as the app grew, it became more difficult to add functionality. Over time I've ended up refactoring it as a queued state machine architecture like the one described in:
http://expressionflow.com/2007/10/01/labview-queued-state-machine-architecture/
After using this architecture for a while, I can say that it makes for very easy-to-enhance code. But the flip side is that debugging can quickly become a nightmare. I was ready to quit on it at one point, but instead I wrote a suite of VIs to do some detailed state/status logging. Once I had these, the benefits far outweighed the disadvantages. If you decide to go this route, spend some time thinking about how you are going to trace execution - particularly if your state machine is driven by events/messages generated from multiple sources.
JasonP
09-10-2009 09:32 PM
09-10-2009 09:37 PM
Your question has nothing to do with this message thread and isn't very clear.
Please don't hijack this thread. Start a new one that has a clear question and more details.
09-11-2009 12:15 PM
Jason,
In the words of Arte Johnson, "Very Interesting..."