-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIrrigationControl.CR1
More file actions
178 lines (164 loc) · 5.72 KB
/
IrrigationControl.CR1
File metadata and controls
178 lines (164 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
'CR1000
'Created by Short Cut (3.0)
'Declare Variables and Units
Public BattV
Public PTemp_C
Public T107_C
Public RTime(9)
Public IrrigCount
Public CoolingCount
Public WP(4)
Public StartTemp_C(4)
Public Temp1Sec_C(4)
Public Temp30Sec_C(4)
Public DeltaT_C(4)
Public LastGoodValue(4)
Public MeanWP
Const IrrigationDuration = 5
Const CoolingDuration = 20
Const TriggerWP = 2.5
Const CoolTrigger = 26.0
Const Alpha = 1
Const Beta = 0
Units BattV=Volts
Units PTemp_C=Deg C
Units T107_C=Deg C
Function MeasureWC()
'Do soil moisture measurements
'Do soil water potential measurements
'Measure reference temperature'
PanelTemp(PTemp_C,_60Hz)
'Measure Sensors starting temperature
'TCDiff (Dest, Reps, Range, DiffChan, TCType, TRef,RevDiff, SettlingTime, Integ, Mult, Offset)
TCDiff (StartTemp_C(1), 1, mV2_5C, 1, TypeT, PTemp_C,True, 0, _60Hz, 1, 0)
TCDiff (StartTemp_C(2), 1, mV2_5C, 2, TypeT, PTemp_C,True, 0, _60Hz, 1, 0)
TCDiff (StartTemp_C(3), 1, mV2_5C, 3, TypeT, PTemp_C,True, 0, _60Hz, 1, 0)
TCDiff (StartTemp_C(4), 1, mV2_5C, 4, TypeT, PTemp_C,True, 0, _60Hz, 1, 0)
'Switch heater on
PortSet(7,1)
'Pause for a second
Delay(0,1,Sec)
'Take 1 Second measurements
TCDiff (Temp1Sec_C(1), 1, mV2_5C, 1, TypeT, PTemp_C,True, 0, _60Hz, 1, 0)
TCDiff (Temp1Sec_C(2), 1, mV2_5C, 2, TypeT, PTemp_C,True, 0, _60Hz, 1, 0)
TCDiff (Temp1Sec_C(3), 1, mV2_5C, 3, TypeT, PTemp_C,True, 0, _60Hz, 1, 0)
TCDiff (Temp1Sec_C(4), 1, mV2_5C, 4, TypeT, PTemp_C,True, 0, _60Hz, 1, 0)
'Pause for a further 29 seconds
Delay(0,29,Sec)
'Take 30 Second measurements
TCDiff (Temp30Sec_C(1), 1, mV2_5C, 1, TypeT, PTemp_C,True, 0, _60Hz, 1, 0)
TCDiff (Temp30Sec_C(2), 1, mV2_5C, 2, TypeT, PTemp_C,True, 0, _60Hz, 1, 0)
TCDiff (Temp30Sec_C(3), 1, mV2_5C, 3, TypeT, PTemp_C,True, 0, _60Hz, 1, 0)
TCDiff (Temp30Sec_C(4), 1, mV2_5C, 4, TypeT, PTemp_C,True, 0, _60Hz, 1, 0)
'Turn header off
PortSet(7,0)
'Do calculations
DeltaT_C(1) = Temp30Sec_C(1) - Temp1Sec_C(1)
WP(1) = EXP(Alpha * DeltaT_C(1) + Beta)
DeltaT_C(2) = Temp30Sec_C(2) - Temp1Sec_C(2)
WP(2) = EXP(Alpha * DeltaT_C(2) + Beta)
DeltaT_C(3) = Temp30Sec_C(3) - Temp1Sec_C(3)
WP(3) = EXP(Alpha * DeltaT_C(3) + Beta)
DeltaT_C(4) = Temp30Sec_C(4) - Temp1Sec_C(4)
WP(4) = EXP(Alpha * DeltaT_C(4) + Beta)
'Calculate mean water potential
Dim I
For I = 1 To 4
If WP(I) = NAN Then
LastGoodValue(I) = LastGoodValue(I)
Else
If WP(I) > 2 AND WP(I) < 20 Then
'If the current measurement of WP is within sensible bounds use it for means. Otherwise keep last value
LastGoodValue(I) = WP(I)
EndIf
EndIf
Next I
MeanWP = (LastGoodValue(1)+LastGoodValue(2)+LastGoodValue(3)+LastGoodValue(4))/4
'If for some reason MeanWP becomes NAN, set mean WP to a value high enough to trigger irrigation
If MeanWP = NAN Then
MeanWP = TriggerWP + 1
EndIf
EndFunction
Function DoIrrigation(IrrigDurat)
PortSet(1,1)
Delay(0,IrrigDurat*1.1,min)
PortSet(1,0)
Delay(0,5,Sec)
PortSet(2,1)
Delay(0,IrrigDurat*0.9,min)
PortSet(2,0)
IrrigCount +=1
EndFunction
Function DoCooling(CoolDurat)
PortSet(1,1)
Delay(0,CoolDurat*1.0,sec)
PortSet(1,0)
Delay(0,5,Sec)
PortSet(2,1)
Delay(0,CoolDurat*0.8,sec)
PortSet(2,0)
CoolingCount +=1
EndFunction
'Define Data Tables
DataTable(PotTables,True,-1)
DataInterval(0,20,min,10)
Average(1,BattV,FP2,False)
Average(1,PTemp_C,FP2,False)
Sample(1,T107_C,FP2)
Average(1,WP(1),FP2,False)
Average(1,WP(2),FP2,False)
Average(1,WP(3),FP2,False)
Average(1,WP(4),FP2,False)
Average(1,MeanWP,FP2,False)
Average(1,DeltaT_C(1),FP2,False)
Average(1,DeltaT_C(2),FP2,False)
Average(1,DeltaT_C(3),FP2,False)
Average(1,DeltaT_C(4),FP2,False)
Average(1,LastGoodValue(1),FP2,False)
Average(1,LastGoodValue(2),FP2,False)
Average(1,LastGoodValue(3),FP2,False)
Average(1,LastGoodValue(4),FP2,False)
EndTable
'Main Program
BeginProg
'Main Scan
Scan(10,min,1,0)
'Default Datalogger Battery Voltage measurement 'BattV'
Battery(BattV)
'Default Wiring Panel Temperature measurement 'PTemp_C'
PanelTemp(PTemp_C,_60Hz)
'109 Temperature Probe measurement 'T109_C'
'Measure thermoster temperature Therm109 (Dest, Reps, SEChan, VX/ExChan, SettlingTime, Integ, Mult, Offset)
Therm107(T107_C,1,16,3,0,_60Hz,1,0)
'Do soil moisture measurements
MeasureWC()
'Call Data Tables and Store Data
CallTable(PotTables)
Delay(0,150,mSec) 'Delay(Option, Delay, Units)
'Update time variable
RealTime(RTime(1)) '1=year, 2=month, 3=day of month, 4=hour of day, 5=minutes, 6=seconds, 7=microseconds, 8=day of week, 9=day of year
'If the time is right consider applying irrigation
If (RTime(4) >= 4 AND RTime(4) < 7) Then
'If pots are dry give them a squirt of irrigation
While MeanWP > TriggerWP
DoIrrigation(IrrigationDuration) 'Put water om
Delay(0,1,min) ' Wait a minuits for it to settel
MeasureWC() ' Remeaasure water and repeat if pots still dry
CallTable(PotTables)
Wend
EndIf
Delay(0,150,mSec) 'Delay(Option, Delay, Units)
'If the time is right consider cooling the tables
If (RTime(4) >= 10 AND RTime(4) < 18) Then
'If the temperature is sufficiently high give a short squirt of water to cool things down
If T107_C > CoolTrigger Then
DoCooling(CoolingDuration)
EndIf
EndIf
'Zero the counts at the end of each day
If RTime(4) = 0 Then
IrrigCount = 0
CoolingCount = 0
EndIf
NextScan
EndProg