LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State machine: State entry and exit actions

I would like to enable my LabVIEW state machine to perform specific actions upon entry and exit from states. Is there a good design principle for this in Labview?

 

I was thinking of enabling history by using variables to store previous, current, and next states, then compare these upon each state transition to determine if the state has changed. If the state has changed, perform the appropriate EXIT and ENTRY actions.

 

This seems like a common part of standard state machines, yet I have found little (or no) discussion to serve as a guide. Any suggestions?

 

0 Kudos
Message 1 of 7
(4,304 Views)

What you mentioned is a common way to impelment that functionality (look at some of the CLD exam solutions) but it's almost worth implementing each enter/exit functionality in it's own state that gets called "on the way" to the main state..i.e it immediately transitions to another state. - it helps keep the diagram cleaner and is a little easier to follow the transitions.

Philip
CLD
0 Kudos
Message 2 of 7
(4,299 Views)

You mention "variables" without defining what you mean by that. Generally the preferred method of passing data from one state to the next (even it if is the same state) is via a shift register.  The use of global or local variables in LV for such purposes is discouraged. They break dataflow, force operation in the UI thread (locals), may make extra data copies, and are slower than wires.

 

Certainly the previous state could be considered a "state variable" just as elapsed time or the voltage on Input 3. The state variables may be used to determine the next state.

 

As Philip indicated it is probably better to keep the entry and exit actions inside the states. Make subVIs if appropriate. By doing it this way there is no need to store the next state because the exit action is handled internally within the state.

 

Lynn

0 Kudos
Message 3 of 7
(4,285 Views)

If you're comfortable with LVOOP, there is a different way of implementing a state machine in which you get this cleanly. I think it's an implmentation of the state pattern, although I'm not really conversant in the OO patterns enough to tell. Essentially, each state is a class and there are two nested loops - the outer one calls the state's entry action method and then the inner loop keeps calling the state's Do method until it decides to change state and then it stops the loop, calls the exit action method and changes the state.

 

You can see an example with actual code here - http://lavag.org/topic/13064-object-based-state-machine-pattern/


___________________
Try to take over the world!
0 Kudos
Message 4 of 7
(4,247 Views)

Just to add something:

The LabVIEW State Machine architecture contains functionality code as "Entry" Action by default. You can, as already pointed out, add additional code to differ between Entry and Exit code (additional case structure within states fed by another shift register with comparison).

 

But there is another possible "solution" for your request:

LabVIEW State Chart Module. It does supply you with the requested functionality generically.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 5 of 7
(4,206 Views)

@tst wrote:

[...]

 

You can see an example with actual code here - http://lavag.org/topic/13064-object-based-state-machine-pattern/


I was thinking of the same thing.  Specifically, this post with this picture.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 6 of 7
(4,194 Views)

Thanks for the replies. I would have liked to try the statechart module (in addition to requiring entry/exit actions, my state machine is heirachichal,) but the statechart module appears to be 32-bit only and our lab runs 64-bit versions of LabVIEW.

 

For now I've gone the route of implementing state history using shift registers (and some local variables.) Perhaps not as efficient or elegant as the LVOOP suggestions above, but it is relatively straightforward and seems to work as desired.

0 Kudos
Message 7 of 7
(4,136 Views)