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

Similar Messages

  • 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 .

  • 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

  • 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

  • Can you use event case with labview real time?

    I have a real time application I am putting together and until recentally have concentrated on getting the data acquisition working as expected.
    I am using a PXI-8183 in a 1031 chassis.
    I am now trying to add the functionality for setting up the system in the form of a GUI remote front panel that I connect to with a host laptop.  I am connecting with the host as expected and it seems to be working well in that respect.
    My problem is with event cases, operating in a while loop on the target.  They just dont seem to want to trigger when i click on a button I have set an event for.
    I have looked through the documentation and cant see any reference to issues with event cases on rt, but I feel I am missing something fundamental.  Can anyone help?
    Regards,
    Barry

    look here maybe:
    http://digital.ni.com/public.nsf/allkb/42B70D2D0C4B568586256E2F0051441D
    Harold Timmis
    [email protected]
    Orlando,Fl
    *Kudos always welcome

  • 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

  • How can A state machine be used to monitor flow from a micro motion using bridgeview/labview

    I want to be able to use a state machine to monitor if the flow stops during a chemical charge. Currently I am using labview 5.0 and this monitors flow but I need an alarm to let me know if flow stops during a charge. Any suggestions?

    this example might explain what i meant.
    A Rafiq
    Attachments:
    statemon.vi ‏55 KB

  • How to do state machine using events .

    Hi all.
    i like to create a state machine using events methos .
    i have 4 functions 1,2,3,4. (event based functios) (seperate sub vis)
    1.i will trigger the 1 function.
    then end of the first function should trigger the next function.
    like state machine .
    how to create this method in labview .. i tried value signaling its still not working . what i want.
    Solved!
    Go to Solution.

    JGar wrote:
    Wouldn't it make sense to have the entire state machine within one event case?  When you trigger the event case the state machine then executes like a normal state machine.
    DO NOT DO THAT!!!!!!  Long parts of code do NOT belong inside of an event case.
    The Event Structure should be in its own state and the state machine should to to that state every once in awhile to check for user events.
    Alternatively, you could put just the state case structure inside of the Timeout event case.  Something like this: http://www.notatamelion.com/2015/03/02/building-a-proper-labview-state-machine-design-pattern-pt-2/
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Wiring Data in a State Machine

    I have a state machine with about 20 cases all handling different user interactions and all completely independent of one another. That is, what one case does has nothing to do with what another does (for most of them anyway). They just execute one case and then go back to the default case. Some of them though do require data to be passed out of one case so that it can be read in another (actually not the data but just the data structure to be reused). Shift registeres work just fine of course, but this requires me to wire this data through all the other cases that don't need it just so they can have an output for the tunnel. Is there anything else I can do to avoid wiring paths through every case that doesn't actually need the data?

    Here's a real simple example. I can't give you too much insight with respect to the memory usage, except to say that I've never had any problems doing things this way. I've written a couple of big vi's with 30 - 40 variables clustered this way.
    Attachments:
    Clustered_Variables.vi ‏35 KB

  • How to use a event structure with a state machine

    First, I would like to inform you that I only work on LabView part time, and have much to learn.  Anything I do learn, I usually forget until I need it again, because I only work on it part time.
    Using your StopWhileLoopMOD[1].vi, I am trying to put a state machine inside the event structure.  
    Related link: http://forums.ni.com/t5/LabVIEW/How-to-stop-while-loop-in-Event-case/td-p/465564/page/2
    Here is my application:  on the front panel, the user can select any combination of 7 different tests.  I have created cases to perform each step of each test in the correct order, but if the user presses stop, the tests won't stop because some of the cases have a while loop inside the event structure (like you mentioned is a bad idea).  The user should be able to stop the test, reselect tests to perform, and re-start the tests. 
    When the start button is pressed for the event structure, I need all the cases to run in the proper order, unless stop is pressed.
    In the past I have indexed an array and used that to run the state machine, but it won't stop immediately.  
    I have sub VIs that are built in while loops because the outputs of the product needs time to stabilize.  The state machine stops and waits up to a certain number of iterations.  If it passes the test, the while loop stops and the next state starts.  If it takes too long, it exits and reports an error.  Maybe I need to just use the state machine and not an event structure?
    Is there a good example of an event structure?
    metzler CLAD
    Solved!
    Go to Solution.

    I'm not sure exactly what you are asking, but it sounds like you want to script a bunch of tests and if the user says stop, to immediately stop the current test and abandon the others?  I'm going to assume that you know how to clear the array so that it will abandon the others, so I'm guessing that you are having trouble abandoning the current test?  If this is indeed the case, then the problem is that you are not able to propagate the message from the main VI FP which is the GUI to the sub vi which is the test, where the test may or may not have a GUI (FP visible) of it's own.  Threading was the first thing to come to mind, but this may not be necessary using events.
    You can do this by passing a refnum of the stop button to the subVI, where you can then add that wait to the event case structure.
    I've attached 2 VIs, mainvi.vi which is just a loop displays the count*2 (number of seconds passed since running) that will call subvi.vi and then check to see if the stop button is pressed.  mainvi.vi is by no means a state engine, it is just a simple loop for demonstration purposes.  subvi.vi just waits 2 seconds and leaves, it is a better structured state engine with an init state to start a poll case to wait for events and an exit state to clean up.  You can modify this any way you wish to get it to do what you want.  You will note that even if subvi.vi is being executed, it will terminate immediately when the stop button is pressed.
    Hope this helps.
    A
    Attachments:
    mainvi.vi ‏17 KB
    subvi.vi ‏33 KB

  • 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

  • Producer Consumer with a state machine within the consumer

        Hi All,
    I have been trying to develop a data acquisition system with the producer consumer architecture.  To the left of the two main loops I initialize the serial port and any constants and variables im using.  I also have an obtain queue VI needed for enqueue and dequeue. Then in the producer loop i have a state machine.  The first state is where I wait for a button press on the front panel to write a GO signal on the serial line which will tell the device connected to the serial port to begin sampling data.  After this button press I go into the next state which is called my read state.
    In the read state I use a property node to read all of the available bytes at the serial port and then enqueue this collected data into a queue.  The state machine then is directed to continously go to the read state again and collect more data.
    Now this is where my dilemma is......  The consumer loop has the dequeue VI inside it and after this VI i have a state machine (while loop and case structure) which contains the following states
    1.  Build Array - build an array from the dequeue element and if there is any left over data from the parsing states it will build an array with the left over data and the dequeued data
    2.  Determine packet type - this state looks for the packet type byte(not necessarily the first byte in the message) and also check the next byte (packet length) to ensure that I am at the begininng of this chunk of data.  This state may be a little slow because there can be three different packet types and based on this byte and the packet length it may have to search the array several time to find the valid starting point.  This state also determine the next state to go to based on the packet type.
    3 packet type 1 parsing - parse data and store the remaining data it leftOver array.  Go to exit state.
    4 packet type 2 parsing - "" ""
    5 packet type 3 parsing - "" ""
    6 exit - leave this state machine and fall back to the consumer while loop.
    After it exit I think it should fall back to the consumer while loop and dequeue more data and enter the state machine again to build a new array with the dequeued data and leftover data.  It seems to work when I trace the execution using the Highlight execution feature, however when I run this all at full speed, it seems to go into the consumers 1st and 2nd states back and forth and not completely go through the state machine.
    I tried adding in a delay in the producer loop to give the consumer loop time, but I didnt notice any difference.  Is it possible that my dequeue element is retreiving more data while im still in the state machine, causing the execution to leave the state machine before it finished all states?
    Is there a better approach to take to solve this problem. Basically I need to read data at a 1,000,000 baudrate and parse it as quickly as possible so that I can break it up into 3 different packet types, write the data to a file, and graph the actual data (header info removed) in realtime.  I need to also ensure that I am not losing any of the collected data.  Data loss cannnot occur.

    A couple of things more to go along with Ben's pointers:
    You convert your data from a string, to a U8 array, to a Hex string array in the producer loop, then convert back to a integer to determine what to do with it.  In the process, you create two or three copies of your data, slowing yourself down quite a bit.  The code would be quite a bit more efficient if you left the data as a U8 array.  You can change the format of the controls and indicators to show hex values instead of integer by right clicking on them and selecting Format and Precision...
    Your search code is fairly inefficient.  I made a whack at making it a bit better.  See attachment below.
    If you continue to run into race conditions, you can debug them using a calls to the Windows debug write sprinkled liberally about your code.  Check out the post here for more information.
    Don't let your lack of format LabVIEW training stop you.  The biggest thing to get is the data flow paradigm (aka data is wires, not registers).  Once you get past that and learn how to pass data around using shift registers, queues, events, etc, you are most of the way to mastering LabVIEW.  The rest is just learning the plethora of functionality LabVIEW gives you (yes, I have reimplemented LabVIEW native code more than once in the process of learning).
    Let us know if you need more help.
    This account is no longer active. Contact ShadesOfGray for current posts and information.
    Attachments:
    serialUtil_V3_DFG.zip ‏137 KB

  • Event structure in a State machine

    Hello all,
    I've got a state machine with a sort of Stand-by state from where a user can select the next state using buttons. I tried using an Event structure with value change to select the next case but when the state machine is in a specific case and the button of an other state is pressed the whole thing blocks. I've attached an example, the LEDs just indicate what state you are in.
    Thx for your time,
    Bert
    edit: Indeed, I miss-clicked
    Solved!
    Go to Solution.
    Attachments:
    Question.lvproj ‏2 KB
    Question.vi ‏21 KB

    All your inner while loop should not be there, they just gum up the gears. It is a bad idea to trap the code inside inner loops, because during that time, events cannot be handled, whil they are still queued up. For example if you are in state 1 and press state 3 100 times, then exit state 1, state 3 will be entered 100 times in a row, witout a possibility of escaping.
    Thus the use of an event structure is also ill advised here.
    Here's is a quick draft showing the same code without inner loops and without the event structure just to give you an idea what I meant. See if it gets you some ideas. It is still not perfect ...
    (Sorry, I had to disconnect the type definitions, because you did not include it)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Question 1mod2.vi ‏19 KB

  • Can I have multiple event structures with the same event cases?

    Hello, 
    I'm doing an application that reproduces the front panel of the HP6675A power supply. To achieve this, I have done a state machine with different states
    (initialize, measures, voltage, current, ocp, ov, store, recall, etc). In each state, should have an event structure that catches the events of the buttons, like for example: if the current state is the Voltage mode and the user press the current button the next state will be the Current mode. For this in each state of the state machine should be the same event structure with the same events.
    My problem is that the Vi doesn't work properly when I have multiple event structures with the same event cases. There are some possibily to do this, and how? Or is impossible to have multiple events? I have been reading some posts, but I don't find solutions. 
    Any help is appreciated.
    Thank you very much.
    Solved!
    Go to Solution.

    natasftw wrote:
    Or as others mentioned, make two parallel loops.  In one loop, have your state machine.  In the other, have just the Event Handler.  Pass the events from the handler to the state machine by way of queues.
    A proper state machine will not need the second loop.  The "Wait For Event" or "Idle" state (whatever you want to call it) is all you really need in order to catch the user button presses.  The setup is almost there.  Maybe add a shift register to keep track of which state to go to in the case of a timeout on the Event Structure.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

Maybe you are looking for

  • How do I make PDFs OPEN and fit my screen?

    Every time I open a PDF, the document opens larger than my screen. How do I make the document fit the screen I have? This is absolutely NOT a zoom problem. I have a 15 inch laptop. It has a screen that is about 12 inches wide x 7.5 inches high. I ope

  • OutLook 2007 Macro to create Folder Based on Received Date

    Dear All, Is it possible to create a macro which will automatically create a folder based on Received Date of the mail and then group these mails (in folders) based on the received month-. Can someone help me with the VBA Coding for Outlook 2007, whe

  • Is a separate update page necessary?

    Hi Is it necessary to have a separate page for updates when you have a requirement to allow updating of records for only a specific set of users or roles? Say i have a page that allows querying, inserts, and deletes for records.  Now if I only want s

  • Online number...lost?

    I signed-up for a skype online number but did not immediately put money on the account. The system indicated that the online number was reserved for me for 90 days (verified when I logged out and tried to choose that number again). Anyway, less than

  • How do I restore the Colors in the Finder side panel?

    Hello; How do I restore the colors to the Finder's Side Panel?