...
Once the text file has been created and written, and the VI is done running, the text file is closed outside of the loop. It is possible to open the text file while it is still running, but it will only contain the data up to the time you opened it, and will not keep updating while open.
Response VI:
Interface
This is an example of what the Response VI Interface will look like when first opened.
...
Lastly, in the bottom left hand corner of the VI is the option to enable advanced controls for the PID loop. If this icon is selected, the PID gains table will appear to its right. The pid loop uses a PID controller and equation constants to run and maintain the level. Unless you have a deep understanding of these coeffecients and need to make edits to them to increase the VI's efficiency, do not try to change these values. If advanced controls are enabled, and the VI is in manual mode, the option is given to recalibrate the current position of the valve. If it is in automatic mode, then the option to change the equation constants is enabled as well. At the bottom there is the developer table which contains the stop bool, which basically does the same thing as deselecting the "Run VI" bool (turning off the program).
Code
The entirety of the Response VI code is contained within a while loop, in which each iteration lasts 1 second and which can only be stopped by either an error in either VI (while they are running simultaneously) or if the VI is stopped with the use of the stop bool in the developer box.
File IO
The File IO in the Response VI appears very similar to that of the Measuring VI. It begins with opening the desired text file containing the Measuring VI data, which is defined by the user, and uses the last 3 characters for that iteration while the VI is running. The last three characters represent the level of the system. This information is then converted from a string to a numeric, and the text file is closed. The level data is then outputted into a graph which represents the level with respect to time.
There are also two OK buttons to "Save PID gains" and "Load PID gains". Selecting the former of the two will prompt you to create a file that will house the current PID gains in the controls box, while the latter will prompt you to select a file to load PID gains from (i.e. the file that you had created earlier). This allows you to store PID gains that you know work well, in case you wanted to experiment with the coefficients.
At the bottom there is the developer table which contains the stop bool, which basically does the same thing as deselecting the "Run VI" bool (turning off the program).
Code
The entirety of the Response VI code is contained within a while loop, in which each iteration lasts 1 second and which can only be stopped by either an error in either VI (while they are running simultaneously) or if the VI is stopped with the use of the stop bool in the developer box.
File IO
The File IO in the Response VI appears very similar to that of the Measuring VI. It begins with opening the desired text file containing the Measuring VI data, which is defined by the user, and uses the last 3 characters for that iteration while the VI is running. The last three characters represent the level of the system. This information is then converted from a string to a numeric, and the text file is closed. The level data is then outputted into a graph which represents the level with respect to time.
On the right side of the above image, there is a case structure that is activated when the user selects the bool "Log Data?". Selecting this icon in the VI interface sets the case as true, which activates the assembly of a text file which contains data for the On the right side of the above image, there is a case structure that is activated when the user selects the bool "Log Data?". Selecting this icon in the VI interface sets the case as true, which activates the assembly of a text file which contains data for the Date/Time Stamp in unix, the current level and finally the valve position, which will be read into the Measuring VI (see LINK). All this data is taken into a string concatenator and written into the text file path supplied by the user. Then the text file is closed in the case structure. If the case was set to false, then no text file would have been written or even opened.
...
Case 3 is activated when the "Motor Enabled" bool is selected. If it is selected,nothing within the VI is changed, but because the motor is reading the position output from the VI the physical position of the motor changes with it.
Automatic Mode
In automatic mode, the VI reads the level and, from it, produces a new valve position to bring the level closer to the target level. In this mode, the PID loop is active and continuously reading the level and assigning a new valve position.
...
Case (1), shown above, contains a case structure that is wired to the bool, "Enable Advanced Controls". If the bool is True, then a message first appears to the user warning them about changing the default values of the PID Controls. The values should not be changed if the user does not have an understanding of the PID coefficients.
...
Connecting the
...
Motor
In order to connect your computer to the motor...
...
- make sure that the "Motor Enabled" bool is activated, and that the correct COMPort is selected.
- connect your USB Port to a Serial Port. This conversion is necessary in order to make your computer's code readable to the step driver.
- the step motor driver should be connected to a) a Power Box, b) the other end of that aforementioned Serial Port and c) a wire that eventually connects to the motor itself. Information on where to insert what should be evident on the box itself.
- make sure that the wire leading to the step motor driver is actually connected to the motor (I have forgotten to do this many times, please check!!!).
Running the VIs
Below are a few steps to running the VI...
- Ensure that all controls in both VIs are accounted for. In the Response VI this includes...
- text file paths are indicated, preferably in the computer's hard drive
- min and max valve position
- target level
- the COMPort is correctly configured
...and in the Measuring VI...
- the text filepath is indicated in the same folder as the response file on the computer's hard drive
- the standard deviation, which shouldn't be any greater than 1 - Follow the steps in "Connecting the Motor" (above) and set up the connection between the valve motor and the computer.
- In the response VI:
- the Run VI icon at the top left should be green
- the "Motor Connected" bool icon will be red when the VI is not running, but if it does not turn green after about a second of the VI running then the motor is not connected
- if you want the VI to automatically change the valve position for a trial, then you should select automatic. This should be done after the connection between the VI and the motor are tested (see Step 3).
- the Log Data icon should be green
- the Motor Enabled icon should be green, but grayed out
- When you initialize the valve position, it is important that the valve be completely closed, and that zero is set as the initial position. If this is not done successfully then there is a risk of the valve overturning and breaking. Likewise, the constant velocity should not be too fast in order to prevent the valve from slipping while the program is running.
- Before running the VIs, you should do a test of the Response VI to make sure everything is working properly. This is done by enabling manual mode and changing the set number of turns open icon to any number between 0 and 3. make sure the "Log Data?" bool is selected, as this will create logfile.txt, the text file needed to run a trail in automatic mode. Once it is determined that this does in fact change the run valve position connected to the motor, then the VI is connected correctly. Once you are done testing, and logfile.txt has been created, automatic mode should be reselected in order to run a trial.
When the above steps are completed, and the Response VI test has run in manual mode successfully, the two VIs are ready to be run simultaneously. Simply click the run button of both VIs. If this is the first time using one of the text files, you may need to run the VI with the respective new text file first.
Retrieving Data from Text Files
Readable data is retrieved from the VI in a format of a text file, for the purpose of converting the collected data into a format that is easily understood by the user.
There are two main text files that would be constantly in use during a test. This includes the Response VI text file, logfile.txt, and the Measuring VI text file, which should be changed with each test, preferably to the date or time the test took place.
Text files were used as a means of providing constant communication between the two VIs while running, as both can be changed and saved during each iteration, so that the data from the last iteration is extracted. This is the case for both text files.
I recommend putting all your text files in a folder on the same drive as your LabVIEW codes (as shown above).
Response VI Text File, logfile.txt
logfile.txt is the name of the data file produced by the Response VI, and namely contains the new valve position and the last recorded level in the tank. It also includes the enoch timestamp.
This text file is created in the Response VI and referred to in the Measuring VIs.
Only one logfile will ever be created once you have run the two programs successfully, as the new data is appended to the old data during each run.
Measuring VI text file
The measuring VI text file contains the date and timestamp, iteration number, new flow rate based on the valve position, the valve position recorded from the Response VI, and the new level created by the Measuring VI.
If you want to save the data from your trials, you should change the name of this text file every time before you begin running.
...
When the above steps are completed, and the Response VI test has run successfully, the two VIs are ready to be run. Simply run click the run button of both VIs. If this is the first time using one of the text files, you may need to run the VI with the respective new text file first.
Retrieving Data from the VIs
Data is retrieved by the motor from the VIs, which allows it to open and close the valve to whichever degree is desired.
Data is also retrieved from the VI in a format of a text file, for the purpose of converting the collected data into a format that is easily understood by the user.
Motor Connection
In order to connect your computer to the motor...
...
Text Files
There are two main text files that would be constantly in use during a test. This includes the Response VI text file, logfile.txt, and the Measuring VI text file, which should be changed with each test, preferably to the date or time the test took place.
Text files were used as a means of providing constant communication between the two VIs while running, as both can be changed and saved during each iteration, so that the data from the last iteration is extracted. This is the case for both text files.
I recommend putting all your text files in a folder on the same drive as your LabVIEW codes (as shown above).
Response VI Text File, logfile.txt
logfile.txt is the name of the data file produced by the Response VI, and namely contains the new valve position and the last recorded level in the tank. It also includes the enoch timestamp.
This text file is created in the Response VI and referred to in the Measuring VIs.
Only one logfile will ever be created once you have run the two programs successfully, as the new data is appended to the old data during each run.
Measuring VI text file
The measuring VI text file contains the date and timestamp, iteration number, new flow rate based on the valve position, the valve position recorded from the Response VI, and the new level created by the Measuring VI.
If you want to save the data from your trials, you should change the name of this text file every time before you begin running.
Development Text Files
If either the Measuring VI or the Response VI do not already have a text file with data recorded saved on your computer, you will initially need to run with a development text file. This text file simply contains any number between 0 and 100 that will serve as the temporary Measuring VI text file containing the "level". With this as a replacement for the text file containing the new level data, you can run the two VIs and create a brand new logfile.txt. The next time you run the two VIs you can use logfile.txt with a new Measuring VI text file named after whatever your little heart desires.
CONGRATS ON MAKING IT TO THE END!!! (or maybe you just scrolled down here)
...