LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State Machine vs Sequence Structure for DAQ read/write and file I/O

Greetings,

 

Let me state the task, first. We have 3 analog (floating-point) signals being read from a file that are being fed to an external computer. These 3 signals are replicated 4 times so there are 4 channels of signal A, 4 channels of signal B, and 4 channels of signal C. The replicated signals differ from the ACTUAL signal read from the file by a certain amount of noise added (in LabVIEW). The idea is that there are four sensors per signal but we don't actually have 4 sensors so we're emulating this by adding a little noise to the ACTUAL signal. We're interested in 3 particular values.

 

The 4 channels of a signal are sent to a 2-out-of-4 voter (not in LabVIEW) and the signal is passed to a comparator. If the signal exceeds a particular range, a digital signal is sent as an alarm. So, in total, we have 3 analog signals read from a file in LV and sent to an external computer via DAQ. The external computer looks at the signals (12, after the replication) and simply indicates if any of the final 3 signals have exceeded their limits. 

 

The question is this. How do we organize these activities? What we need to do is:

  • read data from a file
  • pass the read information to an external computer
  • monitor the alarms from the external computer
  • record the "bad" signals in a file

 

As the main designer, I'm trying to decide if a state machine structure is best or a stacked sequence structure. Should I break each of the activities up into sub-VI's? Read data subVI, pass data to external computer subVI, monitor alarm subVI, record "bad" signal subVI?!?!?

 

I hope I've been as clear as possible. Personal opinions are very welcome.

 

Thanks,

 

-- Michael

0 Kudos
Message 1 of 16
(6,854 Views)

Michael,

 

it is good to post such questions before starting to code 😉 .

 

Well, to prevent any kind of misunderstandings:

- A (stacked) Sequence Structure is (as the name already includes) a structure. A tool to solve programmatic issues. But it is recommend not to use any kind of sequence structures in LabVIEW since they are considered bad style and esp. the stacked sequence is bad to handle.

- A State Machine is no structure but an architecture. It consists of several structures: a while-loop, a shiftregister and a case structure. An architecture is a methodologie for the application on how to handle the execution. You should definetly consider learning more about architectures before planning your code further. You can find infos about that topic using the templatebrowser (File => New), or the LV help. This is an example for the help.

 

A state machine might work for you, but it has some restrictions you will encounter during coding or maybe at expansion of the application. So choosing the right architecture is the first step to success!

 

hope this helps,

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 16
(6,835 Views)

Stacked Sequence Structures should be removed from the palette.  They always lead to horrible code..  Especially when people nest them within othe Stacked Sequences.  Avoid them at all cost.

 

Question:  Will the software need to respond to Operator selections while running?  (ie:  Front Panel Controls)  If so, you may want to look at Event Structures as well.  Event Structures team well with State Machines.  The Event Structure can pass data to the State Machine via queue(s), including the selection of the next state(s) or influence the next states.

 

R

Message 3 of 16
(6,818 Views)

