LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Run code Wait until condition is met Run next code, Repeat till count is filled. How???

Solved!
Go to solution

This one has me stumped on how to do it properly.

 

I am currently using the wait function, which I know is wrong, but it is allowing me to work while I try to fix it.

 

I need to switch an output high for a set time.  Then after that time switch a different output high. Repeat until count is reached.

This is one cycle.  I have hardcoded the timing on these, but actually have an input for time on my front panel before I hit cycle.

 

I can get it to cycle the correct number of times with a for loop, but would like to be able to cancel the test mid cycle.

As you guys know, can't do that with a wait command.

 

 

TheRednecknerd_0-1670368265476.png

 

 

This is my extend or retract only code.  I have it in an event loop looking for value change on Extend full or Retract full buttons.

They work great and allow me to cancel.  I have tried a state machine, but for some reason can't get it through a full cycle.

 

 

TheRednecknerd_4-1670368435298.png

 

 

TheRednecknerd_3-1670368398853.png

This is running in my while loop.

When the Boolean is high my output is high.

TheRednecknerd_7-1670369155814.png

 

 

 

 

 

TheRednecknerd_5-1670368775491.png

 

   

 

The parts of the VI that won't load have to do with Labjack hardware.  U6 to be precise.

 

I need to operate an actuator to the extend position then to the retract position while reading the feedback circuit.

I am currently reading 4 analog inputs.  (only using 2 at the moment, 2 for future sensors)

I am controlling the 2 analog outputs to switch a pair of SSRs that power the electric actuator.

My main loop is running at approx 20 ms.

 

As any of you that open my vi will find readily apparent, I could use better coding practices.

 

 

0 Kudos
Message 1 of 5
(954 Views)

Instead of a sequence worm, just create a state machine and things will fall in place.

 

(sorry cannot see your code. consider "save for previous" (2020 or older)  before attaching)

 

I would also recommend a few basic tutorials. Most likely you don't need any local variables and sequence structures. A one-iteration FOR loop is just a glorified sequence frame. Why are they even there?

Message 2 of 5
(895 Views)

I attempted a state machine.  But can't get it to hold until my first condition is met.

Hence the flat sequence that at least gets me testing for the time being.

But it's not something I want to release to my techs.

 

I either get both outputs on, or it runs the first bit and then stops.

 

I created a state machine with what I am trying to accomplish and saved it to version 14.

0 Kudos
Message 3 of 5
(867 Views)
Solution
Accepted by topic author TheRednecknerd

Well....... turns out I just really needed to verify my variables are set correctly.

 

While playing with the stand alone code I found that I had "time retract" instead of "time extend" extend selected in the state machines second state.

This messed up what I was trying to do. 

 

Thank you for watching this episode of the S#!t show and encouraging me on!

0 Kudos
Message 4 of 5
(859 Views)

Hi nerd,

 


@TheRednecknerd wrote:

Thank you for watching this episode of the S#!t show and encouraging me on!


Ok, some more suggestions for improvement:

  • Use less local variables! In the lower (event handling) loop you don't need any locals…
  • In LabVIEW the wire is the "variable", so one more reason to use less locals! (THINK DATAFLOW!)
  • Use terminals instead of your locals, they don't need to linger unused in your block diagram…
  • When there is no code in the TimeOut event and no timeout set then you don't need any TimeOut event case…
  • Without a TimeOut event case a parallel Wait function is senseless…
  • With a proper TimeOut event you don't need an additional parallel loop just to display your "Running In/Out" indicators! (And no second stop button just to end your small VI…)
  • Buttons should be placed inside their event cases!
  • A FOR loop set to iterate just once is just a sequence frame - and sequence frames are most often pointless( aka Rube-Goldberg)!
  • Why is CycleCount orange (aka DBL) when it just stores integer values??? The same applies to Cycle#…
  • Enums should be typedef'd - and their typedef should be used for EVERY instance!
  • There are primitives (functions) like "+1" - again "Avoid Rube-Goldberg!"…
  • Placing loops inside event cases is not recommend, especially when they (can) take long to process! Event cases usually should be handled within miliseconds…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 5
(823 Views)