04-24-2021 05:04 PM
So my code has multiple very similar loops which must run in sequence as given in the snippet. The only difference between them is the reference each of therm get. First loops get a reference to move the Y axis motor while second loop gets the reference to move the Z axis.Now since each of these references are just local variables is there a way I can put them in an array and do only one loop instead of multiple such while loops.( I want to add loops for the other axes motors a swell, like X , Yaw, Pitch etc.,)
Solved! Go to Solution.
04-24-2021 09:39 PM
Your picture is just way to small for us to be able to look at in order to try to decode what you are trying to say in your message.
Do you really need local references?
Yes you can build references into an array using Build Array.
04-25-2021 12:33 AM - edited 04-25-2021 12:35 AM
As RavensFan said, you can use Build Array and a For loop with the references you want to use.
You might run into difficulties if the references have different types (because the array wire will be of the closest shared parent type) in which case you might have better luck with an Object-Oriented / class-based approach (see below).
Edit: It looks like at least the example you gave uses two axes that are both "Modular Stepper Motor"s. To clarify, if all of your references have the same type (or are close enough that a shared parent type exposes the methods you need) I would stick with the raw references for simplicity in this case (although your case might become more complex, etc... up to you to determine if classes might be better, feel free to post more details).
That could look something like:
04-25-2021 05:32 AM
Hope this is much better
04-25-2021 05:41 AM - edited 04-25-2021 06:36 AM
**As RavensFan said, you can use Build Array and a For loop with the references you want to use.
You might run into difficulties if the references have different types (because the array wire will be of the closest shared parent type) in which case you might have better luck with an Object-Oriented / class-based approach (see below).**
Will try using for loop with build array. Don't know much about classes, will have to read on that.
**Edit: It looks like at least the example you gave uses two axes that are both "Modular Stepper Motor"s. To clarify, if all of your references have the same type (or are close enough that a shared parent type exposes the methods you need) I would stick with the raw references for simplicity in this case (although your case might become more complex, etc... up to you to determine if classes might be better, feel free to post more details).
That could look something like:
I can't bild a type for each type of motor( stepper, piezo etc) Each motor will have to have its own .NET reference. This is a limitation of the references provided by the manufacturer of the motor stage.
**
I have given a much clearer snippet now as a reply to RavensFan, do have a look.
Edit: So a build array work fine. I attached the array to an auto indexed while loop, something like this
Just one issue, I would want the array to wraparound itsef. i.e: after 4th iteration go back to the first array element to continue running the while loop until the stop condition is met. How should I do this??
Thanks a lot
bajajvishal11
04-25-2021 07:07 AM
@bajajvishal11 wrote:
Just one issue, I would want the array to wraparound itsef. i.e: after 4th iteration go back to the first array element to continue running the while loop until the stop condition is met. How should I do this??
To go with the quickest point first, use a While loop (because you want to continue indefinitely, from the point of view of number of iterations) and then use Quotient and Remainder with the divisor equal to the Array Size, and Index Array with the remainder as the index.
Something like this:
Here of course is just an example, I used Doubles but you'd want to use your reference array.
@bajajvishal11 wrote:That could look something like:
- build a class for each type (but not necessarily each direction, etc)**
I can't bild a type for each type of motor( stepper, piezo etc) Each motor will have to have its own .NET reference. This is a limitation of the references provided by the manufacturer of the motor stage.
**
- provide it with methods to write the reference (data accessor, you probably need to call these before you start doing anything, and possibly before you build an array, so a 'constructor' type method might be appropriate
- provide it with some actions that you need to carry out ("Set Position"?). In these (dynamic dispatch, public) VIs, carry out the appropriate action. I also can't see your image well enough to determine what that might be...**
Hmm, I think you didn't understand what I meant (or maybe I don't understand what you meant...) but you could do this. You'd create a class for Piezo, a class for Stepper etc. Then build an Object (instance) of that class for each axis you wanted to control, and give the object that reference as an input.
But if you can use the .NET references in an array and have the operations you need (e.g. the movements) then you can just do that instead, probably easier and less stuff needed.
04-25-2021 04:49 PM
The code worked fine exactly.
I didn't know how classes worked in Labview. Read on it. What you said made complete sense, but I guess I'll stick to this approach since its simpler and I only have 6 motors to control. Creating a Class seems overkill.
Thanks a lot.
bajajvishal11