Discussion:
controls and event structure
(too old to reply)
krispiekream
2008-08-05 18:40:05 UTC
Permalink
i currently have a while loop that works by data flow. i am hoping to change this work as a while loop and inside the while loop. it will have an event structure. currently, if SINGLE STEP is TRUE.then it will enter a manual programming mode.if i press CONTINUE. it will go back to auto modeif i press ADV. it will skip the current postion.if i press stop. it will stop at the current positionif i press ADV&STOP. it will stop the programif I press ADV&STOP&DELETE. it will stop and delelete the current log file.i dont know if anyone can point me to the right direction. it seems like its impossible?


CONTROLS and event structure.vi:
http://forums.ni.com/attachments/ni/170/346811/1/CONTROLS and event structure.vi
GerdW
2008-08-05 19:10:23 UTC
Permalink
Hi krispiekream,from your description it seems you should rather look for a state machine architecture...And you still use too much locals! And maybe you should also look at the "compound arithmetic", as it can add/multiply/AND/OR multiple inputs...And please don't hide terminals far far away from the main part of the block diagram. Use those terminals to avoid locals!See attachment with changes and comments:smileywink:Message Edited by GerdW on 08-05-2008 09:09 PM


CONTROLS and event structure.vi:
http://forums.ni.com/attachments/ni/170/346838/1/CONTROLS and event structure.vi
krispiekream
2008-08-05 21:10:05 UTC
Permalink
thanks for your help! i see that there is anot i have to learn. i just want to clean up my codes.but from the look of what i used to have. this is so much better.let me send you the full code and see if you can add any comments for me.i need help the most ending the two loop. i dont  know if i should get rid of those local variables since they control how the program will end.


program.vi:
http://forums.ni.com/attachments/ni/170/346880/1/program.vi
krispiekream
2008-08-05 22:40:05 UTC
Permalink
looking at this image. i think its safe for me to remove the flat sequence?just making sure?<img src="Loading Image..."> Message Edited by krispiekream on 08-05-2008 05:27 PM


untitled6.PNG:
http://forums.ni.com/attachments/ni/170/346913/1/untitled6.PNG
johnsold
2008-08-06 00:40:05 UTC
Permalink
Certainly the one on the right. Dataflow assures that the while loop is finished before the Press to Continue executes and that will be done before the case structure at the left. The one on the left? I cannot tell from the picture. The cluster wire coming in to the Bundle by Name comes around the inner case structure. If you put the True constant inside that case structure (all cases or wired through all cases), then neither the Bundle by Name nor the local variable would need to be in the sequence.Lynn
krispiekream
2008-08-06 00:40:06 UTC
Permalink
thanks Lynn, I have attached my program here.can someone have a quick look to see if there is anything else i can do to make it better. the end of the loop especially.i dont know if my block diagram is too long. i am thinking that i should make subvi to reduce the diagram sizes by the local variables to display in the frontpage is killing me. also, i dont know what to do with the local variables of the control.i can't use wires because i noticed that my problem doesn't run PROBABLY when i run the wires. when the user press the control button, the wire doesnt remember it.i hope its clear.


program.vi:
http://forums.ni.com/attachments/ni/170/346928/1/program.vi
GerdW
2008-08-06 19:40:06 UTC
Permalink
Hi krispiekream, at the moment I can't save back to LV7, so all I can do is giving some textual comments:- at "delay to stabalize system"/"measure tempearature" you write the temp to the cluster, but then you don't use that changed cluster and so "forget" about this change...- you write to "error out" locals 22 times! But then at the end of your program you write to the terminal after those file functions and all the previous error states are lost... (typical race condition)- when using "index array" with index=0 you don't need to wire a zero constant; when indexing consecutive elements you only need to wire the first index- enable "auto grow" on all structures to avoid hiding block diagram elements... Use left-to-right wiring when other people should analyze your code!- use compound arithmetic instead of all those NOT/AND instructions...- use matching datatypes for indicators to avoid coercion (unless there's a reason to do so)- at the right side of the big (light green?) loop there a construct of "index array(array size)" - this will fail every time as the last element of an array of size n has the index n-1!- you can use the case selector as an input to the case structure: you can avoid a lot of (TRUE) constants this way- make (more) subvis as the block diagram is way to big to get an overview- in the init while loop (yellow colored) you have a case structure having only one case "0, default" - what is it good for? (Rube-Goldberg code)Well, now it's getting late and I need to recover for the next day:smileywink:
krispiekream
2008-08-06 19:40:07 UTC
Permalink
i have labview 8.5 also in my laptop. maybe i can see it from there?
GerdW
2008-08-06 20:40:05 UTC
Permalink
Hi krispiekream,now it's enough for today, see attachment!And I found the classical Rube-Goldberg (atleast) two times: if TRUE then TRUE else FALSE :smileyvery-happy::smileyvery-happy::smileyvery-happy:Don't forget: all the previous comments still apply!Message Edited by GerdW on 08-06-2008 10:15 PM


