LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Constant iterative computation error

Solved!
Go to solution

Greetings everyone.
I have a program for interpolation of a monochromator step motor calibration table. The program takes the value of wavelength next to which monochromator at is and number of steps needed to reach that value. And then makes a subtable with interpolated values of wavelengths and steps to make multiple measurements for photoconductivity spectrum with delta being an interval between interpolated values of wavelengths. In the end of program I have an indicator for next value of wavelength which I move to at the next iteration of interpolation in the main program. Also in that program I made a check for initial wavelength value of current measurement iteration being higher than the one measurement has to stop, the latter I set manually.
And so getting to the problem. During the test experiments of obtaining photoconductivity spectrum I noticed that the measurement stops not at the wavelength value I set but at the next one. So I decided to check the condition satisfaction I mentioned above. It was found out that somehow after being moved to the required value it is not equal to one I set, e.g. 270 =/= 270. I moved to the interpolation program and modified it to test the same without executing the main program (Block diagram on the screen). And so the error keeps happening whether I play with representation (DBL, I32 and so on) or try to write nonsignificant zeros into the check control or anything else. Everything is correct only if delta = 1.
And so I do not know how to get rid of the problem. I know I can evade it for instance by setting a previous wavelength value to what I want to stop at, but I want to make a qualitative program without having to keep that in mind every time. So I am open to every solutions.

0 Kudos
Message 1 of 11
(2,417 Views)

The diagram shown is to messy to really tell what's going on from a picture alone. We prefer the actual VI and some typical data. Also set all controls to reasonable defaults before saving. Also tell us what result you expect.

 

  • Why is there a local variable for initial wavelengh if the control is right there? delete it and branch the wire!
  • Learn about autoindexing. No need for the array shift registers and built array nodes.
  • Index array is resizeable. You only need one instance.
  • Search array is dangerous because DBL comparisons are dangerous.
  • If the wavelength array is non-descending, you should use "threshold array" instead of "search array".
  • If you do it right (build the two elements in a array with two elements before autoindexing at the loop boundary), you don't need to transpose later.
  • Some of your shift registers (bottom one) don't look initialized. Is that what you want?

Again, please attach your VI!

0 Kudos
Message 2 of 11
(2,406 Views)

Hi Nodrael,

 


@Nodrael wrote:

It was found out that somehow after being moved to the required value it is not equal to one I set, e.g. 270 =/= 270.


NEVER compare floating point numbers for equality! (Learn about IEEE754/854 definitions, rounding rules and accuracy of floating point numbers…)

One more item: that "initial wavelength" local is not needed: use more wire!

Best regards,
GerdW


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

Hi, 
Here is my program. In this case the "wavelength to" value has to be equal to next to "initial wavelength" value in the calibration table. Also there is a part of the table I use for testing and compiling.

Download All
0 Kudos
Message 4 of 11
(2,351 Views)
  • All your controls are zero (init wavelenght, delta, etc.). What are typical values?
  • What should be the initialization of the lowest shift register? Zero? Something else?
  • What result do you expect in "appended array" given your current sample file?
0 Kudos
Message 5 of 11
(2,346 Views)
  • For init wavelength I use values from the test file (the first column - wavelength values, the second - number of steps needed to reach the wavelength value of the respective index from the previous one), delta represents interpolation coefficient i.e., for instance, I use delta = 0,2 which means the interval between two neighbouring wavelength values is to be divided into 5 smaller intervals with respective values of steps to move from one value to another.
  • I guess it's zero, but I didn't met any problems with interpolation because of that. This shift register is used for better approximation of step values in interpolated table, because they have to be integer.
  • The result is supposed to be subtable representing interpolated interval between two neighbouring wavelength values from original table with delta between new values set in the respective control and step values as I described higher.
0 Kudos
Message 6 of 11
(2,344 Views)

The answers to all my questions are simple numbers, not long confusing paragraphs. 😉

 

Given the current file:

  • initial wavelength?
  • Delta?
  • expected result?

If you don't initialize the shift register, it's initial value will be the last value from the previous run. It will only be zero after the first loading and after recompile.

 

If all values are integers, why is all your code orange???

What do the values in the second column represent?

 

You are making a lot of assumptions about the initial data, e.g. that the initial wavelength actually exists in the file, that all data in the file are integers, and that the spacing between wavelength in the file is exactly one. What should happen if any of those assumptions are not true?

 

There are better and simpler ways to interpolate.

0 Kudos
Message 7 of 11
(2,307 Views)

Your problem descriptions is still very unclear.

 

Here is a quick draft that might give you some ideas how to simplify. You still need to deal with the exceptions mentioned.

 

altenbach_0-1575480474561.png

0 Kudos
Message 8 of 11
(2,304 Views)

As I mentioned above the program itself works fine. The problem occurs only when it's needed to compare the value contained in "wavelength to" indicator with the preset one. If you try to create a double numeric control and write there, for instance, 359, it will not be equal to 359 in the indicator. That was the original problem.

0 Kudos
Message 9 of 11
(2,297 Views)

You cannot compare floating point numbers for equality.

 

https://floating-point-gui.de/errors/comparison/ 

0 Kudos
Message 10 of 11
(2,294 Views)