...
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.
...
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.
...
In this mode, the "Current Position", "Recalibrate", "Set # of Turns Open (Man)" controls and the "Motor Enabled" bool are all disabled and grayed out, but the "Min Open" and "Max Open" controls are enabled. The Min and Max Open values are set by the user, and represent the minimum position that the valve can close to and the maximum position it can open to while running. These values can be changed while the PID loop is active.
...
The Proportional-Integral-Derivative (PID) Response
The PID response operates by calculating an error from the designated target level and corrects that by using proportional, integral and derivative terms.
...
The above picture shows the code which creates the PID response.
In short, the PID loop takes the current level and the target level and compares them to determine what the new valve position should be. It also takes into account the min and max open positions, and converts them to steps. It uses these positions to edit the new position created by the PID loop to ensure its validity.
If you want to change the PID gains or are interested in the mathematics behind the PID response, visit my page (yep that is a shameless plug) on Creating the PID Response.
The image above (from top to bottom) shows how the current level is subtracted from the target level for each iteration, and this data is then used to produce the error graph, which plots the current error from the target level with respect to time.
...
- 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 filesMeasuring VI text file you have indicated, you may will need to run the Measuring VI with the respective new text file first.
Running the Response VI (with LHe)
Below are steps needed to run the Response VI with an actual level probe during a real run involving LHe.
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. This text file is created in the Response VI and referred to in the Measuring VIs. It also contains the enoch timestamp.
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. If you have not previously created a logfile, then you should create one by first running the VI in manual mode and changing the position a few times. This will give the logfile a start at which, if you want to immediately start testing in automatic mode, the Measuring VI can read the valve position and both VIs can 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.
- Prior to testing, make sure that...
- the LHe level probe is securely fastened in the LHe reservoir
- the motor is connected to the computer and the Response VI has direct communication with it (this can be determined by checking to see if the "Motor Enabled" and "Motor Connected" bools are activated).
- When testing with LHe, it is not necessary to log data as far as the valve position and the timestamp are concerned. This is up to personal preference, but is always a good idea to collect as much data as possible.
- The same thing applies as far as calibrating the default (zero) position in this situation... 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.
- Finally, once the Response VI is running, you should go check and see that the motor is actively running and that the valve is not slipping (the motor is in sync with the valve and they don't become out of sync during a sharp turn in the other direction - this can cause problems for your valve and may result in something breaking if you don't address the issue).
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. This text file is created in the Response VI and referred to in the Measuring VIs. It also contains the enoch timestamp.
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. If you have not previously created a logfile, then you should create one by first running the VI in manual mode and changing the position a few times. This will give the logfile a start at which, if you want to immediately start testing in automatic mode, the Measuring VI can read the valve position and both VIs can 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.
Possible Bugs and Issues
There are a few issues that could come up while using the VIs, especially the Response VI due to its complexity. Some are listed (with their possible solutions) below:
- if you are in automatic mode and switch to manual, you may not be able to change the value of the valve position the first time if it is the same value that the VI was trying to write to when automatic mode ended (ex: if auto wrote zero to the # of turns open but didn't quite get there, and you are trying to write zero under the #of turns open (man) but its not working, this is likely your issue). This happens because those control values are currently operating in a way where they only change when the value specified changes, not when the user presses enter. A temporary fix would be to just write a negative number to the valve position, as the code is designed to immediately convert any number less than zero to simply zero. A better method is currently in development, by changing the property of the controls so that they change anytime the user signals it (ie the enter key) instead of whenever the actual value is changed.
Other How-to Webpages
CONGRATS ON MAKING IT TO THE END!!! (or maybe you just scrolled down here)
...