LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

state machine?

i have seen this term several times on newsgroups and mail lists.... what is
it?
what does it refer to?
0 Kudos
Message 1 of 30
(5,610 Views)
anyoldjoe wrote:

> i have seen this term several times on newsgroups and mail lists.... what is
> it?
> what does it refer to?

I tried to describe a state machine in general terms but failed
so here is the description as far as Labview is concerned.

A state machine is a case structure inside of a while loop.
Each case has an ouput (to a local ) that determines
the next case to execute.

You can use any kind of logic to determine what the next case should be.
Some bad psuedo code:

Case1
Read data
goto Case2
Case2
Data good?
Yes goto Case3
No goto case4
Case3
Process data
goto Case1
Case4
send error
goto Case1

In normal operation the flow is Case1->Case2->Case3->Case1 .......repeat
If an error occurs Case4 is execute
d then the flow returns to normal as above.

Dang that is real bad, maybe someone else can explain it better?
Kevin Kent
Message 2 of 30
(5,609 Views)
The point of a case statement is that it offers all the advantages of a
sequence with the possibility of
a) redirecting flow to an arbitrary case
b) aborting the sequence altogether if things go wrong
c) having common code execute before or after step

set case=start
start loop
do general error checking
if error then set case = end
do general user interrupt checking
if interrupt then set case = end
case start
do start stuff
set case = step 1
case step 1
do step 1 stuff
set case = step 2
case step 2
do step 2 stuff
set case = end
case end
do end stuff
loop until case = end

If required, any case could, for example, set the case to an earlier value
to repeat a step.

S
equences (and to a lesser extent sequential commands in a text language)
are very inflexible and require ugly coding to break out of, or to redirect
flow.


Kevin B. Kent wrote in message
news:39170E22.3CDF122C@usa.alcatel.com...
> anyoldjoe wrote:
>
> > i have seen this term several times on newsgroups and mail lists....
what is
> > it?
> > what does it refer to?
>
> I tried to describe a state machine in general terms but failed
> so here is the description as far as Labview is concerned.
>
> A state machine is a case structure inside of a while loop.
> Each case has an ouput (to a local ) that determines
> the next case to execute.
>
> You can use any kind of logic to determine what the next case should be.
> Some bad psuedo code:
>
> Case1
> Read data
> goto Case2
> Case2
> Data good?
> Yes goto Case3
> No goto case4
> Case3
> Process data
> goto Case1
> Case4
> send error
> goto Case1
>
> In normal operation the fl
ow is Case1->Case2->Case3->Case1 .......repeat
> If an error occurs Case4 is executed then the flow returns to normal as
above.
>
> Dang that is real bad, maybe someone else can explain it better?
> Kevin Kent
>
0 Kudos
Message 3 of 30
(5,612 Views)
Most of introductory digital design textbooks talk about FSM (finite state
machine), e.g. vending machine can be modeled as a state machine, etc.

"anyoldjoe" wrote in message
news:3916f48d@newsgroups.ni.com...
> i have seen this term several times on newsgroups and mail lists.... what
is
> it?
> what does it refer to?
>
>




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
0 Kudos
Message 4 of 30
(5,614 Views)
On Mon, 8 May 2000 12:06:51 -0500, "anyoldjoe"
wrote:

>i have seen this term several times on newsgroups and mail lists.... what is
>it?
>what does it refer to?
>
>

A state machine has inputs and outputs. It generates a specific
output for each possible combination of its inputs. This can be used
to control the flow of your program. i.e. Each time the user presses
button A, this happens; each time the user presses button B, that
happens, etc. You can construct a state machine in LabVIEW using the
case statement inside a while loop technique described in other
responses. The point is that this allows you to have a predictable
response of you program to any given situation regardless of order of
the sequence of events the user gene
rates.
Message 5 of 30
(5,619 Views)
So, mechanically, does a state machine only require a while loop and a case? 

Does each case in the switch box correspond to a state? 

How do you direct which state to go to next?

Do you need to have a shift register?
0 Kudos
Message 6 of 30
(5,187 Views)

A good place to start is here.

"

So, mechanically, does a state machine only require a while loop and a case?

"

It also requires a mechanism to deterime the next state. This is often implemented using a Shift Register. I have seen queues used for this but that is rare.

"
Does each case in the switch box correspond to a state? 

"

If "switch box" = case then yes. You could combine two identical states as one case but that would be very confusing.

"
How do you direct which state to go to next?

"

That is where the SR comes into play. When each state completes, it should place the next state in the SR.

"

Do you need to have a shift register?

"

To keep it simple, yes.

 

I have written about my thought on State Diagrams in the LabVIEW Champions Blog if you are interested.

Let us know if you have more questions.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 30
(5,193 Views)
I'm catching on.  I thought shift registers were purely index-numeric when I read, but now it all makes sense.

I say "switch" because a LabVIEW case seems to contain multiple cases.  Instead of saying a case of cases, I just revert to the generic term "switch".

So, let's say that I'm running two pumps that each have independent tanks.  One's for gage vacuum, one's for gage pressure.  If I wanted to run them independently but simultaneously while monitoring tank pressures, what's the best way to do so without creating unnecessarily complex code?
0 Kudos
Message 8 of 30
(5,192 Views)

"

 If I wanted to run them independently but simultaneously ... without ...complex code?

"

I would advise you to start by sketching up a quick state diagram.

Do you have access to the State Diagram Editor?

The SDE has a single step mode that is great for these types of complex systems. You set up your application to read all of its inputs and decide if it should stay in the current state or if a transition to a different state is required. Here is a quick example.

Other-wise you can code it up manually just the way the link I provided earlier said.

Ben

Message Edited by Ben on 04-14-2007 10:56 AM

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 9 of 30
(5,191 Views)
No, I don't have SDE.  An evaluation version would be fantastic.  My university may have a license.
0 Kudos
Message 10 of 30
(5,183 Views)