LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to keep the block diagram/ front panel clean?

Solved!
Go to solution

Hello,

 

I am relatively new to Labview so I'm not able to tell if I'm overcomplicating my programs or making my block diagram too cluttered. I was wondering if there were some ways to tell whether I could simplify my programming just by looking at it (perhaps only experience helps for these things) ? 

 

I have attached my VI here. Currently, it has the capability to monitor the voltage and current from two motors. On display, you can see a indicator with the voltage and current values and there are charts toward the bottom that can display waveforms from different motors with a drop down menu. 

 

The front panel is rather clean in my novice opinion, but the block diagram seems messy to me, just at first glance. I foresee a problem occuring in the future however. In the future, I will have to scale the VI to monitor 50 motors. All the programming will be the same as the one I have now, except it will have 50 indicators and unfortunately 50 times pretty much everything. I would like to avoid this, but I'm not sure how I could.

 

I am using a USB 6009. I am using its four differential inputs to monitor the voltage and current of two motors. In the future, I will be getting more DAQ units (25 total because 2 motors can be monitored for each DAQ). The new DAQs will help will help with more resource space, but I think complicate things with the additional potential of 24 more DAQ Assistants (as used in my code). 

 

Thanks for any help you might be able to provide!

0 Kudos
Message 1 of 9
(5,210 Views)
Solution
Accepted by msiwk

It usually is mainly experience that will teach you the best methods to make your code look pretty. I don't know anyone who is proud of their first from-scratch application. There are a few resources out there to help with best practices, like this group on ni.com, but you'll learn the most from your own development.

 

Your front panel looks great. FPs in general are really up to you. You can make it look as ugly or pretty as you want. When you have some duplicate controls and indicator groups, you should utilize clusters and arrays to simplify. You could use a little bit of cleanup in that regard, but not much. Also, personally, I hate reading red text unless it's a warning of some sort.

 

Your block diagram could use some cleanup in a modularity sense. You have a lot of repeated code, which you could consolidate in to a subVI that is used in multiple locations, or in a For loop. A general rule of thumb is to keep your block diagram within a single monitor. You shouldn't have to scroll. Your application is pretty simple, so it's hard to mess it up Smiley Happy

 

Here are some specifics about your block diagram:

  • Right click your terminals on the block diagram and uncheck "View As Icon". You're welcome.
  • Duplicate operations on each waveform "(x*2-4)/16": create subVI and/or run the waveforms through a For loop.
  • You do a lot of 2-element arrays and then indexing. Just replace those with a Select node based on the numeric.
  • All of your code is running every time, including your property nodes at the bottom, which is unnecessary. As you learn LabVIEW architectures, you will learn how to bypass this with initialization and exiting code, but for now you should put a case structure around those for only when the motor numbers change.
  • I'm not sure how you're timing your main loop, but you should put a delay in there because you don't need the DAQmx node to be pulling as fast as your CPU will allow.

 

There are free intro videos you can watch to learn what NI would suggest in terms of coding and teach you some of the basic features and such. Here's a three hour course, and here's a six hour course.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 2 of 9
(5,197 Views)

Thank you for the reply. The multiple indicators are so that all the values can be viewed together and I figured they aren't too big to present a problem (although with more values to monitor, I guess it could present a problem).

 

I figured no scrolling on the block diagram would signify good code, but are there any instances where that's not possible? My guess would be that you can always break up the code into SubVi's to avoid too much code on one page, but like I said, I'm new to Labview so I'm not sure. Could you expand a little bit on what you mean by using subVi's for repeated code. I've heard of it, but I'm not exactly sure how to works and where it could be applied. I'll be sure to look up resources on this topic as well.

0 Kudos
Message 3 of 9
(5,172 Views)

Oh whoops, you included specifics. Not sure how I missed that. Thanks

0 Kudos
Message 4 of 9
(5,170 Views)
Hehe, yeah, sorry. I went back and edited the post to add the specifics. That's the only thing I don't like about this forum, there's always new info or someone else posts while I'm typing up a response.

The easiest way to create a subVI is by selecting the code you want, right-clicking, and selecting Create SubVI. SubVIs are another file that you have to save with your code, so make sure you keep it all together.

Really, you should watch some training videos to get a better grasp of LabVIEW's functionality.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 5 of 9
(5,153 Views)

@James.M wrote:
Hehe, yeah, sorry. I went back and edited the post to add the specifics. That's the only thing I don't like about this forum, there's always new info or someone else posts while I'm typing up a response.

The easiest way to create a subVI is by selecting the code you want, right-clicking, and selecting Create SubVI. SubVIs are another file that you have to save with your code, so make sure you keep it all together.

Really, you should watch some training videos to get a better grasp of LabVIEW's functionality.

This is the easiest, but (at least from a block diagram cleanliness perspective) not usually the best way to create a subVI.  This creates an ugly gap in your block diagram and you have to shift stuff around to fill up the hole.  The best way is to have in mind the subVIs to begin with.  (Think about each paragraph of a requirement to be a subVI, for instance.)  Create them and drop them onto your block diagram.  I think it was Altenbach that gave me the idea to use a one-frame flat sequence structure to attach all the input and output wires of your "proposed" subVI, select the flat sequence structure and create the subVI from that.  (Don't forget to eliminate the flat sequence structure from your SubVI!)  That way the hole will only be as big as the flat sequence structure.  Create your code inside the newly created subVI.

 

It's easier to start and maintain a clean block diagram than it is to let it get messy and then try to clean it up all at once.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 6 of 9
(5,113 Views)

@billko wrote:

This is the easiest, but (at least from a block diagram cleanliness perspective) not usually the best way to create a subVI.  This creates an ugly gap in your block diagram and you have to shift stuff around to fill up the hole.  The best way is to have in mind the subVIs to begin with.  (Think about each paragraph of a requirement to be a subVI, for instance.)  Create them and drop them onto your block diagram.  I think it was Altenbach that gave me the idea to use a one-frame flat sequence structure to attach all the input and output wires of your "proposed" subVI, select the flat sequence structure and create the subVI from that.  (Don't forget to eliminate the flat sequence structure from your SubVI!)  That way the hole will only be as big as the flat sequence structure.  Create your code inside the newly created subVI.

 

It's easier to start and maintain a clean block diagram than it is to let it get messy and then try to clean it up all at once.


Well put. I've been using flat sequence structures to do that for a while and I'm glad to hear I'm not the only one.

 

My initial suggestion to make a subVI that way was intended for a newbie to understand their purpose. I don't think I understood what a subVI was (long ago) until I was looking at my block diagram thinking "where can I shrink this code I already made too big", just like OP is thinking.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 7 of 9
(5,106 Views)

 


It's easier to start and maintain a clean block diagram than it is to let it get messy and then try to clean it up all at once.


 

Perhaps, but cleaning it all can be therapeutic, kind of like cleaning the kitchen or your room. Maybe that's just me Smiley Happy 

 

Message 8 of 9
(5,098 Views)
I don't mind cleaning block diagrams but, like the kitchen, it is usually much better to clean up as you go.

I don't notice cleaning up one plate after eating, a few plates may even be relaxing but cleaning up an entire sink (especially if it was not your mess) is no fun.
Matt J | National Instruments | CLA
0 Kudos
Message 9 of 9
(5,024 Views)