LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Add more input to the same code

Solved!
Go to solution

Hi everyone. Need your help again. As you can see in the pic, there are 8 motors with 3 inputs, velocity and acceleration are numeric inputs and direction is Boolean. What I am trying to achieve is that, change this completely so that in the future they can add as many motors without copying the code for each motor again and again. Should be able to add as many motors on the existing code. I am thinking about this as hard as I can, but if someone can give me a small idea on how to go with this, please kindly enlighten me. Thanking You in advance.
Motors.pngMotors.png

0 Kudos
Message 1 of 7
(2,462 Views)

Hi govindsankar,

 

give me a small idea on how to go with this, please kindly enlighten me

Do you really don't know how to use arrays?

 

When you need to handle several elements, all of the same datatype, you should use arrays of that element!

Best regards,
GerdW


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

Yes I know how to use arrays. Here what I have is 8 motors as hardware. I have 8 motors and u see in the labview gui, there are 8 motors each having velocity, acceleration and direction. Motor 1 velocity in GUI will control the velocity of the actual motor 1 and similarly for acceleration and direction and then similarily for remaining 7 motors. Now in the future if we add an extra motor to the hardware I or someone else need to code again the same thing which was done for the other 8 motors. My boss says we dont want that. I can change the code in any way as I want, but we should be able to add a new motor without changing the code. Is that possible. I had thought of using these same inputs motor 9 will be controlled by the motor 1 inputs in the GUI. But if I do that then motor 9 and motor 1 cannot be switched on at the same time. So that is a problem. Let me please know what should I l know in order to do that.  

0 Kudos
Message 3 of 7
(2,448 Views)

I am thinking right now that is not possible. If I add a new motor I will need to add new inputs. Maybe I can use the same code from input to output. That can be same. But definitely new inputs are needed. That is what I am thinking. Just confirm that and I can move on with this code. 

0 Kudos
Message 4 of 7
(2,446 Views)
Solution
Accepted by topic author govindsankar

Hi govindsankar,

 

If I add a new motor I will need to add new inputs.

Yes. Those "new inputs" are just one new element in an array of "motors"…

On the UI you can use just one (1) input for motor values and an additional selector (enum?) to address the motor to apply the input values…

 

Maybe I can use the same code from input to output.

Sure: use an (autoindexing) loop to handle all elements of the array.

 

Hint: I prefer to separate the UI representation from data handling in the background. This way you can use different data structures on UI and in your program…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 7
(2,433 Views)

What do you mean by selector enum. An enum consisting of numbers and a case structure. Selecting number 1 in enum will select case 1 which has code for motor 1 and then input values are passed into it. Then you can change the input value and select another value in enum which will change the case and hence that motor will be controlled. This way I only need one set of inputs and I can control multiple motors. If I add more motors in the future, I just need to update the enum and add a new case with the same program. That is a good idea. Thank You. So this is what u meant. Just correct me if there are any corrections. 

0 Kudos
Message 6 of 7
(2,424 Views)

To add to Gerds answer, having a 1D Array of motors (clusters) is the way to go. In your UI you're presenting it as a 2D representation. All that is needed is a Reshape Array to shift between the two. 

Also, if the current display is a cluster of motor clusters, you'll need to change it to a 2D Array of motor clusters for things to be easily scaleable.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 7 of 7
(2,421 Views)