LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

state machine?

Hm.  I'm using the on-line evaluation, but it doesn't include the option to create VIs from templates.  Could I start the SDE manually in a blank VI?  Is it a function?
0 Kudos
Message 11 of 30
(1,706 Views)
OK, it's working.  What if I wanted to do two things (prepare two tank pressures) at once?  Would I have to combine those actions into a sub-state?

I'm just going to run the pumps once.  I won't be continually monitoring pressure of the tanks, I just need to prepare their initial values for the experiment.

Message Edited by bmunden on 04-14-2007 11:48 AM

0 Kudos
Message 12 of 30
(1,706 Views)

First get your thought clear to the point that you can explain it someone.

Draw it up and walk through it asking yourself "what if" questions and revise as you see fit.

If they are interdependent, code them together.

If they are independent, code tham that way.

THEN code it.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 13 of 30
(1,698 Views)
Maybe this will help to illustrate the point.  I'm more articulate with sequential text programming.





{Default Digital Relay States}

Solenoid 1 = CLOSED
Solenoid 2 = CLOSED
Solenoid 3 = CLOSED
Solenoid 4 = CLOSED
Solenoid 5 = OPEN

Pump 1 = OFF
Pump 2 = OFF

{Defined Values}

Tank 1 Set Pressure = 4.2 psi
Tank 2 set Pressure = -220 cmH2O

{Prepare Tank 1, Tank 2}

while (Tank 1 Current Pressure <= Tank 1 set Pressure) OR (Tank 2 Current Pressure >= Tank 2 set Pressure)
    if (Tank 1 Current Pressure <= Tank 1 set Pressure)
        Solenoid 2 = OPEN
        Pump 1 = ON
    end

    if (Tank 2 Current Pressure >= Tank 2 set Pressure)
        Solenoid 4 = OPEN
        Pump 2 = ON
    end
end

Solenoid 2 = CLOSED
Solenoid 4 = CLOSED
Pump 1 = OFF
Pump 2 = OFF

{Inflate Tank 3}
Solenoid 5 = CLOSED
Tank 3 set Pressure = 3.5 psi
while (Tank 3 Pressure < Tank 3 set Pressure)
    Solenoid 1 = OPEN
end
Solenoid 1 = CLOSED

{Deflate Tank 3, Collect Data}
Tank 2 Start Pressure = Tank 2 Current Pressure
Solenoid 3 = OPEN
for (4 Seconds)
    X = Tank 2 Current Pressure - Tank 2 Start Pressure
    Y = Integral(Tank 2 Current Pressure, dt)
   
Graph(X,Y)
   
Save(X,Y) to user-defined filepath/filename
end

{Done}
Solenoid 1 = CLOSED
Solenoid 2 = CLOSED
Solenoid 3 = CLOSED
Solenoid 4 = CLOSED
Solenoid 5 = OPEN

Message 14 of 30
(1,695 Views)

Hi bmunden,

      I read your pseudo-code from top to bottom and it was very clear.  You could implement this on one G-diagram "plane" - from left to right, and I think it would be similarly easy to read.  You could also use a "state-machine" which allows arbitrary jumps from one section of logic to another - very much like the "GOTO" statement (long ago abandoned.)  The "State-machine" stacks planes of logic "hiding" them - making code less easy to read.  I think NI's state-diagramming tools help clarify what a "State-machine" does, though that's another layer of documentation to explain what the LabVIEW code is doing!  I'd avoid state-machines as a general-solution, though I'm certain Ben will disagree.

Cheers!

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Message 15 of 30
(1,681 Views)
Cool.  Some potential hang-ups I'm aware of are the "default" values of some of the solenoid binaries.  Also, when I run the test and save the file (in a while loop?), I certainly cannot have the while loop just hanging there with the solenoids shut while I'm waiting on the user to input a file name.  How would I ensure that the file-save is ready to go?

Could I put all the data in a RAM-stored memory array and then ask the user if they want to save that?  This would seem like a preferred method, since there's no guarantee that every test run will provide gorgeous data.  How could I do this?  (Block diagram pictures say a thousand words 🙂 )


Also, I know this code will always execute in this manner and order.  Just a thought.

Message Edited by bmunden on 04-15-2007 12:33 PM

0 Kudos
Message 16 of 30
(1,672 Views)
Hi bmunden,


Some potential hang-ups I'm aware of are the "default" values of some of the solenoid binaries.

I'd make a sub-VI to set all 5 solenoids at once.  A "Configuration File" (AKA "INI file") would allow you freedom to change "defaults" without changing your program-logic.  See "Configuration File VIs" on the File pallet (also search examples).  There are also VIs for manipulating values stored in the Windows registry, but I don't recommend going there.  Smiley Tongue:


 Also, when I run the test and save the file (in a while loop?), I certainly cannot have the while loop just hanging there with the solenoids shut while I'm waiting on the user to input a file name.  How would I ensure that the file-save is ready to go?

One way might be to always save data, and postpone the save/discard decision until after critical-functions (solenoid operation) have completed.  It's pretty simple to auto-generate a filename  - see attached - (though calling this vi twice within one second may result in duplicate file-names!)  This VI tries to create a unique file-name based on time, though you could just overwrite the same file[name] every run, and if you decide to "SAVE" just copy the temporary file to a new/unique path.Smiley Wink


Cheers!
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Message 17 of 30
(1,629 Views)
That sounds like a good idea.  How would I do that, though?
0 Kudos
Message 18 of 30
(1,605 Views)

@bmunden wrote:
That sounds like a good idea.  How would I do that, though?

Hopefully a VI is attached this time!  It generates a Filepath (see warning above re: potential for duplicate paths.)

To copy one file to another, use "Advanced File Functions\Copy" function (it's pretty simple - Smiley Wink -) - calling the attached VI should provide one (or both) of the two required (source, destination) path parameters!

(I don't think you were, but If you're asking how to create a sub-VI or how to use the "Configuration" VIs, please refer to the Examples under "Help". )

Cheers!


 

     

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 19 of 30
(1,598 Views)
Hmmm.  I'm still not sure how I would do create-then-save treatment in LabVIEW.

In pseudo, it'd be something like this:


"State 4"

    matrix = 0;

    while (conditions)
        sample data;
        append data to
matrix;
   
        if
(ready for state 5)
              state = 5;
        else
              state = 4;
        end

    end


"State 4"

    prompt "Do you want to save file?"

    If yes, then save it.

    If no, then expunge from memory.



0 Kudos
Message 20 of 30
(1,583 Views)