LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx and State Machines

DAQmx and State Machines.  


Greetings,

I'm having a little trouble working with DAQmx and State Machines.  

What I'm trying to do is as follows:

Turn on a digital output to fire an air cylinder.
Start a timer.
Begin acquiring data from a load cell.
When the timer is done, turn off the digital output.
Start a timer
When that timer is done stop acquisition.
"Cycle" is complete.  Save data etc.

Unfortunately there's no reed switch on this cylinder.  So the operation is going to be time/load based.  

The feedback from the load cell also needs to serve as an emergency stop if the load exceeds a given value.  As well as a Pass/Fail criteria should the load be above or below a given value.

I've had problems in the past with two DAQmx tasks happening at the same time and I'm hoping someone with experience has some tips for me.

I'm envisioning my load cell DAQ happening in a loop parallel to my main state  diagram loop.  I'm assuming I'll have to use a continuous acquisition if I want to monitor for an overload situation.  If I use this method, I'm not sure how I'll be able to keep/save/display the data relevant to the test.  I'm also not sure if this is even a good approach to this problem.  

Any guidance or suggested reading would be greatly appreciated.   
---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 1 of 4
(2,820 Views)
A state machine, or more likely two or three independent state machines, will work well for this type of task. I typically have three state machines: One for GUI (user interface), one for data acquisition, and one for data processing, analysis, saving to files,and other behind-the-scenes work. I exchange data and commands among the loops with queues.

The emergency stop should ALWAYS be done with hardware, not software! The software should monitor the stop condition and respond appropriately, but never depend on software to prevent injury to persons or damage to property.

Look at producer/consumer examples.

Lynn
0 Kudos
Message 2 of 4
(2,808 Views)
"Emergency Stop" was a bad choice of words.  The load is being monitored for over and under values as part of the test.  Either condition is a "fail" and will stop the test.  This is not part of a safety circuit.

I'm hoping to make use of the State Diagram Toolkit, as I have some familiarity with this tool.  I've not had experience with Event Structures or Queues.    

---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 3 of 4
(2,797 Views)
Often the best way to learn about a tool is to make some simple test VIs. For example set two loops running in parallel. Use an event structure in one to generate "commands." Many systems use "Run," "Pause," "Resume," and "Stop." Those commands are sent to the second loop via a queue named "Command". The second loop generates data and status messages. The data could be a simple count, elapsed time, or random numbers. The status is "OK," "Error," or "Stopped." These are returned to the user interface loop via the queue named "Response." The user interface (UI) loop can read the "Response" queue in the timeout case.

The second loop would be a state machine with states for each command plus and "Idle" state. When a command is received, the state changes, and the appropriate data or status messages are sent. When the "Stop" button is pressed, the UI loop sends the "Stop" command. When the second loop receives the "stop" command it switches to the "Stop" state, shuts down any data processes, sends the "Stopped" status message and exits from the loop. Onyl after the UI loop receives the "Stopped" status message does it exit its loop.

This can easily be extended to more than two loops with much more complex activities, but this makes it fairly easy to see what is going on.

Lynn
Message 4 of 4
(2,791 Views)