LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State Machine Demo

Any suggestions or feedback folks?
0 Kudos
Message 11 of 21
(1,346 Views)
To only enqueue when the State Operation control changes, use the event structure. If you only have the base version of LV, you will need to poll the control and compare the current value to the previous value saved in a shift register.

Here is a simple modification.

Lynn
0 Kudos
Message 12 of 21
(1,336 Views)

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

Jim

LV 2020
0 Kudos
Message 13 of 21
(1,322 Views)
  • 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). 🙂

0 Kudos
Message 14 of 21
(1,312 Views)
Hello folks,
 
Once again Thanks a LOT. Its back to the lab again. I was actually on my way to used enums instead but still using the RING for Visual appearance!
 
 
Jim/lmtis
Please find the the files for LabView ver 8.0

Message Edited by labVexpert2b on 08-16-2007 01:47 PM

0 Kudos
Message 15 of 21
(1,288 Views)


@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).


 

Message Edited by altenbach on 08-16-2007 12:32 PM

Download All
0 Kudos
Message 16 of 21
(1,279 Views)

Well folks,

I think I am done with this program in terms of general improvements.
Is there anything else that can be improved that is general that I am not thinking of.

By the way, any hints for my certification exam this coming Monday that I should be aware of?

 

Once again, Thanks A LOT for the continous support of this forum members.

0 Kudos
Message 17 of 21
(1,257 Views)
  • Delete the timeout event case. It is not used at all.
  • You might have a deadlock condition if there are several elements in the queue remaining and you place the "quit" state in the queue. In this case, the upper loop will not complete after "quit" is entered, but will never spin again and thus cannot complete. I would drop the "get queue status" completely so the upper loop completes after quit is entered. However, you need to move the "release queue" operation after the lower loop instead so it can complete all remaining operations before release.
  • It seems useless to check the queue status about one nanosecond after enqueueing an element. It will most likely never be zero, again preventing the upper loop to ever complete!
  • In this particular case, you might want to set the queue size to 1.
  • That 100ms wait in the "show table state" seems useless since you are now using an event structure.
  • I would get rid of all the coerecion dots. Just delete the offending diagram constant, right click on the disconnected terminal, "create constant", and select the desired item. If possible, eliminate the comparison and wire directly to the case structures. (as in my example above).

Good luck with the exam!

0 Kudos
Message 18 of 21
(1,249 Views)
Oh... and dont set the diagram window to be maximized to the screen and make sure the main body of the code is within the visible area.
 
(right now, most of the code is beyond the upper left corner and the window is maximized to the screen, showing large areas of whitespace on large monitors).
0 Kudos
Message 19 of 21
(1,246 Views)

Advise taken & this is my final version.
I also figured out that I can use the Re-initialize to Default InvokeNode and confirm with data flow.
Hence, I don't need to use LocalVariable to set the Ring control to the default Value.

Is this an efficient or good practise?

Message Edited by labVexpert2b on 08-16-2007 08:19 PM

Message Edited by labVexpert2b on 08-16-2007 08:19 PM

0 Kudos
Message 20 of 21
(1,241 Views)