project3 team4 - CourseReps/ECEN489-Fall2015 GitHub Wiki
#Project 3 - Team 4 ##Members:
- Udaya Bhaskar Kothapalli
- Abhay Anand
- Seungwon Yoon
- Cooper Rehn
##Block Diagram
##PCB
This board used the schematic and layout of Team 5 Project 2 as a starting point, since it worked as expected after fabrication. There were only a few minor changes made to adjust to the new project requirements and also acting on some lessons learned from Project 2.
The first noticeable difference is the size of the board. Much more effort was put into compressing the layout of the board by optimizing the use of space. Since the screw terminal is so long, that dominated the length of the board, but it doesn't extend beyond it and the width was kept at a minimum by using as much of the surface for components as possible. The solenoid was replaced by the second pump for the PID, and the second flow sensor replaced by the second IR sensor. Also, the RGB LED was changed from a PWM LED to an I2C LED, removing three resistors from the design, also creating space on the board. The soloenoid and low water LEDs were removed as they serve no purpose in this design, and a new LED was put on the +5V line to show that the regulator is functioning properly.
The biggest functional change came in three new switches, one toggle switch for each pump to be able to turn them off without removing the power from the board to keep the Teensy running and connected over bluetooth for debugging, and also a normally-closed push-button on the +5V input to the Teensy to be able to give the Teensy a hard reset without unplugging the whole board. These changes take what was learned from the first board to optimize space and functionality, and add ease to debugging without constantly unplugging the circuit. There are top and bottom ground pours not shown in this picture to better see the traces. The top pour can be seen in the 3D rendering of the board.
The four teams presented their PCBs to propose one to be fabricated for the rigs for the class, and this board won the vote. One small change was made before fabrication when it was pointed out that the flow rate sensor should run off of 5 V instead of 12. After the boards were fabricated, there was an issue with getting the push buttons and switches that the PCB was designed for since the EIC did not carry the switches, and the push buttons were actually normally-open instead of normally-closed. These were replaced with female headers and jumper wires, providing the same functionality for the short-term use that it needed. When placed on the full rigs, both boards functioned completely as intended with no hitch.
##Reservoir Rigs It was decided that the four groups would work together to make two of the project rigs so that we could have two teams on a rig at a time. After discussion with the other teams and Dr. Huff, a simple design using a plastic tub with two large cups on the lid was decided on. Two holes were cut into the lid of each tub to hold the two cups, and two holes for the plastic hose going to the pumps were drilled near the bottom on each of the long sides. On the cups, a hole was drilled on the bottom for a drain nozzle, and another hole on the side near the bottom was drilled for the tube connecting the two reservoirs. The hose connecting the reservoirs was attached to each nozzle, and then the nozzles, the cups, and the hoses on the tub were all fitted with Gorilla Glue and allowed to set overnight. A rectangular piece of hard foam was cut to bridge the two cups, and two small holes were cut at each end to hold the IR sensors for each reservoir. It also provides a place to set the controller board. The pumps were fitted with long wires to reach the PCB on top of the rig and then attached to the tubes at the bottom of the tub. A flow sensor was attached to one of the pumps, and then a longer tube was run from each pump to their respective cups. Two small holes were cut at the top of each cup, and the hose was fed close to the bottom, and then zip-tied to the top of the cup through those holes. After all of the glue had set and everything had been hooked up correctly, water was added to the rig to check for water-tightness. zip-ties were added to any tube fittings the were leaking, and after that everything held up, and we began testing each rig to make sure its hardware was functioning correctly. Small foam discs were put into the cups to help the IR sensors detect the level of the water, and one faulty flow sensor was replaced, and then both rigs were up and running.
In this sub-section, a mathematical modelling of a single tank, as shown above, will be explained.
The user may input a desired setpoint for the water level in the tank (measured from the bottom). The pump output is controlled by a PID controller which takes in the current IR sensor height as the input, and controls the pump PWM to reach the desired setpoint. This is the scenario that is being modeled here.
Let us assume that the input flow rate (Qi) is linearly proportional to the pump PWM value and that the maximum flow rate supported by the in-flow tube is 5 liters/min. The output flow rate (Qo) can be calculated using the formula:
Qo = Cd * A * sqrt(2*g*H)
Cd = Discharge coefficient
A = Cross-sectional area of tube
g = Acceleration due to gravity
H = current height of water
Theoretically for a cylindrical valve the Cd = 0.61. Once both these values are known, summation of the difference between Qi and Qo multiplied by the sample time will give the volume of water in the tank.
The PID equation can be modeled as shown below:
output = (Kp * error) + summation(ST*Ki*error) - (Kd * (input-prevInput) / ST)
Kp = Proportional constant
Ki = Integral constant
Kd = Differential constant
error = setpoint - input
ST = Sample time
prevInput = Input of previous sample
This output is the variable that controls the pump and hence the Qi.
####Pseudo-code:
Algo-1: Based on Height measured from IR readings. In this approach the IR readings are stored once the level is greater than a threshold value. To find the time taken to discharge a time measurement between the rise in water level and drop in water level to the steady state.
WHILE (IRreading > threshold) // Looping till the IR reading is greater than the threshold
Initialize count[], IRreading[] and FlowRates[] arrays; // Initializing the IR readings and flow rate arrays along with corresponding sample time count.
ENDWHILE
TIME = count(MaxIRreading) - count(SetpointHeight); // Finding the number of sample times taken for the rise in height to drop from the max value to steady state value
LoopOver TIME { // For each sample time count
Netflow = Difference FlowRates[]; // Finding the net flow rates from the stored value in flowrate array.
Volume = Volume + Netflow; // Volume is updated for each sample time.
}
Algo-2: Based on cycle time measurement. Here in this approach the time taken for the water level to rise and drop from the steady state is measured.
WHILE (IRreading > threshold) // Looping till the IR reading is greater than the threshold
Compute Qnet; // Computing the Net flow rate
Volume = Volume + Qnet*SampleTime; // Computing the volume per sample time ST
ENDWHILE
##Scenario 2: Two Tank Model
In this sub-section, a mathematical modelling of two tanks system, as shown, will be explained.
The user may input a desired setpoints for the water levels in both the tanks (measured from the bottom). The pumps output is controlled by PID controllers which takes in the current IR sensors heights as the input, and controls the pump PWM to reach the desired setpoints. This is the scenario that is being modeled here.
Let the setpoints be at H1 and H2. Let us assume that the input flow rates are Qin1 and Qin2 are linearly proportional to the pump PWM value and that the maximum flow rate supported by the in-flow tube is 5 liters/min. The output flow rate Qo1 and Qo2 can be calculated using the formula:
Qo1 = Cd * A1 * sqrt(2*g*h1) & Qo2 = Cd * A2 * sqrt(2*g*h2)
Cd = Discharge coefficient
A1 & A2 = Cross-sectional areas of each tank
g = Acceleration due to gravity
h1 & h2 = current heights of water levels
For the interconnecting tube between tanks. Let us assume that the heights are unequal. The flow rate Q12 can be calculated using the formula:
Q12 = Cd12 * A12 * sqrt(2*g*(h1-h2))
Cd12 = Discharge coefficient of the interconnecting tube
A12 = Cross-sectional area of the tube
g = Acceleration due to gravity
h1 & h2 = current heights of water levels. Assuming h1 > h2.
The rate of change in Volume for both the tanks is given by the below equations (1) and (2).
dV1/dt = (Qi1 - Qo1 +/- Q12) - (1)
dV2/dt = (Qi2 - Qo2 -/+ Q12) - (2)
The volume for every sample time will be the integral from 0 to SampleTime of the Qnet. From this volume measured we can find the updated heights h1 and h2 for each sample time. The process continues until the heights h1 and h2 equals the setpoint heights H1 and H2.
Pseudo-Code:
Declare setpointHeights
While(h1<=H1 & h2<=H2) // till current heights equal to Setpoint Heights.
dv1 = Qnet1 * ST // Calculating net change in volume for a sampletime ST in tank1
dv2 = Qnet2 * ST // Calculating net change in volume for a sampletime ST in tank2
Volume1 = Volume1 + dv1 // Calculating current volume in tank1
Volume2 = Volume2 + dv2 // Calculating current volume in tank2
h1 = Volume1 / (A1) // Calculating current height. A1 is area of tank1
h2 = Volume2 / (A2) // Calculating current height. A2 is area of tank2
ENDWHILE
Experimental model
Calibrations
The IR sensor was calibrated in the test-rig environment to avoid any discrepancies in the IR readings. A circular plate was dropped into the water to have a reflective surface for the sensor but this has caused erroneous values for the same height when measured at different instances. This was because of the tilt in the plate that was caused due to the water pumped in from the top, so the tube was adjusted to pump water at lower heights such that it doesn't tilt the plate. Also a filter was employed to reduce the fluctuations in the IR sensor readings.
Filtered = ((Input - PrevFiltered) * Alpha) + PrevFiltered // Pseudo code for the filter. alpha = 0.0042
A voltage to distance measurement equation was found.
// IR reading in Voltage to Height in cm.
Height = .0293*pow(IRreading,5) - 0.5663*pow(IRreading,4) + 4.4136*pow(IRreading,3) - 17.7419*pow(IRreading,2) + 38.7313*IRreading - 28.8534;
For calibrating the flow sensor the water flow was measured for every 250m.sec. The flow rate measurement was done in a similar way performed in earlier projects. The inflow is obtained by measuring the flow sensor reading.
The PID gain coefficients was calibrated again because of the PID used in the earlier projects was calibrated for a different rig dimensions. The three gain values were tuned using Ziegler–Nichols method and the updated gain values are:
-
Kp = 20
-
Ki = 4
-
Kd = 2
The outflow rate of the tank at a steady setpoint height is nothing but the inflow rate measured by the flow sensor. So to calibrate the outflow of the rig at different water levels, the PID was set to different setpoint ranging from 2cms to 12cms of height from the bottom of the tank. At the steady state for each setpoint height, the inflow rate was measured. A relationship between the setpoint height and the outflow rate was obtained by the following equation.
// Height is in cm.
OutFlowRate = -.00215*pow(Height,4)+0.0699*pow(Height,3)-0.8287*pow(Height,2)+4.4372*Height-5.2091;
Qt interface
Similar to the project-2 Qt interface, the Qt interface running on the NUC receives the data from the Teensy using the bluetooth serial communication. In the Qt interface, two sliders are provided with one of them controlling the setpoint height and the other displaying the current water level in the tank. Two graphs for Inflow rate and outflow rate are plotted against the timestamp. Two buttons are provided for starting and stopping the bluetooth communication.
The screenshot of the QT interface displayed above is the case where the object volume dropped is 200ml and the measured volume is 189.81ml.
###Scenario 1: Object Volume Measurement with Single Tank Model
The object is dropped when the water level is at a steady state setpoint. When the level of the water changes by about 0.3cm the volume calculation is triggered. From this triggering point till the water level drops back to the setpoint level a difference between the outflow and inflow rates is measured for this time interval.
A state machine representation of the algorithm is displayed in the image below.
pseudo code
IF (waterLevel - setpointLevel >= 0.3) // Object Detected Volume measurement starts
WHILE (Object detected)
Volume = Outflow rate - Inflow rate. // This is measured for every 250msec
END WHILE
END IF
The following table shows the experimental results obtained.
Setpoint Water Level | Actual Volume | Calculated Volume | Error |
---|---|---|---|
5cm | 150 ml | 156 ml | 4% |
5cm | 200 ml | 204 ml | 2% |
5cm | 200 ml | 190 ml | 5% |
5cm | 250 ml | 263 ml | 5.2% |
###Scenario 2: Balancing the heights in two tank model
For the project presentation, due to the time limitation and hardware issues, we could not complete the second part of the project. In this case the Coupled tank flow rate can be measured by the difference of the inflow rate and outflow rate at a given setpoint due to each tank. An expression relating height and coupled flowrate can be calculated for each tank.
Coupled flow rate 1 = Inflow rate 1 - Outflow rate 1 -> @ a particular height
Coupled flow rate 2 = Inflow rate 2 - Outflow rate 2 -> @ a particular height
Net flow rate = Coupled flow rate 1 - Coupled flow rate 1 -> from tank 1 to tank 2
But the direction of flow depends on the height of water in both the tanks.
Demo Video Link of Scenario-1
##Reference