08-13-2018 06:12 AM
Hey there,
I know, this question is quite for beginners/stupid. But I'm stuck to a certain problem for my FROG LabVIEW program. Found nothing specific by google and in here... The program is state machine based. The certain states will initialize variables, calculate the scanning parameters, control the scan process and collect the necessary position data.
The attached screenshot is showing the scanning and position aquiring process. The axis will go to a certain position and will then move the defined scanrange in small steps. For each step, the programm will compare the desired position to the actual position, returned by the motion controller. Is the position within a range, the axis will move the next step. This is repeaded "number of steps" times. This number is depending on expected pulselength and stepsize.
Now my problem: I want to fill an array, where the row/index is equal to the current step number. At the moment, the array should have three columns, and of course as many rows as steps. Column one should be filled with the index/step number, the other to with the desired and actual position. Since I'm using a state machine, I'm obviously within a while loop. I know, that, in general, such an array can be build, by having the data collecting process inside a loop and the array outside. With a shift register, the data will be auto indexed by the iteration i. But, afaik, it's better to avoid loops in a loop.
So, how to initialize a "num of steps" x 3 array inside a loop, without using an additional loop with shift registers? The screenshots show my current "solution". In the state, where the scanning parameters are calculated, I initialize my array. It is filled with data in the scan state. Is this "correct" or are there any other solutions? Doesn't seem to be a good solution atm...
Hopefully the attached code is enough. Just need to know the basic principle of initialize and fill this array with data 🙂
Solved! Go to Solution.
08-13-2018 06:35 AM
Hi Johannes,
Hopefully the attached code is enough.
No, we cannot debug images using LabVIEW.
We could work with VIs…
Just need to know the basic principle of initialize and fill this array with data
- Why don't you put the array into the cluster you already use to hold state data?
- Why do you need additional local variables? When you don't like to mess with the cluster you should use shift registers!
- Why do you initialize the array with "current step number" rows (all values set to NaN) and insert more rows later on? Either use InitArray with ReplaceArraySubset or create an empty array and inster rows later on!
08-13-2018 09:01 AM
-No, we cannot debug images using LabVIEW.
Shure, know that. Just wanted to give an expression of my program. All the other parts are unimportant for my problem. Screenshot of my code would have been the correct expression. My basic problem is, how to fill an array inside my state machine. I'll need the data within my state machine for following states. For example the spectra I'll record for each step. But if you need a VI to help me, I could try to put my problem in one, withouth any instrument related (sub)VIs and so on.
- Why don't you put the array into the cluster you already use to hold state data?
- Why do you need additional local variables? When you don't like to mess with the cluster you should use shift registers!
Going to do that. Just wanted to get it to work, then implement these. I'm quicker this way, first set up program parts with local variables and so on, then include my clusters and tidy up 🙂 I'm not using Labview that long, so I need some time from idea to working code.
- Why do you initialize the array with "current step number" rows (all values set to NaN) and insert more rows later on? Either use InitArray with ReplaceArraySubset or create an empty array and inster rows later on!
Actually, I didn't knew, that additional rows are added. Still having problems to understand array handling in Labview. That's the first version, that kind of does what I want, and I know that it's not the way to do it. That's why I opened this thread 🙂
I thought: I got NN steps. For each step, I want to record the position (and later the spectrum). So, I need NN rows, each for one dataset at the corresponding position. Also, I learned from Labview books, that it's better so initialize an array with the size and fill it completely with 0 or NaN. Then, each field should be filled with the desired values by overwriting each 0/NaN. "number of steps" is equal to the number of datasets and "current step number" is equal the row index.
Maybe again in short: I got NN steps, so I need an array with NN rows. I want to fill this array with data (several columns) at each step. One step is equal to one row and it should be indexed by the step number. How can I do that, without adding everything into an additional loop?
If I would do it like that, I'm going to have problems, because I can't add (easly) intermediate states. And a state machine for data aqusition in my main state machine didn't seem to be proper.
08-13-2018 09:50 AM
08-13-2018 10:11 AM - edited 08-13-2018 10:11 AM
well... 😄
Changed to replace and I actually get the correct indexed and filled array (See screenshot). That's it? Just have to implement the array into my cluster and get rid of the local variables? Damn, I feel stupid if that was my problem...
08-13-2018 10:24 AM - edited 08-13-2018 10:25 AM
@JohannesLutz wrote:
well... 😄
Changed to replace and I actually get the correct indexed and filled array (See screenshot). That's it? Just have to implement the array into my cluster and get rid of the local variables? Damn, I feel stupid if that was my problem...
Don't, these are common "text programmer learning LabVIEW" issues. Dataflow takes a different mindset than lower level languages like C++/ C#.
You'll find lots of examples like yours on these forums. Look around and learn from others "silly" mistakes
None of them mine of course;)
08-13-2018 10:37 AM
Thanks for your help! 🙂
08-14-2018 10:27 AM - edited 08-14-2018 10:28 AM
ok, got one more question regarding array/cluster for my data. Or I just want to make shure, my array handling is fine 🙂 Well, not just a single question...
The way I predefine my data array, is that appropriate? I put an array constant into a cluster constant. The array constant is filled with DBL constants. I was wondering, if it makes sense, to put in as many DBL, as columns I'm going to use. If I use the insert function, my last row is just zero. Replace will only replace the predefined row, others are empty (of course).
-Is it recommendable, to put a DBL constant for each row into my array constant or is just one enough?
-Shall I fill the predefined array with n columns and N rows, determined by number of steps and needed columns? So as before, when I initialized and filled my array with 0/NaN, and then use the replace function. Or just fill the empty array with the insert function?
08-14-2018 10:32 AM
@JohannesLutz wrote:
-Shall I fill the predefined array with n columns and N rows, determined by number of steps and needed columns? So as before, when I initialized and filled my array with 0/NaN, and then use the replace function. Or just fill the empty array with the insert function?
It is best to preallocate your array and then use the Replace Array Subset. Use Initialize Array to create your array.
08-14-2018 10:40 AM - edited 08-14-2018 11:04 AM
alright! So empty array constant in cluster constant, initialize the array and then replace each row in my acquisition states. Thanks man!