04-18-2013 12:58 PM - edited 04-18-2013 12:58 PM
Hello, I am implementing my first state machine in LabView and need some help. The state machine definition is as follows:
The program will be initialized. The program will wait for a user request for a reading. A reading consists of sampling a signal for 20 seconds on a 1 second sampling interval. The program will use the sampled data to calculate an output which is displayed on the front panel. A reading can be taken initially after startup but subsequent readings must be taken only after a 60 second settling period. A reading can be taken at any time after the 60 second settling period. The program exits upon user request to stop the program; this can be done at any time.
The states I have defined so far are:
1. Initialize
2. Wait
3. Read
4. Output
5. End
I am newer to LabView and typically implement this kind of program using C/Java using counter variables and time delays for the Wait/Read states. My main issue moving forward is how to implement this state machine in labview not being able to use counter variables and using the data flow concept instead. I will post my initial VI below. Thank you in advance.
Robert
04-18-2013 02:06 PM - edited 04-18-2013 02:28 PM
I helped you out, maybe you can figure out the rest of the algorithm..But you will see the flow of the state machine ![]()
try not to use 'Icons' in your block diagram, they take up so much room
goto tools>option>highlight_ 'block diagram'> uncheck_"place front panel terminals as icons."
04-18-2013 02:34 PM
Thanks Apok, I'm working on it now. The flow somewhat makes sense. Here are some questions I have for the code:
1. during the Init state, how do I instantiate a variable and set to 0? I am trying to set a variable to zero for the singular event that if the user wants to take a reading right after startup, it is possible to do so. After that, the variable should be set to 1 and force the wait state into a 60 second delay.
04-18-2013 02:39 PM - edited 04-18-2013 02:45 PM
@surferEE wrote:
Thanks Apok, I'm working on it now. The flow somewhat makes sense. Here are some questions I have for the code:
1. during the Init state, how do I instantiate a variable and set to 0? I am trying to set a variable to zero for the singular event that if the user wants to take a reading right after startup, it is possible to do so. After that, the variable should be set to 1 and force the wait state into a 60 second delay.
yes, you can initiate it in that case or outside the while loop like i did with the local. not quite sure about your sequence to force a delay in the wait state or wait case statement?
04-18-2013 02:58 PM
Let me simplify my question, I just want to instantiate a single integer variable at the start of the program. Set it to zero, after the first read request set it to one then all other subsequent read requests will require a 60 second wait. Does this make sense? I am unfamiliar with how to do this in LabView.
04-18-2013 03:06 PM - edited 04-18-2013 03:08 PM
There are two ways you can do this.
1) duplicate the read code and place it before the state machine or as a part of the Initialize state. this will run a 1 time measurement before the statemachine enters it's normal operation. This will run everytime you start the VI so it's not quite what you want.
2) Modify the READ state to use a numerical control as the integration time, instead of wiring a zero or 1 to a case statement. Set it's default value to be, say 10 seconds, then after the first read, set it to 60 so every following read will be 60 seconds.
I have a question though, how will the user be able to decide if this initial read occurs? This section of code will be processes faster than the user can click a button on the front panel. Will this decision be based on some external signal or possibly an ini file?
04-18-2013 03:12 PM
No, the Read LED will have a label that tells the user the signal is ready to be acquired. When the program is first started, this will be active. After the first reading it will be inactive until 60s has passed. Once the 60s has passed, it will be in the wait state. I think I just answered my own question. I will repost my solution in a minute. Thanks again Apok.
04-18-2013 03:15 PM
So you are having the user change the state of the LED prior to starting the VI? Be careful with this approach as users will be able to easily change the front panel or accidentally delete controls/indicators.
04-18-2013
03:27 PM
- last edited on
05-12-2025
04:35 PM
by
Content Cleaner
@surferEE wrote:
The states I have defined so far are:
1. Initialize(set variables to '0', initialize equipment to power on state, set voltages.....)
2. Wait ( wait for user front panel interface...)
3. Read
4. Output
5. End
Robert
i like what you did here by defining the states, next you will have to add transitions between states, whether using time delays, user input and etc...this will make programming much easier to implement and understand
04-18-2013 03:34 PM - edited 04-18-2013 03:35 PM
Ok, let me clarify Apok:
1. User starts the program (eventually this will have to be exported to a .exe).
2. The program enters the 'Wait' state, the 'Read' LED will display that a reading is able to be performed (by color code that I have yet to determine) and the 'Take Reading' button will be enabled.
3. The user has the option to take a reading at that point or wait for an unspecified period of time. Both the 'Read' LED and the 'Take Reading' button remain enabled.
4. The user decides to take a reading. *at this point I need to somehow track the fact that the first reading has been performed hence my desire to instantiate/use a variable, if there is a better way I'm all ears*
5. The program enters the 'Read' state, data is acquired, LED1 and LED2 are set according to the acquired data.
6. The program enters the 'Cooldown' state for 60s and ther 'Read' LED and 'Take Reading' button are grayed out/disabled.
7. After 60s has transpired, the program enters the 'Wait' state the 'Read' LED will display that a reading is able to be performed (by color code that I have yet to determine) and the 'Take Reading' button will be enabled.
I have redone the case statement as I will only need the read, cooldown and wait states if I account for the first reading. Attached is the updated VI. Thanks!