LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Structuring large application with multiple parallel loops

Hi all,

 

I'm working on a - for my experience - large piece of LabVIEW software. I'm relatively familiar with programming, however not so much with LabVIEW and parallel processing. I would like to ask some help and input on structuring a large VI with multiple parallel loops and data communication.

The idea is that my application, using machine-vision and temperature, can be integrated and communicate with a commercial piece of hardware. Samples are introduced by this external system.

 

I have attached an example VI with several loops to illustrate as I imagened the structure, but I'll elaborate on it here.


The backbone of my application is a PRODUCER/CONSUMER structure with a EVENT-CONTROLLED STATE MACHINE embedded in the consumer-loop (the "MAIN"-loop). The producer continuously grabs images from a camera (15 fps). The consumer, depending on the state, will either do image processing or directly outputs the images to the screen.

The CONSUMER can be in 3 consecutive states: IDLE > INITIALISE > MEASURE (> back to IDLE). Switching states is triggered with TTL signals from and to the external hardware.

How this works:
- MAIN loop is in IDLE
- TTL signal received: go to INITIALISE
- Initialisation done: Send TTL signal back, continue to MEASURE-state
- TTL signal received: go to IDLE state, wait for new signal

 

In the INITIALISE state, sample metadata is read from a TXT-file generated by external software.
To receive the TTL input, I thought of a loop polling the input channel (set boolean) combined with an OnValueChange in the event-structure of the state machine.

 

So far so good.

 

Additionally there are two extra loops: one PID loop keeping two heaters at constant temperature, and another one for data monitoring/logging. The PID-loop is set to 5 Hz, which is sufficient for this process, data logging happens at 2 Hz.

And here comes the tricky part: upon initialisation of a sample in the MAIN loop, the metadata contains the setpoint temperatures for the two heaters. This setpoint has to be passed on to the heater controls, but the MAIN loop cannot proceed to the next state ("measure") until the desired temperature is reached.

Furthermore, after a sample is done (MAIN loop back to IDLE), the heaters should stay at their last known setpoint until a new sample is introduced, but with a maximum of 5 minutes. After 5 minutes, the heaters should turn off for safety.

 

The case is similar for DATA LOGGING: the metadata of the sample contains the sample ID/name, which needs to be in the filename of the log-file. Data is only logged during the "Measure"-state.
Since this loop only reads data, I'm not worried about race conditions here using local variables.

 

My idea first idea for the communication to the heater and data logging was to use notifiers, to notify when a new sample enters and to send it back - this is also in the attached VI. This allows the loops to run at their own frequencies and still communicate. But because of the need for "resetting" the loops, I was also thinking about a continuous state machine like the MAIN-loop has.
Or maybe even a combination of notifiers and state machines?

 

Input on how to structure this is highly appreciated. Thanks!

0 Kudos
Message 1 of 3
(3,206 Views)

You should look into the Queued Message Handler.

If you dig into this, i think you can answer most questions on you own.

 

Please note that the queued message handler is nowadays part of the LV project template browser (Create Project).

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

Thanks for the tip, Norbert.

I have read the QMH article several times, examined the project template and looked at some other examples. Probably I still don't fully understand it, but I don't see the structure how this would integrate communication between loops at different frequencies (or how it would make this superfluous), and mostly how it would work with/replace the current image producer/consumer and state machine in the consumer.

 

Can you maybe elaborate on that?

 

I also looked into replacing my current state machine, for example with the more elaborate JKI state machine, but I think my current one is pretty solid for my application.

0 Kudos
Message 3 of 3
(3,111 Views)