program.vi:
http://forums.ni.com/attachments/ni/170/347275/1/program.vi
krispiekream
2008-08-06 20:40:07 UTC
Permalink
you can use the case selector as an input to the case structure: you can avoid a lot of (TRUE) constants this way
can someone show me a diagram of what a case selector it? i tried looking it up in the HELP. but i couldnt find it.thanks
GerdW
2008-08-06 20:40:08 UTC
Permalink
Hi krispiekream,did you look at the attachment? There are examples in it. All my comments are in red! But anyway, here's an example:<img src="Loading Image..."> :smileywink:Message Edited by GerdW on 08-06-2008 10:27 PM


case.png:
http://forums.ni.com/attachments/ni/170/347284/1/case.png
krispiekream
2008-08-06 21:40:05 UTC
Permalink
yeah. i have looked at the examples. they are really great.thank you for taking your time and yeah. its enough for today. :smileyvery-happy:i am having a problem making subvi for my block diagram to make it smaller. i dont like to use REFERENCES?is it good LABVIEW Practice to create subvi with references?Message Edited by krispiekream on 08-06-2008 04:22 PM
GerdW
2008-08-07 06:40:06 UTC
Permalink
Hi krispiekream,references are created when you have terminals/locals inside the part making the subvi. Move them outside of your subvi part to avoid references...By removing all (unneeded) locals you also avoid to create references:smileywink:References aren't bad (or good) - they are a way of programming. They have their advantages as well as disadvantages..."Good practice": there are situations when you need the reference, i.e. manipulating a graph display from a subvi.But in your case I think it's different due to overuse of locals, so making references "bad practice".Message Edited by GerdW on 08-07-2008 08:13 AM
krispiekream
2008-08-07 17:40:07 UTC
Permalink
great advices. after llooking at my code. what do you recommend me to do with the PRESURE/PRESSURE 2 local variables? i have to have them in order to display in the front panel.do you have any suggestion to get rid of them?
johnsold
2008-08-07 18:40:05 UTC
Permalink
Those are easy. Once you get reorganized to a state machine architecture then the Pressure and most other indicators can be managed via the big cluster you are passing around. I spent some time (way too much time, actually) revising your program to illustrate some of the things that several of us have been suggesting to you.Your diagram was over 15000 pixels wide! I reduced it to much less than that , although it is still much too wide. The goal is to fit it on one screen.It is partially converted to a state machine. The Call Module case structure you have is actually a simple state machine. By combining it with what I have shown at the left side of the outer while loop, you can build something that may work well. I added comments at various points in the code - background colored with some obnoxious shade so you can find them.I set it up so that when the buttons on the panel are pressed, the event loop sends a command via a queue to the main loop. The commands are a typedef enum.What I sent will not work. It is incomplete and I do not know what much of your program was intended to do. Because I did not have most of the subVIs, it will complain and ask you to help find them when you first open it.I think you will be able to eliminate almost all of the locals and probably most of the globals.Lynn


CONTROLS and event structure.2.vi:
http://forums.ni.com/attachments/ni/170/347633/1/CONTROLS and event structure.2.vi


Command.kk.ctl:
http://forums.ni.com/attachments/ni/170/347633/2/Command.kk.ctl
krispiekream
2008-08-07 19:10:05 UTC
Permalink
wowwwwwwwwwwwwwwww, that is some nice sh*t. i have never worked with something this good so i don't know if i can get it to work. thank you for taking the time to do this. i never had better teachers then you guys.but actually, you helped me modified the Controls and events subvi which is part of the program.and the PROGRAM.VI is the whole program. but i'll see if i can pull it off. its a great start for me. Message Edited by krispiekream on 08-07-2008 01:54 PM