There will be limited user interaction, hopefully. This "environment" is being designed for fault injection. So, the faulty data will be read from a file and the external computer will react to the faulty data and either send an alarm or not (meaning that it didn't see the fault). An experiment involves: 1) system reset, 2) initialization of other devices, 3) file read for data and export to external computer, 4) monitor alarms (in LV), 4a) if an alarm occurs, record the offending signal in a timestamped file, 4b) if no alarm, return to 1) and start another campaign.

 

So, at most the user will simply need to start things off. Later, we may wish to inject faults by user-intervention by adding even more noise to the analog signals or by manually tripping alarms (digital signals). 

 

That's it 🙂 

 

I've used state machines in digital logic design but never in LabVIEW. Time is somewhat of the essence right now, and I'm not sure how much of a learning curve there is for State Machines. I'll take a look at the Event structures. Given my further description, do you have a recommendation?

 

Thanks again,

 

-- Michael

0 Kudos
Message 4 of 16
(6,803 Views)

Thanks Norbert. Is there a steep learning curve for the State Machine vi? One thing I like about LV is there are many examples of how to do specific things but the explanation for how and why things are the way they are seems to be lacking. I looked at the State Machine material for a Coke Machine but it didn't give enough specifics. It showed the VI's but didn't really say how one would go about building there own from scratch.

 

Thoughts?

 

Thanks again,

 

-- Michael 

0 Kudos
Message 5 of 16
(6,802 Views)

Michael,

 

the State Machine is quite easy...

If your task can be designed within a state diagram, you have states and transitions. Each transition can have preconditions.

Each case in the case structure within the State Machine reflects a single state from the diagram. The transition code has to be included there to decide what the next state is....

 

hope this helps,

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 6 of 16
(6,797 Views)

Norbert B wrote:

Michael,

 

the State Machine is quite easy...

If your task can be designed within a state diagram, you have states and transitions. Each transition can have preconditions.

Each case in the case structure within the State Machine reflects a single state from the diagram. The transition code has to be included there to decide what the next state is....

 

hope this helps,

Norbert 


It does, but my question remains. Is there a resource that gives you a step-by-step guide to making a State Machine? I've seen the example finder material but it doesn't really tell you how to proceed. It's more like a recipe without instructions: add a case structure, put in transition code, add some typedef stuff, and voila! Given the turnaround time on this, I need something a little more hand-holding-ish 🙂 LOL. 

 

If you have a simple example that you've done or seen that guides a "newbie" through the steps, that would be great. I know how to construct a state machine, in general, but I'm drawing blanks as to its implementation in LV.

 

Thanks again -- loving the quick replies (especially since I'm in the lab now trying to figure things out).

 

-- Michael

0 Kudos
Message 7 of 16
(6,795 Views)

Michael,

 

besides of courses from National Instruments, there are several online tutorials about LV and about state machines in LV in specific.

Please look for example here or here.

 

If you want to have guided exercises on different questions, you really should consider attending a NI course....

 

hope this helps,

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 8 of 16
(6,758 Views)

Norbert B wrote:

Michael,

 

besides of courses from National Instruments, there are several online tutorials about LV and about state machines in LV in specific.

Please look for example here or here.

 

If you want to have guided exercises on different questions, you really should consider attending a NI course....

 

hope this helps,

Norbert 


 

Thanks Norbert. I've been looking at the "Revised Coke Machine" for quite some time. I just found another version at http://decibel.ni.com/content/docs/DOC-2147. It's slightly different from the original one I downloaded but it'll do for my questions. I'm unclear about how Property Nodes are used. I tried to make a simple 4-state machine (init, something, next, done). The state table would be as follows:

 

PS                     NS (x= 0)  (x=1)

Init                      Something   Next

Something          Next            Done

Next                    Done           Next

Done                  Done            Done

 

 

I create enumerations for the states and proceeded to duplicate the Next State Vi like the coke machine example and ran into some problems 😞  I agree with you regarding taking a course, but I just don't have time right now. I think I'm going to have to go with a Flat Sequence Structure and move on. I've searched for State Machine examples and found some, but, again, very little explanation (documentation). Quick question though. The Property Node allows me to reuse a boolean switch (for instance) in different cases of my state machine? That is, I want two switches (Zero, One). When I click Zero it goes one way and so on for One. Ahhh...forget it. I'm sleepy. This isn't making sense to me anymore.

 

Thanks again for all the help! It's much appreciated!!!!!!!

 

-- Michael 

0 Kudos
Message 9 of 16
(6,757 Views)

Michael,

 

please look at attached screenshot. Hope this clears up some questions.....

 

 

 


[...] I agree with you regarding taking a course, but I just don't have time right now. [...]


That is one of the most common false estimation ever done! You have to spend some time (about a week), but you can save weeks during your developement. Choosing the wrong architecture due to lack of knowledge has to lead to exceeded projecttimeframes as well as nearly impossible changemanagement! So gathering as much knowledge as possible before starting to design the code can save you a lot of money!

To be honest, sure maybe there is no suitable course available at the moment, so taking a course is not possible. But if you are not sure, ask your local NI representative!

 


[...] I think I'm going to have to go with a Flat Sequence Structure and move on[...]

That is imho the badest choice you can meet. Just to quote Ray: "Stacked Sequence Structures should be removed from the palette.  They always lead to horrible code."

 

hope this helps,

Norbert 

 

[EDIT]: Please note that the enums are predestinated to be typedefined... so please make a single typedefinition and use this for controlling the states. This will reduce implementationtime when extending the state machine immensly....
Message Edited by Norbert B on 09-12-2008 04:05 AM
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 10 of 16
(6,745 Views)