Performance of state machine with enum vs string?

I am laying out the groundwork for a very large state machine. It will have about 60 to 100 states. I kind of want to use an enum for selecting the states for convenience. But then if I use a string I can use Jim Carmody's case select tool so that wins out in convenience in one respect.
One concern about using a string is performance. Since an enum is just an integer wouldn't the selections perform better? I need to squeeze out every ounce of performance and in fact this state machine will be set for subroutine priority. Another concern that I have about a typedef enum is that I have heard something about the possibility of them getting "out of sync" between VIs when you edit them. Is there some way to avoid that, such as making sure all VIs that use this typedef are in memory when editing it?
=====================
LabVIEW 2012

Steve Chandler wrote:
As for the number of states, I am pretty sure that it has to be one state machine. I'm afraid I cannot give a lot of details.
I am having trouble figuring out the "has to" part.
See this thread for designs I have posted previously.
In this SM
please look the section that is entered from "Change Request 8 " can take multiple paths but all ends at "Stop Monitoring? 15". I could have implemented that as a sub-SM and it would have reduced the number of state required for that part of the work from five to one.
Any time I see "single entry, fan out, merge" I think sub-SM.
This could also help with your shift register as well because (again seea bove) the bulk of the ose states deal with Logging so rather than use a SR, put what would have been in the SR (file path or ref) to be used there OR possibly an AE that can be used in each of those states.
So I still don't understand why sub-SM aren't a possiblity.
Trying to help,
Ben 
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction

