LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Advice on code structure please

Hi,

 

I am a newbie to labview but not to programming.

 

Here is what I want to do:  Simulate an object moving on a conveyer that has optical sensors, and then develop my program that does some measurements based on when the sensors change.

 

In my main VI I have a while loop that executes every 10th ms.  It calls a sub VI that updates the conveyer position and the state of the sensors.  All works well.  Now I want to work on my application which in the real world could sit and wait on the state of the optical sensors.  Of course, if I wait on anything while including my simulated conveyer then my conveyer does not get updated!  So, I need to effectively execute my conveyer update and control code in parallel.  I want to avoid doing any server/client type thing to keep it simple for learning.  Is the best way to handle it to use a state machine in my main while loop to keep checking the optical sensors then change state when required?  That way it does not have to wait/block on anything.

 

Any advice appreciated.

 

Thanks

 

Ashley

 

0 Kudos
Message 1 of 4
(3,058 Views)

Hi Ashley,

 

The thing you're trying to do is called "Hardware-in-the-Loop" simulation. 

 

http://www.ni.com/white-paper/4566/en/

 

U can use "queued state architecture" or "producer/consumer loop" to effectively deploy this system. Here you will have to use two loops. One for User-Interface and other for Processing/Data Acquisition. 

 

 


0 Kudos
Message 2 of 4
(3,039 Views)

Ashley,

 

     I recommend that you take a look at the two Producer/Consumer Design Pattern Templates/Demos, as they will give you some ideas on how to use two parallel loops, one (the Producer) that gets data "on demand" (either timed or because the User interacted with the Front Panel) and the other (the Consumer) that "does something with the data".  The reason to have two loops is that both will have times they are idle, but you don't want to "block" the activity of the other.  The Producer is idle while waiting for a Clock Tick (if you are, say, sampling every 10 msec) or for someone to click on a Front Panel control, while the Consumer is idle if there are no data to process (because the Producer hasn't sent it any).

 

     I'm assuming you are running a "relatively recent" (say, 20xx) version of LabVIEW.  Open LabVIEW, got to the File menu, choose "New ..." (the dots are important!), and expand VI/From Templates/Framework/Design Patterns (or something similar), where you should find the two Templates I mentioned.  Select one, let it build the code, then study the code and documentation.

 

Bob Schor

0 Kudos
Message 3 of 4
(3,003 Views)

Thanks for the pointers guys.  I will go have a look and see what I can find.

 

Cheers

 

Ashley

 

0 Kudos
Message 4 of 4
(2,967 Views)