LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array operations and for loop

Hello,
The code attached basically only uses array n for loop. It's supposed to define the path in YZ plane for my two motors. The first frame in the sequence does that and creates two 1 dimension arrays, named Y-Array and Z_Array. The remaining frame seperates 1 element at a time from each of the arrays (in some other code, I will transfer this coordinate as target positions for motors).
I am calculating two values N_Y and N_Z, which define how many time the for loop should run. When this run stops, I am expecting no elements left in "Remaining Y_Subarray" and "Remaining Z_Subarray". However, it always leaves some element. I may be need to add some integer to N-Y and N_z, but I am not sure. I not want to run the for loop for iteration just enough to do this, else it's generating error when I am combining with stepper motor code.

(I was using while loop previously and only running that till there is no element left. However, when I tried to integrate that with stepper motor code, it was running indefinitely. One guy suggested me using for loop ashe told me that for while loop using "x=y" condition was responsible as both of them were DBL.)

Please suggest me something.

Thanks,
Dushyant

Message Edited by Dushyant on 04-18-2005 05:31 PM

0 Kudos
Message 1 of 4
(2,754 Views)
There are many problems with your code - It's undocumented, you have things overlapping each other, you have the same code in multiple places, you have a race condition (unconnected code outside the frames) and you even have something unwired (Y Target).
I suggest you learn more about LV by searching this site and google for LabVIEW tutorials. Here is one you can start with and here is another. You can also contact your local NI office and join one of their courses.

All that said, if I understand you correctly, you need to have N_Y*N_Z = Array size. I'm not sure if this is happening. Even if it is, I think your problem is that for the entire first iteration of the OUTER loop, you keep taking the whole array, thus missing all those times to remove elements from the array.

I think you have some bigger problems than this, though. For one thing, converting to a cluster and then back is completely unnecessary. You could simply use index array instead, and it would extract the first element. A much larger problem is "what are you going to do with this?". At the moment, you're constantly writing to local variables. This seems completely unnecessary. In fact, I'm fairly sure that there would be a much simpler way to accomplish your target than how you're doing it the moment, but since I can't follow your code, I'm not sure what your target is exactly. I strongly suggest that you sit down and design the solution to the problem before doing it like this. I would also suggest again that you think about those courses. They have some invaluble information.

___________________
Try to take over the world!
0 Kudos
Message 2 of 4
(2,723 Views)
I agree with tst that your code is way too convoluted to really debug it. I have given you some tips a while ago and you should really try to simplify things. To better illustrate, I have made a few simple adjustments to translate your code into a diagram according to my earlier suggestions. I think it solves your current issue, but please test and possibly make some adjustments.

I truly believe that both VIs can be simplified MUCH more, for example if you would really only need the y_target and z_target scalar outputs, you could just autoindex the X_array and Z_Array into a single FOR loop containing ONLY the two scalars.


Your first priority should be to stay away from local variables and stacked sequences, they are virtually never needed in such programs and they tend to make code maintenance very difficult. They are bad form!

Please let me know if you have any questions. Happy wiring! 🙂
0 Kudos
Message 3 of 4
(2,718 Views)
Thanks a lot guys for helping me out!!

I will follow your suggestion/s while writing next code. Actually, I am learning it on my own and so, sometimes
I am not aware of good code writing practice. That's why I had been using stacked sequence and local varibles too much.

Thanks again,
Dushyant
0 Kudos
Message 4 of 4
(2,698 Views)