LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I reset a formula node input to 0 after I finish the program?

Solved!
Go to solution

So in my program the shift register sends its value to Sump, an input of the formula node.

When I press the STOP button Sump will still have the last value of the shift register so if I start the program again Area will have an initial value (not 0) since its formula is Sumc=Sump+((Xc-Xp)*(Yc-Yp))/2 and Sump starts with a previous value.

How can I reset Sump to 0 when I press the STOP button?

Download All
0 Kudos
Message 1 of 19
(3,847 Views)

Hi patomated,

 

to answer your message title: You CANNOT do anything in your program after the program has finished…

 

How can I reset Sump to 0 when I press the STOP button?

I don't see any "STOP" button in your image: you deleted terminal labels! Never do this!

 

Edit:

- NEVER DELETE TERMINAL LABELS! What kind of event do you have here? A value change of "", ""??? When the labels disturb you: HIDE THEM on the front panel!

- What's the purpose of the inner WHILE loops? They either iterate just once (then you don't need them) or they run forever (then your VI isn't usable anymore)!

 

To solve your question: You need to initialize the shift register! I would do this rather at program start instead when stopping (aka "finishing") the VI…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 19
(3,829 Views)

Sorry I fixed the stop button.

The title is a bit misleading you are right, what I meant is when I press the STOP button I want Sump to reset to 0. 

In my case when I press the STOP button the shift register sends its last value to it.

 

How can I initialize the shift register as 0? Adding an input to it does not work.

 

Thank you for helping

0 Kudos
Message 3 of 19
(3,816 Views)

Hi patomated,

 

Sorry I fixed the stop button.

NO, YOU DIDN'T!

 

DON'T DELETE THE LABELS…

 

when I press the STOP button I want Sump to reset to 0. 

Some pseudocode:

IF STOP
  THEN SYMP:=0
  ELSE SYMP:= result of overkill formula node

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 19
(3,802 Views)

Your inner while loop have no purpose than to act as a scaffold for your shift registers, they never iterate more than once. delete them and place all needed shift registers in the outer loop, where you can initialize them at program start.

 

Delete the hidden indicators and local variables for xindex and yindex. all you need is an initialized shift register containing an array of two elements, one for x and one for y. Nothing on the front panel. It even seems that xindex and y index are always the same, so just keep a single "index" instead.

 

You have serious race conditions, because incrementing the xyindex and reading the xyindex can occur in random order, but the outcome critically depends on the order.

 

You have many datatype mismatches. Try to eliminate all the coercion dots.

 

Why do you need "select" nodes if both inputs are the same? (right side of main loop)

 

Never delete labels (your buttons) if you don't want to show the label on the front panel, right-click to hide the label. Always show the label on the diagram for self-documentation.

 

Why does the event structure have two boolean output tunnels. Branch he wire outside instead.

 

Instead of a 2D array to keep the xy graph data, use a complex 1D array. Simpler code!

 

It is not clear why you are autoindexing the array in one place and not in another. It seems you want the first and second element, so just use a single tunnel and single index array.

Message 5 of 19
(3,794 Views)

@patomated wrote:

So in my program the shift register sends its value to Sump, an input of the formula node.

When I press the STOP button Sump will still have the last value of the shift register so if I start the program again Area will have an initial value (not 0) since its formula is Sumc=Sump+((Xc-Xp)*(Yc-Yp))/2 and Sump starts with a previous value.

How can I reset Sump to 0 when I press the STOP button?


WTFWYT <Face-palm> those local variables have no flow control to tell you when they are updated in regards to when the terminals are read!  Both While loops in the event case<"","":Value Change> either execute once or are infinate loops! (Trigger the event, then read the controls once, then start executing those greedy loops untill you mash the "Abort" button and the CPU has time to process that nasty command!)

 

OH those boolean controls are "Latchers" True when the event fires so the while loops are single-shot garunteed! (Why are there loops then.... just, run though that once again....)

 

I gotta give you applause for the use of the select primitaves!  "If Bool is True or False output the same value" (Not that the Bool could be False when the stop condition for the outer loop is True)

 

Did you forget to grab a cup of coffee before coding that?


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 19
(3,775 Views)

 

 

Thank you so much for the detailed help. I'm still new to LabView and was not aware of many alternatives you are suggesting.

 

So far I have:

>fixed the shift registers and placed them on the outer loop

>restored the labels

>used 1 index for x and y

 

I used the select nodes because I couldn't find another node that takes a boolean and outputs a double.

 

Also you suggested that I remove the local variables, but then how can I increment the Index whenever I press Next Point?

 

Concerning the autoindexing, I am writing an additional Column whenever I press Next Point, so autoindexing reads the value from the first row always (as far as I know), in the second one I removed the autoindexing and added a ROW index of 1 so it can read the second row always and change columns with the button press.

 

Here's where I'm at so far.

 

Again, Thanks for your help. Greatly appreciated 🙂

0 Kudos
Message 7 of 19
(3,750 Views)

Hi patomated,

 

I used the select nodes because I couldn't find another node that takes a boolean and outputs a double.

Put the "-1" inside the while loop and wire it through the loop border to your "index" local variable - THINK DATAFLOW!

 

There is so much more to clean up and fix…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 19
(3,745 Views)

Hi 

 

I've just started using LabView (3 days ago to be exact), so I'm trying my best to learn through videos, books, and the ni forum so no need for applauses.

 

The loops do not run continuously, they execute and exit whenever I press the button "Next Point" (I re-added the labels) since it is connected to their stop if true button. However I removed one of the while loops as altenbach suggested.

 

I'm still working on improving it.

 

Thanks for your feedback.

0 Kudos
Message 9 of 19
(3,741 Views)

Worked like a charm, thank you 

0 Kudos
Message 10 of 19
(3,731 Views)