To download NI software, including the products shown below, visit ni.com/downloads.
Overview
Have you ever started an application thinking it MUST be really easy to implement (what you're trying to do isn't that hard after all!), then realized halfway through development that what you're trying to do is deceptively complex? I was recently working with a customer who had just this problem. He was trying to cycle through several states for many columns of water (e.g. filling, draining...). He needed to leave the columns in certain states for variable periods of time, and have a manual override. Doesn't sound that complicated, right?
Let’s say you’re working on a system that needs to be sent through states in an order that could change dynamically, and could be changed by interaction from the user. Perhaps the transition needs to happen after a certain time. Or perhaps you need to control multiple objects that are going through different states? It might be tempting to use a state machine, but you’ll quickly find that things will get out of hand. An ordinary state machine can usually only control one object or system, and checking timing and handling events at the same time could prove difficult.
This template I’ve put together can handle multiple objects transitioning through different states, dictated by timing and has a manual override from the user interface built in.
Description
This code is an expansion on the state machine idea. The main VI has 3 loops in it, with communication between them being key to the application.
The state change cluster type-def holds four pieces of information: the current state, the next state and the time to make the transition as well as the column number. An array of this cluster needs to be passed through all three loops in the application.
When a button is pressed, the top loop’s event structure detects it and changes the next state and the time to make the switch in the right array element, which is passed to the middle loop. This continually goes around checking each element in the array to see if any of the times for a change to happen have passed. If a change needs to happen, the next state and the column number are extracted and sent into a queue to the bottom loop which is where the state change happens, and the conditions for the next expected state change are put back into the Functional Global Variable (FGV).
A second FGV looks after the front panel indicators, which need to be updated from both the middle and bottom loops.
This application is written to work with an application that fills and empties columns of water, and the names of the states and front panel objects reflect this, but this template can be adapted to work with other complex systems
Requirement
Steps to Run
Additional Information or References
Block Diagram
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.