LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Nested FOR loops and flat sequence - A good design ?

Hi,

 

My idea is to design an optimum modular program which is best on compiler optimizations.

 

Right now, I have 3 FOR loops with flat sequences based in each one of them, the execution is in sequence becacause I have to move X motor and then Y motor and repeat until END.

 

 

But I am not sure if this is best habit to be followed when programming. Please do advise what other methods can be followed.

 

 

NOTE: There is no actual working code here, just a illustration of the method I had been doing till now.

Thanks.

 

PS: Please find the attached VI.

Abhilash S Nair

Research Assistant @ Photonic Devices and Systems lab

[ LabView professional Development System - Version 11.0 - 32-bit ]

LabView Gear:
1. NI PXI-7951R & NI 5761
2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021

OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
MEMORY - [ 16.0 GB RAM ]
GPU - [ NVIDIA GeForce GT 530 ]
0 Kudos
Message 1 of 11
(3,978 Views)

My own personal preference is to never use a Flat Sequence (unless dragged kicking and screaming).  Most VIs have the Error Line running through the bottom corner -- you can enforce Data Flow (which you are also getting with the Flat Sequence) simply by connecting Error Out of the first VI to Error In of the second.  Look at your diagram, and imagine how it would look with no frames, but with an Error Line running through it ...

 

Here's a picture of what I'd do.  Note I've used a "Dummy Sub-VI" everywhere -- you would, of course, have a "Move Motor Y", "Delay", "Move Motor X", etc. VI, each with a clear icon so you could look at the Block Diagram and instantly see (without the Big Blue Labels) what is going on, and with the sequence "defined" by the Error Line running through it.  Your Diagram will be much easier to read, much less cluttered, and can be much smaller (so it fits on a single screen).  [Note that an important part of this trick is writing all of those sub-VIs -- Sub-VIs Are Your Friends ...].

 

BS

Imaging Sequence Idea.png

0 Kudos
Message 2 of 11
(3,957 Views)

Thanks.

 

There are quite something that I dont understand from the figure you posted. What are the "references" [ please see the highlighted boxes in the edited figure you posted below] , why should we use them ? 

 

Presentation1.png

Abhilash S Nair

Research Assistant @ Photonic Devices and Systems lab

[ LabView professional Development System - Version 11.0 - 32-bit ]

LabView Gear:
1. NI PXI-7951R & NI 5761
2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021

OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
MEMORY - [ 16.0 GB RAM ]
GPU - [ NVIDIA GeForce GT 530 ]
0 Kudos
Message 3 of 11
(3,938 Views)

Those references are caused by flaws in the built-in VI snippet tool.  It takes the implicit property nodes and breaks them into a reference and an explicit property node.  I'm sure on Bob's real VI, he did not have those reference controls, just property nodes that were implicitly connected to a particular control.  The problem with the built-in VI snippet tool is that it breaks that connection, and now you don't know which property node was linked to which control.

 

The better solution is if Bob had used the Code Capture Tool.  It does not break the references.  It leaves the property nodes intact.

 

Please go and vote for the idea Treat Code Snippets as "Copy and Paste" instead of "Create Sub-VI" to fix the built-in VI snippet tool.

0 Kudos
Message 4 of 11
(3,916 Views)

Ok so how does one get to create a sub VI with error handling technique in it. Can some one point me to any tutorial or example I can learn from.

Abhilash S Nair

Research Assistant @ Photonic Devices and Systems lab

[ LabView professional Development System - Version 11.0 - 32-bit ]

LabView Gear:
1. NI PXI-7951R & NI 5761
2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021

OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
MEMORY - [ 16.0 GB RAM ]
GPU - [ NVIDIA GeForce GT 530 ]
0 Kudos
Message 5 of 11
(3,912 Views)

When you create your subVI, just put an Error In control and Error Out indicator on the front panel and tie them to the connector panel.  In the subVI you wire from one to the other.  Or you can wire through any functions subVI's inside of it that also have error terminals.

0 Kudos
Message 6 of 11
(3,909 Views)

Is this the right way to do it. this is a simple Sub Vi (add and increment).

 

Abhilash S Nair

Research Assistant @ Photonic Devices and Systems lab

[ LabView professional Development System - Version 11.0 - 32-bit ]

LabView Gear:
1. NI PXI-7951R & NI 5761
2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021

OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
MEMORY - [ 16.0 GB RAM ]
GPU - [ NVIDIA GeForce GT 530 ]
0 Kudos
Message 7 of 11
(3,902 Views)

@abikutn wrote:

Is this the right way to do it. this is a simple Sub Vi (add and increment).


You don't need to wire the error across the while loop. Why is there even a while loop consuming all available CPU until the button is pressed? Since the terminals are outside the loop, the result can never change so you are just repeating the same calculation as fast as the computer allows!

 

Comments to your original code:

Why do you use local variables instead of wiring from the control directly? Don't be afraid to branch the wire. Since the last frame cannot be reached unless "scan complete=TRUE", the case structure makes no sense and can be deleted. Why is writing to a spreadsheet file inside a while loop? How many times do you possibly need to write the same thing as fast as the computer and HD allows? And yes, if you use proper dataflow, none of your sequences are needed

0 Kudos
Message 8 of 11
(3,894 Views)

 

Wow I dint realise that at all. I am still learning. And yeah the main challenge I am facing right now is to learn about PROPER DATAFLOW. I want to optimize my code as much as possible.

 

Using Sub Vi for modular programming and also like previous answers to this post, using ERROR HANDLING techniques. 

 

I am trying to learn these. Please direct me to any resource from where I can learn all these ideas.

Abhilash S Nair

Research Assistant @ Photonic Devices and Systems lab

[ LabView professional Development System - Version 11.0 - 32-bit ]

LabView Gear:
1. NI PXI-7951R & NI 5761
2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021

OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
MEMORY - [ 16.0 GB RAM ]
GPU - [ NVIDIA GeForce GT 530 ]
0 Kudos
Message 9 of 11
(3,890 Views)

www.ni.com/largeapps

 

Not necessarily a direct answer for your question, but for a long term a good source for information on software development using LV.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 10 of 11
(3,838 Views)