Similar Messages

  • An example of a state machine with transition array?

    I am looking at state machine design patterns and am interested particularly in a state machine with boolean trasition array which defines the next state to be executed using an array. Here, the index of the first “True” boolean in the boolean array corresponds to the index of the new state in the array of enums. Has anyone got an example of this design pattern as it would greatly help in my understanding of it. Refer to figure 3c in http://zone.ni.com/devzone/cda/tut/p/id/3024#toc2 for clarity on what i am asking for.
    Thanks in advance.

    That seems like a lot of extra work. Why not just use a queue, and queue up the enum you want to go to next? Look up examples on queued state machine. No need for an array and then a boolean to index that array. here is an example
    CLA, LabVIEW Versions 2010-2013

  • Need help created state machine with timed digital output

    Hello everyone I'm new in LabView especially about how to make a state machine. I want to make simulation about state machine with digital output. In Front Panel there are volt_in as an input slider (0-10 V), two numeric control (upper limit and bottom limit), a waveform chart to plot those 3 value, and three boolean (P0.0, P0.1, P0.2) as an indicator. Boolean indicator will on if input from slider exceed the limit in certain situation. This simulation will work as follow:
    1. Define the upper & bottom limit (ex. 8 & 4V)
    2. Make an input from slider (0-10V)
    3. If input (2) exceed the upper limit but less than 10 second (ex. you have 9V input for 8 second, but after 8 second you change the slider back to normal between 4-8V) then the boolean indicator P0.0 & P0.2 will stay off
    4. If input (2) exceed the upper limit more than 10 second (ex. you have 9V input for 4 second, change to 8.5 V for 3 second, and then change to 10V for 3 second) then the boolean indicator P0.0 will turn on for 5 second, turn off, then follow by indicator P0.2 for 5 second, and turn off
    5. Wait 15 second, then repeat process from (2)
    Same process for input that exceed the bottom limit (P0.1 and P0.2 as indicator).
    Can you help me make the block diagram of this process? I will appreciate any of your help.
    Best Regards
    juventom 
    Attachments:
    State Machine Digital Output.vi ‏28 KB

    I would highly recommend you to open the template in LabVIEW to design state machines. You can the Standard State Machine template if you go to File -> New.. and Browse to VI -> From Template -> Frameworks -> Design Patterns.
    Also, here is a good explanation of one:
    https://decibel.ni.com/content/groups/northeast-oh-labview-users/blog/2009/09/08/state-machines
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies

  • Shutting down a queued event state machine with multiple parallel loops

    I am trying to find the best way to shutdown a program that consists of a queued event state machine architecture with multiple parallel loops. Can anyone recommend the best way to accomplish this in my attached VI? (From browsing the forum, this seems to be a common question but I haven't found a solution that works for me.)
    I welcome any other feedback on my code as well, if anyone is willing to offer it.
    My Program Requirements:
    If the user presses the "Shutdown" button, the program should prompt the user with "Are you sure you want to stop the program?" and then either return to the Idle state or proceed to stop the program. Additionally if there is an error, the program should prompt the user with "Clear error and continue, or Stop program?" Then either return to the Idle State or proceed to stop the program.
    Details of architecture:
    The program consists of 3 parallel loops: (1) an Event Handling loop that enqueues various States to a State Queue, (2) a State Machine which enters the latest state that is dequeued from the State Queue, and (3) an Error/Shutdown handling loop which processes any errors in the Error queue.
    During normal Shutdown, in the Event Handling loop the "Program.Shutdown" event case executes, and the States "Shutdown" and "Idle" are added to the State Queue. In the State Machine, the "Shutdown" state is invoked. A special error code "5000" is added to the Error Queue. In the Error/Shutdown handling loop, the "5000" error triggers a prompt that asks the user if they want to stop the program. If the user chooses not to stop, a notifier StopNotif is sent to the "Shutdown" state and "Program.Shutdown" event case with the notification "Go". If the user chooses to stop, the notifier sends the notification "Stop". The Event handling loop and State Machine are terminated if they receive the notification "Stop".
    In case of error, the program behaves similarly: if the user chooses to clear the error and continue, the program returns to the "Idle" state.
    HOWEVER - if the user chooses to stop the program, the program stalls. The notifier that is sent to stop the Event Handling Loop and State Machine cannot be read because the Program.Shutdown event case and the Shutdown state (which contain the "Wait for Notifier" function) are not active.
    I have been able to activate the Shutdown state by enqueuing it in the Error/Shutdown handling loop. But I don't know how to activate the "Program.Shutdown" event programmatically, and thereby access the "Wait for Notifier" function inside it.
    I tried to place the "Wait for Notifier" function outside the event structure, but then the Event Handling loop never completes. Placing timeouts on the "Wait for Notifier" and on the Event structure makes the program work, but I want to avoid using timeouts because I don't want to turn my event-driven program into a polling-based program. I'd also like to avoid using variables or property nodes to stop the loops, because that requires creating a control/indicator for something that the user doesnt need to interact with.
    Thank you!
    Solved!
    Go to Solution.
    Attachments:
    Queued event state machine parallel loops empty.vi ‏46 KB

    Thanks for clarifying that, Ravens Fan.
    I marked crossrulz as the solution for pointing out User Events to me.
    I also adopted Ravens Fan's suggestion to keep the Shutdown procedure out of the Error Handling Loop. This has simplified the architecture by eliminating the need for Notifiers. Instead, I have used booleans in case structures to stop the Event Loop and State Machine, and Release Queue to stop the Error Handling Loop.
    For reference, I'm attaching my corrected code.
    Thank you to everyone who helped!
    Attachments:
    Queued event state machine parallel loops empty in progress.vi ‏44 KB

  • Problems closing several loops in a state machine with an event structure

    I am having some problems closing three loops running in parallel in a state machine.  I have one loop for an event structure to monitor user controls to change the state.  The other loop is the state machine which will control an actuator, and the third loop is for data aquisition/analysis.  I want to be able to hit the stop button and go to a "shutdown" state where I can home the actuator then close the loops and finally go to the last "shutdown" subdiagriam in the flat sequence structure.  Currently when hitting the stop button it goes into the shutdown state and will end the state machine loop but it appears the other loops are not closing until I hit the stop button again.  Could this be due to using a local variable for the boolean to control the loop conditions? I attached a screenshot of the block diagram.  Any advice would be great!
    Attachments:
    example.png ‏108 KB

    You have a classic race condition due to overuse of local variables. If the stop event fires in the upper loop, the local variable connected to the loop termination condition has already been read (it is false!). This means that the upper loop will iterate once more and again wait at the event structure for the next event. At this time, the local variable connected to the loop termination is TRUE, but the loop cannot complete until the event fires again, for example if you press the stop button once more.
    The correct way is to connect the terminal of the stop button across the right event frame directly to the loop termination terminal. Now it will get the TRUE value correctly once the stop event fires for the first time.
    LabVIEW does not execute left to right, execution order is determined by the wiring.
    I also agree with the above message that you should rethink and re-architect your code using established coding guidelines. 
    LabVIEW Champion . Do more with less code and in less time .

  • State machine with using event case

    Hallo everyone,
    i have a question about how to realize the "Timeout". In the flow diagram below we can see 2 different situation:
    1. in the 1st Situation i have used the state machine, it begins at state 1, which contains a event case. In there it will be at first determined, if the input value has changed within 10 second,  if it didn't, the state machine will go to state 2, if it 's  changed, will be furthermore determined, whether the input value equal to 3, if yes, the state mashine will jump to state 3, if no, jump back to state 1. (this VI i have done before, you can take a look at the Attachment).
    2. my question is in the 2nd situation. It begins also at state 1. In there the input value can also be changed (once or many times) or not. If the value has not been changed within 10 s, or even though it's been changed many times within 10s, but  it's never been equal to 3, the state machine will go to state 2; only when the input value within 10s equal to 3, it can jump to state 3.
    This problem i have no idea how to solve, does anybody have  idea or better methods?
    thanks a lot!!
    Solved!
    Go to Solution.
    Attachments:
    situation 1.vi ‏12 KB

    The statement in the OP is not covering all cases.
    mexaviesta wrote:
    2. my question is in the 2nd situation. It begins also at state 1. In there the input value can also be changed (once or many times) or not. If the value has not been changed within 10 s, or even though it's been changed many times within 10s, but  it's never been equal to 3, the state machine will go to state 2; only when the input value within 10s equal to 3, it can jump to state 3.
    This problem i have no idea how to solve, does anybody have  idea or better methods?
    thanks a lot!!
    Just check my implementation for Situation 2 and let us know, if it works for you.
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.
    Attachments:
    Situation 2.llb ‏40 KB

  • Using "Enum constant" in state machine.

    hallo all.
    i bild state machine, with 10 states. i move beetwen the states with Enum constant.
    my qustion is: if i want to add/delete some  states, why i need to update the Enum constant at every state ?
    there is  way to update "Enum constant" at one state, and  all other "Enum constant"(in other states) will update automatically
    thanks

    If you save you enum as a type def and replace all of the current occurences of the enum wi the type def, you shoud there after only have to update teh typedef.
    1) Find an oocurance of the enum
    2) Right-click and change to control.
    3) Find control and select Advanced customize
    3) Pull down on selector and change from "control" to "type def"
    4) Save control.
    5) close editor and when prompeted say yes to replace control.
    6) Change control back to constant
    7) replcae all previous occurances by choosing replace >>> the typedef'd control.
    8) Case structure will folow typed def from that point forward.
    Ben
    Message Edited by Ben on 12-24-2006 03:31 PM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Help me with a state machine design

    I have a little bit of a problem.  I have a system with several modes, each selected by the user and called with a case structure.  Each case in the case structure is its own state machine with a few states (like 4-6).  Now here's the catch.  I need one of the states within one of the modes to call and execute an entirely different mode (and all of its states) without actually changing the mode command, and to do so every iteration until I jump out of that state into another state within the first mode.
    Is there a simple way to do that that I'm just not thinking of?
    Lee Jay

    Lee, my first thought would be to use just a big state machine.  For example if each mode needs 4 states, mode 1 gets states 0-3, mode 2 get states 4-7, and so on.  This way, if you need to change modes in the middle of another mode, you just direct the state selector to the state that starts the mode.  (If that makes sense).  It's not real elegant, but it works fairly well as you still maintain the flexibilty of the state machine design, including the ability to add and rearrange cases. 
    Don't forget you can use any method to select the cases, including strings, so you have full flexibility with how you setup case select.
    Troy

  • How to use elapsed time function with state machine in Lab VIEW

    Hello
    I've been trying to use state machine with elapsed time function in order to sequentially start and stop my code. The arrangement is to start the code for 1 minute then stop for 5 minutes. I've attached the code, the problem is when I place the elapsed time function out of the while loop it doesn't work, on the other hand when I place it inside the loop it does work but it doesn't give the true  signal to move to the next state. 
    Could you please have a look to my code and help me to solve this issue.
    Regards 
    Rajab
    Solved!
    Go to Solution.
    Attachments:
    daq assistance thermocouple(sate machine raj).vi ‏436 KB

    Rajab84 wrote:
    Thanks apok for your help
    even with pressing start it keeps running on wait case 
    could you please explain the code for me, the use of Boolean crossing, increment , and equal functions 
    Best Regards 
    Rajab 
    OK..I modded the example to stop after 2 cycles. Also recommend taking the free online LabVIEW tutorials.
    run vi. case statement goes to "initialize", shift registers are initialized to their constants. goto "wait"
    "start"= false, stay in current state. If true, transition to "1 min" case
    reset elapsed timer with True from shift register(counter starts at zero)."time has elapsed"=false, stay in current state(1 min). If true, goto "5min" case
    reset elapsed timer with True from shift register of previous case(counter starts at zero)."time has elapsed"=false, stay in current state(5 min). If true, goto "1min" case. Also, bool crossing is looking for "true-false" from "5 min" compare function to add cycle count.
    Once cycle count reaches 2, stop while loop.... 
    Attachments:
    Untitled%202[1].vi ‏42 KB

  • Double Click Property Node not functioning with Queued State Machine

    I am writing an application which relies on input from the operator to start different steps in a process of steps.  I am using a queued state machine, however I cannot get the Double-Click property of my listbox to function with in this Queued state machine.  I have tried Creating a refrence to the Listbox and creating a property node from that refrence.  I have tried a property node of the control.  The double click functon works only if the queueing is not occuring.  It has something to do with the queue but I am at a loss as to what is causing it.  Any help would be GREATLY appreciated.  I have attached a simplified version of the state machine with the double click function.  Thanks for any help on this.  It is written in LV7.1
    Attachments:
    Test Q.llb ‏55 KB

    Hi
    Its  Simple....
    Your Properrty node is not getting read..... dont understand how..
    see the attachment...
    now laugh at your small mistake... (even i have the habbit of making such small mistakes ;-) )
    Message Edited by Tushar Jambhekar on 01-11-2006 11:38 AM
    Tushar Jambhekar
    [email protected]
    Jambhekar Automation Solutions
    LabVIEW Consultancy, LabVIEW Training
    Rent a LabVIEW Developer, My Blog
    Attachments:
    Test Q.llb ‏55 KB
    Picture.JPG ‏44 KB

  • Adding multiple states in state machine

    Hi all,
    I have a state machine with many states.  I am using an enum to select state.  I didn't add all the state in the enum at the beginning, so I am adding more statess to the enum and to the state machine as I go.  I found the following pretty troublesome.
    If after I made the first 3 state, and I realized that that next 3 states are very similar to the first 3 states.  I want to copy duplicate the first 3 case all at once, instead of duplicating one case at a time.
    If I duplicate one state, and the wrong enum is assigned to the state, is there a quick way to change it? 
    Are their anything out there that would help plan and keep track of the state machine?
    Let me know if you have any cool tips to speed up state machine development, especially topic on enum and case structure (adding, deleting, multiple copy, etc).
    Yik
    Kudos and Accepted as Solution are welcome!

    jyang72211 wrote:
    after I made the first 3 state, and I realized that that next 3 states are very similar to the first 3 states.  I want to copy duplicate the first 3 case all at once, instead of duplicating one case at a
    If at all possible, never copy and paste code that is very similar to another piece of code! Try to write modular code. If there are several states that are almost identical except for a few slight differences, wrap those differences in a small case structure within the case.
    If you ever find yourself tempted to copy and paste a diagram of code that is larger than a POSTAGE STAMP, reconsider!
    a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"] {color: black;} a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"]:after {content: '';} .jrd-sig {height: 80px; overflow: visible;} .jrd-sig-deploy {float:left; opacity:0.2;} .jrd-sig-img {float:right; opacity:0.2;} .jrd-sig-img:hover {opacity:0.8;} .jrd-sig-deploy:hover {opacity:0.8;}

  • Nested State machine - Loops continuous​ly

    Hello ,
    I implemented a program for first time using state machines and Enum (type def). 
    I have 2 state machines (nested) 
    I am not sure if the data flow between the Main state machine and the Sub state machine is correct. The program loops continuously ( this is a MOTOR PROGRAM) and I see that the motor keeps working continuously. It is supposed to run the mentioned Number of Steps once and then stop.
    Please have a look at my code and tell me where I could have gone wrong. 
    Thank you.
    Abhilash S Nair
    Research Assistant @ Photonic Devices and Systems lab
    [ LabView professional Development System - Version 11.0 - 32-bit ]
    LabView Gear:
    1. NI PXI-7951R & NI 5761
    2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021
    OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
    CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
    MEMORY - [ 16.0 GB RAM ]
    GPU - [ NVIDIA GeForce GT 530 ]
    Attachments:
    Motor-UNI_Directiona Dev 1.vi ‏49 KB
    Control 1.ctl ‏6 KB
    Control 2.ctl ‏6 KB

    Figured out ! Thank you. One of the ENUM was not defined to the correct state.
    Thank you. 
    Abhilash S Nair
    Research Assistant @ Photonic Devices and Systems lab
    [ LabView professional Development System - Version 11.0 - 32-bit ]
    LabView Gear:
    1. NI PXI-7951R & NI 5761
    2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021
    OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
    CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
    MEMORY - [ 16.0 GB RAM ]
    GPU - [ NVIDIA GeForce GT 530 ]

  • How to add a state to an existing state machine?

    Hello,
    I have a state machine with 5 states. See attached vi (LabVIEW 7.1).
    Now I want to add another state ("wait") between state Druck Aufbau and Druck Abbau. How can I do that?
    I tried to add a state to the enum on the left and then I noticed that I would have to modify every enum in the vi and the case structure as well.
    Is there an easier way?
    Greetings Johannes
    Using LabVIEW 7.1 and 2009 recently
    Attachments:
    Hysterese_Disc.vi ‏75 KB

    You should replace all enums of the state machine with your type def'ed one. Thus, every change you make will be propagated throughout your state machine. When you need to add or delete states, change the typ def (so the Enum.ctl), and then all the enums will change. Thats the very reason of type definitions. In future, always use type defed enums.
    Felix
    www.aescusoft.de
    My latest community nugget on producer/consumer design
    My current blog: A journey through uml

  • State machines caveat

    I have been using the state machine design pattern in programs for a
    while. In this technique, it is a common practice to define boolean
    switches to trigger actions in the next iteration of the machine (eg.
    "TurnLaserON", "Quit", "Compute", "SetAlarm1"...). Thus, the boundary
    between data and processing is easily trespassed.
    This sounds to me like a possible source of errors, that should be
    limited by some design rule of thumb. I tend to believe that boolean
    triggers in state machines should be looked at with the same precautions
    as a "GOTO" control structure.
    Do you have any experience or theoretical frame to enlighten these
    considerations ?
    oz

    Hi,
    I always prefer a state machine with a state buffer. This means, every state
    can, potentially, call several other states. In practice, there is a shift
    register with an array of strings in it. The first string is called, and
    removed. Every state can modify the buffer, so:
    + states can be put before, after or between the buffer
    + states can be removed
    + states can be filtered, sorted etc.
    + buffered states can be copied
    This makes programming with state machines a lot easier. You can simply make
    a state TurnLaserON, and in the calling state(s) diside what the state after
    TurnLaserON has to be. This makes the program a lot clearer.
    Some design rules I use (mainlly because if I don't use them, there is no
    way of documenting the program):
    + states may only put states before the buffer (I call them sub states)
    + buffered states cannot be removed in a state
    Using these rules, I can put the entire program on paper, without any
    problem.
    Still, I have to transfere information between states. This 'information'
    can be a shift register with a bundle, indicators on the front panel (not
    visible to the end user), a GLI, buffers, ini file reference, or whatever. I
    have never found any big advantage or disadvantage for eny of them, but I
    prefer indicators (mixed with buffers when convenient), because they are the
    fastest to use (for me), and easiest to debug (IMO).
    Regards,
    Wiebe.
    "O. Zimmermann" wrote in message
    news:[email protected]...
    >
    > I have been using the state machine design pattern in programs for a
    > while. In this technique, it is a common practice to define boolean
    > switches to trigger actions in the next iteration of the machine (eg.
    > "TurnLaserON", "Quit", "Compute", "SetAlarm1"...). Thus, the boundary
    > between data and processing is easily trespassed.
    >
    > This sounds to me like a possible source of errors, that should be
    > limited by some design rule of thumb. I tend to believe that boolean
    > triggers in state machines should be looked at with the same precautions
    > as a "GOTO" control structure.
    >
    > Do you have any experience or theoretical frame to enlighten these
    > considerations ?
    >
    >
    > oz
    >

  • 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!!!!!
    Attachments:
    StateSimulatorfromEE428.vi ‏71 KB

    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.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    StateSimulatorfromEE428MOD.vi ‏64 KB

Maybe you are looking for

  • 'we had difficulty reading this feed. host parameter is null' I am getting no where here, help!?

    I've had an RSS feed created for an online video podcast but keep getting the message: 'we had difficulty reading this feed. host parameter is null' i've looked at the forums but none of them make any sense. My IT team say the RSS feed is valid and i

  • BPM Monitoring of IDOCs

    Hello all, I have a scenario with 100 IDOCs and I map the IDOCs in ccBPM. But if somehow a mapping process for one of the IDOCs in ccBPM goes wrong you get an error (a red flag) for all of the other 99 IDOCs. My question is then how can we monitor wh

  • What is the solution to save over a file with Windows Explorer preview pane open?

    (This is a stagnant issue in an alternate thread and did not address the issue directly.)  Every time I make a minor change to a document, I am forced to write a new file to save it.  This is cumbersome, annoying and wasteful.  I am an architect and

  • ICal wont work anymore after 10.6.3 update

    I have been receiving a error message out of the blue that goes like this: "Calendar Cache" couldn't be moved because you don't have permission to access "Calendars".. I have reset the permissions and this doesn't work and iCal has become useless on

  • Types of RFC's

    Hi,           Can any one please tell me the types of RFC's and the difference between them. Thanks, Subba Rao ILam