LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Tune VI for use as a SubVI - ideas?

Hello all

 

I have made a VI with 3 while loops in it, but I need to use this as a subVI and thereby I would like to remove my while loops.. Right now I am kind of stuck in the programming, so I need some good advice how to make the same functionality without while loops.

This VI is supposed to take the derivative of any input waveform and make this into a TTL signal that can drive a motor through external hardware.

And like the name suggest is it a dual controller 🐵

 

I used the very good "code with your head under your arm" technique and it kind of backfired on me (well, I expected this to happen but anyways)....

I need to learn to make a flowchart or some kind of protocol to my program in the future, before I start the programming.... 

 

The motor feedback (the feedback function isn't finished yet - wanted to test the VI without feedback at first) is from a ADC (NI-9215) and the motor control output is the 32 Digital IO module (NI-9403). In the main program I also need to use the digital IO module, somaybe I should move all the DAQ stuff to the top level VI?

 

Please feel free to say what you think (I know it is crappy coding, sorry about that)

 

Thanks

Kind Regards

Tommy

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

i couldn't open the file because the version i use is older.

however it seems you are trying to synthetise a derivative controller.... right? as a PID controller except P and I = 0

 

perhaps, you could use the query block to extract data out of the while...(?) 

Or have the two vi's running simultaneously and comunicate them with a global variable (?) 

 

I hope this helps.. tell me if it does! (or doesn't)

0 Kudos
Message 2 of 7
(2,479 Views)

First, you need to work on your coding style in general. Try to avoid wires running backwards, try to align your code segments and minimize your wire bends, align items on your front panel and try to keep some whitespace in your code. It helps to make things more readable. I would also avoid using local/global variables.

 

As for how to make your code more modular the two lower loops are identical other than the data they operate on. I would make that a subVI with the appropriate inputs.

 

Likewise, the two blocks of code in your upper loop appear to be identical as well. You can create a subVI for that functionality as well. Pull out the data that is variable and make them inputs.

 

If you don't want these subVIs to include the loop simply remove the loop structure from the subVI. They will run once through then. Your calling VI will simply call the VIs in parallel. To ensure that you can have parallel operation make the subVIs reentrant.

 

As written, you  code has a race condition since it is using the local variables to pass data from the lower loops to the upper loops. If you rewrite the code as subVIs as I suggested you can call the subVI that was the lower code and simply pass its output to the subVI that was created from the code in the upper loop.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 7
(2,469 Views)

Hello

 

First off thanks for the advice !

 

Regarding the subVI with the two lower loops, right now they work as variable delayed counter modules for the array indexing in the upper loop. How can I convert them to a subVI and keep the the functionality? I want the two motors to be controlled separately, ie. with different delay times. Is this still possible when calling the subVI's in a loop?

As far I can see, converting the lower counting loops to a subVI and calling them from inside the upper loop is going to give me trouble, if one counting loop has a delay of lets say 10ms and the other has a delay of 100ms, then the whole upper loop has a delay > 100ms... This is going to be a problem when I want to controle the motors separetly!

Or did I miss something??

 

Regards

Tommy

0 Kudos
Message 4 of 7
(2,437 Views)

Tombech84 wrote:

Hello

 

First off thanks for the advice !

 

Regarding the subVI with the two lower loops, right now they work as variable delayed counter modules for the array indexing in the upper loop. How can I convert them to a subVI and keep the the functionality? I want the two motors to be controlled separately, ie. with different delay times. Is this still possible when calling the subVI's in a loop?

As far I can see, converting the lower counting loops to a subVI and calling them from inside the upper loop is going to give me trouble, if one counting loop has a delay of lets say 10ms and the other has a delay of 100ms, then the whole upper loop has a delay > 100ms... This is going to be a problem when I want to controle the motors separetly!

Or did I miss something??

 

Regards

Tommy


The differences are minor and the parameters can be passed in. I never suggested calling the subVI created from the lower loop in the upper loop. You do not have to keep the control for both motors in a single loop. You can use two loops loops, one for each motor. Since the motors are independent this is a better solution anyway.

 

One other thing that I noticed is that your code has lots of coercion dots (the red dots on terminals). This can lead to problems since that indicates that you are mixing data types. This is generally not good. You should always keep your data types the same and when they are different explicitly convert the types when necessary.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 7
(2,423 Views)
To be honest, I am having a tough time understanding exactly what you are trying to achieve. Your upper and lower loops each have data dependencies on each other through the local variables. This leads me to suspect you will run into race conditions. Can you provide a detailed explanation of what your are trying to achieve?


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 7
(2,417 Views)

The meaning with this VI is to create TTL control signals for two motors that I need in my project. I want to be able to control how the motor is moving by applying a random waveform (look at the picture) to the controller. From this waveform the VI should create a puls width modulation signal and hopefully the motor movement is somewhat equal to the waveform curve.

In addition to this I need to control how fast the motor is reproducing the curve (cycles pr. minute). The two motors are probably going to move by slightly different curveforms but they need to be in sync.

So my hardware motor controller has two TTL input pr. motor, and that's why I need to convert the random waveform to a PWM signal and output it on my NI-9403, and the feedback is going to be from a potentiometer connected to a reference voltage and input on a 16 Bit adc, the NI-9215.

The feedback part isn't implemented yet, but I am working on it.. I just wanted to make the controller as a subVI before I add functionality!

 

I hope this makes sense now.

 

I appriciate the feedback!

 

Regards

Tommy

 

0 Kudos
Message 7 of 7
(2,403 Views)