program_2.vi:
http://forums.ni.com/attachments/ni/170/347636/1/program_2.vi
krispiekream
2008-08-07 20:40:08 UTC
Permalink
maybe you can see if i am heading to the right direction?


program_mod3.vi:
http://forums.ni.com/attachments/ni/170/347674/1/program_mod3.vi
johnsold
2008-08-07 21:10:05 UTC
Permalink
I only had a few minutes to look. I think you are getting some of the ideas, but it is hard to tell for sure because the program is so big.One concern: In the event structure you do not want any code which is time consuming. For example the Timeout case has the Simple Error Handler.vi. If an error occurs this will pop up a dialog and lock up that case until the user responds. While this may not be all bad for errors, generally you do not want any code in an event case which takes more time to run than the minimum possible time between events. This means: No dialogs. No file I/O. No hardware I/O. No FFTs. No nodes with time delays, waits, or timeouts. No printing. This is why I put the enqueue functions in most of the cases. All the event structure does is detect user events and tell some other part of the program what to do about it. The actual "doing" is done elsewhere.The initialization, temperature cycling, pressure cycling, graphing, and shutdown at the end of the program can all be in one loop. Each will represent one or more states in the state machine.Lynn
krispiekream
2008-08-07 21:40:07 UTC
Permalink
no printing? hmmm, what do you suggest? should i have another while loop like that one you have in parallel with the one that have the PRINTING? so it would be 3 while loops.i'll continue working on it. but i dont really understand why i am doing his.so once the BOOLEAN IS PRESSED IN YOUR STRUCTURE OF PROGRAM. it VALUE changed.and it will release the queue to the CASE for it?
krispiekream
2008-08-07 22:10:07 UTC
Permalink
alright, i am lost now. i have 2 while loops. one for temperature cycling, the other is for pressure cycling.i dont know if what i am doing will be like what i had.
krispiekream
2008-08-07 22:40:05 UTC
Permalink
i remember how state machine work when i was doing undergrad. lets say the first state is to initilize. then the second state would be to set temperature/cyclying or whatever.once i am done with that. i would go to the next state which is to cycle pressure.then go to another state of changing the temperature if its called for. and then end the program.but i dont understand how do i tell the program to do the next state. Message Edited by krispiekream on 08-07-2008 05:21 PM


program_mod41.vi:
http://forums.ni.com/attachments/ni/170/347705/1/program_mod41.vi
krispiekream
2008-08-08 00:10:04 UTC
Permalink
here is my latest version. its not working becuase i dont know if it went in the order i wanted to. it doesnt display in the front page like i intended.i need more help..please..


program_mod5.vi:
http://forums.ni.com/attachments/ni/170/347716/1/program_mod5.vi
GerdW
2008-08-08 19:10:06 UTC
Permalink
Hi krispiekream, some more comments on coding style:- make ALL subvis use a proper connector scheme: connect controls on the left side of the terminal block, indicator go right side; use standard 4224-pattern (if possible)- put bundling/unbundling nodes inside the according subvi, simply wire the big cluster through the subvi (same like error cluster)!example:


style1.png:
Loading Image...
GerdW
2008-08-08 19:40:06 UTC
Permalink
continued here (I was to slow...) <img src="../../attachments/ni/170/347958/2/style2.png">(well, think of your subvis instead of the file functions...) Much much cleaner, easier to wire - all stuff belonging together is put in one place and hidden in the subvis...Rethink use of locals: do they have to be updated in each iteration of loops or would it be ok after the loop?As
told before: you copy all values inside that big cluster. Once you have
a state machine architecture you manipulate that cluster in each case
and only update controls/indicators after each state is finished, thus
requiring (nearly) no locals.
krispiekream
2008-08-08 20:40:05 UTC
Permalink
thanks for the help..i'll rework all my bundle/unbundle so that it would be in the correct way. right now. i am having a hard time from here to reorganize thing in a STATE MACHINE pattern..i have looked up simple state machine examples but its nothing like what i have. so i dont know where to start since i have init state, control state, and temperature and pressure state in one big loop. i am pretty lost as of how to convert my current program to work with the state machine.
Continue reading on narkive:
Loading...