State Machine Demo - labview
This is a discussion on State Machine Demo - labview ; Hi Folks,
 
I am a newbiew LabVIEW developer studying & working towards my CLAD certification.
I already took LabVIEW Basics I & II and I decided to make a simple state machine (please see attached VI).
I was hopping ...
-
State Machine Demo
Hi Folks,
I am a newbiew LabVIEW developer studying & working towards my CLAD certification.
I already took LabVIEW Basics I & II and I decided to make a simple state machine (please see attached VI).
I was hopping if there is anyone out there who find a way for the VI be optimized so I can see my weakness.
ThanX in ADVANCE!!!!!:smileyhappy:
StateSimulatorfromEE428.vi:
http://forums.ni.com/attachments/ni/...orfromEE428.vi
-
Re: State Machine Demo
Overly complicated and convoluted is the word.
- I haven't even tried to undestand what you are juggling with all these string operations, but there's gotta be a better way!
- Case 4 and 5 are identical except for a diagram constant. They can be comined into one case.
- "state operation" is a control, but you are constantly writing to it via local variables. This mean it cannot be reliably operated, because the set value could be reset before it is used due to race conditions.
- It is confusing that you replace the "state" of a typical state machine with a "state operation", while the "state" is actually in a string that does not really influnece operation. Whatever you have is not a state machine.
- In state operation=2 you delete from the 2D string array, but later you always seem to iterate over 9 elements (one too many to begin with) in the inner while loop.
- Since the 2D string array can shrink but never grow, you might stop the program once its size reaches zero.
- You write to a local variable in virtually each state, it would be more reasonable to pull this local variable write before the case structure.
The attached quick modification illustrates some of the above points. This is not a finished or even reasonable program. It would need a complete rewrite.
StateSimulatorfromEE428MOD.vi:
http://forums.ni.com/attachments/ni/...romEE428MOD.vi
-
Re: State Machine Demo
"Overly complicated and convoluted is the word ..."
But at least labVexpert's VI WORKS. :smileytongue:
-
Re: State Machine Demo
WOW!
Thanks a lot folks. I wasn't expecting any response until a week or two later.I am very impressed with this FORUM and most importantly the members.I just learned a whole lot from your MOD altenbach , so thanks a lot once again.I never new you can combine conditions in within a Case Structure andI like the fact where you moved the location for the State Operation.I forgot to mention this earlier but I actually wrote this code in a much betterfashion in C. I was basically trying to do the same program with LabVIEW.Nevertheless, I knew it wasn't going to be perfect but I want to have some functionalprogram that I can learn from. I knew my program was complicated but I was hoping from another set of eyes to have a look at. Anyways, I already feel indebted to you folks cause I really learned a lot already.
Once again, ThanX a lot.
-
Re: State Machine Demo
Hi Folks,
I am back after studying some more and trying to take advantage of all the things I learned so far.
Anyways, I am improved my program a whole lot and changed it drastically.
Hence, I wanted to get some feedback on what can be done to improve it programatically.
My certification exam for CLAD is going to be this Friday or next Monday so any tips for the exam
would be helpful.
Once again, thank you all for your time and input in ADVANCE!
labVexpert2B
StateSimulatorfromEE428MOD_improved.vi:
http://forums.ni.com/attachments/ni/...OD_improved.vi
-
Re: State Machine Demo
> Withregards to the sequence structure, I removed it cause I totally forgot about the error cluster.
> I actually want to enque the Ring Data only when it changes and to revert back to the default after making a selection. I am not sure how to implement this. Withregards to the the defualt State being selected, I thought that using property node would much more efficient than using a local variable. Is there any other way of implementing this?
> I know it would have been better to used Enum but I already started with the Ring and didn't want to adjust that for now.
Hopefully this is much better.
StateSimulatorfromEE428MOD_improved.vi:
http://forums.ni.com/attachments/ni/...OD_improved.vi
-
Re: State Machine Demo
LabVexpert2B,
although I have been programming in LV for several years, it has all been using what I was given to modify/maintain or figured out on my own. I'd be very interested to see both your original VI, and the latest version as a learning tool. The only problem is that I only have LV8.0. Can you save back to 8.0? If so would you post them please? Thanks, and GL on your test if you haven't already taken it.
Jim
-
Re: State Machine Demo
- You really should use an enum for the "state operation", it makes the code much more self-documenting (it took me less than a minute to change over). This makes it much less likely to mix up cases and make coding mistakes. (of course you should make it a typedef, too.)
- If a loop runs for a predetermined number of iterations, use a FOR loop instead of a While loop (e.g. in case "show garbage state"). This eliminates the repeated comparison operation and allows certain compiler optimizations.
- An event structure (as suggested by Lynn) is preferred, but you could use a simple comparison and only queue an element if the state changes. (as shown)
- Instead of a comparison followed by a TRUE/FALSE case, wire the number directly to the case. Again better self-documentation!
Here are some quick implementations of the above. I was not trying to understand your code logic. (Still think it is convoluted). 
StateSimulatorfromEE428MOD_improvedMOD.vi:
http://forums.ni.com/attachments/ni/...improvedMOD.vi
-
Re: State Machine Demo
Hello folks,
Once again Thanks a LOT. Its back to the lab again.
Jim/lmtis Please find the the files for LabView ver 8.0
StateSimulatorfromEE428MOD_improved_v8.vi:
http://forums.ni.com/attachments/ni/...improved_v8.vi
StateSimulatorfromEE428_v8.vi:
http://forums.ni.com/attachments/ni/...romEE428_v8.vi
StateSimulatorfromEE428MOD_by_altenbach_v8.vi:
http://forums.ni.com/attachments/ni/...ltenbach_v8.vi
-
Re: State Machine Demo
labVexpert2b wrote:
I was actually on my way to used enums instead but still using the RING for Visual appearance!
Using a few mouse strokes in the control editor, both can be made to look exactly the same. 
(This is just a draft. Probably needs a few more tweaks).
<img src="http://forums.ni.com/attachments/ni/170/265920/2/RingvsEnum.png">
Message Edited by altenbach on 08-16-2007 12:32 PM
RingvsEnum.vi:
http://forums.ni.com/attachments/ni/.../RingvsEnum.vi
RingvsEnum.png:
http://forums.ni.com/attachments/ni/...RingvsEnum.png
Similar Threads
-
By Application Development in forum DOTNET
Replies: 0
Last Post: 12-06-2007, 06:18 AM
-
By Application Development in forum labview
Replies: 1
Last Post: 12-04-2007, 05:40 AM
-
By Application Development in forum labview
Replies: 1
Last Post: 11-28-2007, 10:40 PM
-
By Application Development in forum verilog
Replies: 4
Last Post: 03-28-2007, 12:32 PM