forked from allpowerlabs/KS_PowerPallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Auger.pde
273 lines (264 loc) · 8.55 KB
/
Auger.pde
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
void DoAuger() {
checkAuger();
switch (auger_state) {
case AUGER_OFF:
if (FuelDemand == SWITCH_ON) { //&& P_reactorLevel > OFF) {
if (relay_board == 1){
TransitionAuger(AUGER_STARTING);
}
else {
TransitionAuger(AUGER_FORWARD);
}
}
if (P_reactorLevel == OFF) {
auger_state_entered = millis(); //reset to zero if no vacuum and auger off
}
if (millis() - auger_state_entered > shutdown[ALARM_AUGER_OFF_LONG] && engine_state == ENGINE_ON){
Log_p("Auger off too long, Engine Shutdown at: ");
Logln((millis() - auger_state_entered));
TransitionEngine(ENGINE_SHUTDOWN);
TransitionAuger(AUGER_ALARM);
}
if (relay_board == 1 && ((millis() - auger_state_entered) % 60000 > 59000)) { //pulse every minute of auger off...only on relay board enabled units
Logln_p("Pulsing Auger");
TransitionAuger(AUGER_PULSE);
}
break;
case AUGER_CURRENT_LOW:
if (FuelDemand == SWITCH_OFF) {
TransitionAuger(AUGER_OFF);
}
if (AugerCurrentLevel != CURRENT_LOW && AugerCurrentLevel != CURRENT_OFF && millis() - auger_state_entered > 500){ //switch forward instead?
TransitionAuger(AUGER_FORWARD);
}
if ((millis() - auger_state_entered) > shutdown[ALARM_AUGER_LOW_CURRENT]){ //turn engine and auger off if auger current low for 3 minutes
TransitionAuger(AUGER_ALARM);
if (engine_state == ENGINE_ON){
Log_p("Low Auger Current for too long, Engine Shutdown at");
Logln((millis() - auger_state_entered));
TransitionEngine(ENGINE_SHUTDOWN);
}
}
break;
case AUGER_STARTING: //disregard all current readings while starting, pulse in reverse for a moment
if (millis() - auger_state_entered > 500){
TransitionAuger(AUGER_FORWARD);
}
break;
case AUGER_FORWARD:
if (FuelDemand == SWITCH_OFF) {
TransitionAuger(AUGER_OFF);
}
if (relay_board == 1) {
if (AugerCurrentLevel == CURRENT_HIGH && millis() - auger_state_entered > 500){
TransitionAuger(AUGER_HIGH);
}
if (AugerCurrentLevel == CURRENT_LOW or AugerCurrentLevel == CURRENT_OFF && millis() - auger_state_entered > 500){
TransitionAuger(AUGER_CURRENT_LOW);
}
}
if ((millis() - auger_state_entered) > shutdown[ALARM_AUGER_ON_LONG]){ //turn engine and auger off if auger runs non-stop for too long, use auger_direction_entered???
TransitionAuger(AUGER_ALARM);
if (engine_state == ENGINE_ON){
Log_p("Auger on too long, Engine Shutdown at:");
Logln((millis() - auger_state_entered));
TransitionEngine(ENGINE_SHUTDOWN);
}
}
break;
case AUGER_HIGH:
if (FuelDemand == SWITCH_OFF) {
TransitionAuger(AUGER_OFF);
}
if (AugerCurrentLevel != CURRENT_HIGH){
TransitionAuger(AUGER_FORWARD);
}
if (millis() - auger_state_entered > 500){
TransitionAuger(AUGER_REVERSE);
}
break;
case AUGER_REVERSE:
if (FuelDemand == SWITCH_OFF) {
TransitionAuger(AUGER_OFF);
}
if (millis() - auger_state_entered > 500 && AugerCurrentLevel == CURRENT_HIGH){
TransitionAuger(AUGER_REVERSE_HIGH);
}
if (millis() - auger_direction_entered > aug_rev_time){
TransitionAuger(AUGER_FORWARD);
}
if (auger_rev_count > shutdown[ALARM_BOUND_AUGER]){ //catch oscillating auger from broken Fuel Switch
Logln_p("Auger Bound or broken Fuel Switch, stopping Auger");
TransitionAuger(AUGER_ALARM);
if (engine_state == ENGINE_ON){
Log_p("Auger Oscillations, Engine Shutdown at: ");
Logln((millis() - auger_state_entered));
TransitionEngine(ENGINE_SHUTDOWN);
}
}
break;
case AUGER_REVERSE_HIGH:
if (FuelDemand == SWITCH_OFF) {
TransitionAuger(AUGER_OFF);
}
if (AugerCurrentLevel != CURRENT_HIGH){
TransitionAuger(AUGER_REVERSE);
}
if (millis() - auger_state_entered > 500){
TransitionAuger(AUGER_FORWARD); //skip Auger starting as it has an initial reverse pulse
}
break;
case AUGER_ALARM: //Auger will remain off until rebooted with a reset from front panel display
break;
case AUGER_PULSE:
if (millis() - auger_pulse_entered > auger_pulse_time){
if (auger_pulse_state == 1){
TransitionAuger(AUGER_PULSE);
}
else {
TransitionAuger(AUGER_OFF);
}
}
if (AugerCurrentLevel == CURRENT_HIGH && millis() - auger_pulse_entered > 500){
if (auger_pulse_state == 1){ //if in reverse...try going forward
TransitionAuger(AUGER_PULSE);
}
else {
TransitionAuger(AUGER_OFF);
}
}
break;
case AUGER_MANUAL_FORWARD:
if (AugerCurrentLevel == CURRENT_HIGH && millis() - auger_state_entered > 500){
TransitionAuger(AUGER_HIGH);
}
break;
}
}
void TransitionAuger(int new_state) {
//const prog_char new_auger_state[] PROGMEM = "New Auger State: ";
strcpy_P(p_buffer, new_auger_state);
//can look at auger_state for "old" state before transitioning at the end of this method
if (new_state != AUGER_PULSE && auger_state != AUGER_PULSE) {
auger_state_entered = millis();
}
switch (new_state) {
case AUGER_OFF:
AugerOff();
Log(p_buffer);
Logln_p("Off");
//TransitionMessage("Auger: Off ");
auger_rev_count = 0;
auger_pulse_state = 0;
break;
case AUGER_STARTING:
AugerReverse(); //start in reverse for a few moments to reduce bridging
Log(p_buffer);
Logln_p("Starting Forward");
//TransitionMessage("Auger: Starting ");
break;
case AUGER_FORWARD:
if (auger_state != AUGER_HIGH){
auger_direction_entered = millis();
}
AugerForward();
Log(p_buffer);
Logln_p("Forward");
//TransitionMessage("Auger: Forward ");
break;
case AUGER_HIGH:
Log(p_buffer);
Logln_p("Forward, Current High");
//TransitionMessage("Auger: Current High ");
break;
case AUGER_REVERSE:
if (auger_state != AUGER_REVERSE_HIGH){
auger_direction_entered = millis();
}
Log(p_buffer);
Logln_p("Reverse");
AugerReverse();
auger_rev_count++;
Logln_p("Auger Rev Count Incremented to ");
Logln(auger_rev_count);
//TransitionMessage("Auger: Reverse ");
break;
case AUGER_REVERSE_HIGH:
Log(p_buffer);
Logln_p("Reverse High Current");
//TransitionMessage("Auger: Reverse High");
break;
case AUGER_CURRENT_LOW:
Log(p_buffer);
Logln_p("Current Low");
//TransitionMessage("Auger: Low Current");
break;
case AUGER_ALARM:
AugerOff();
Log(p_buffer);
Logln_p("Alarmed, Off");
//TransitionMessage("Auger: Off ");
break;
case AUGER_PULSE:
Log(p_buffer);
Logln_p("Pulse");
if (auger_pulse_state == 0){
AugerReverse();
}
else {
AugerForward();
}
auger_pulse_entered = millis();
auger_pulse_state++;
break;
}
auger_state=new_state;
}
void checkAuger(){
FuelSwitchValue = analogRead(ANA_FUEL_SWITCH); // switch voltage, 1024 if on, 0 if off
if (FuelSwitchValue > 600){
if (FuelDemand == SWITCH_OFF){
fuel_state_entered = millis();
}
FuelDemand = SWITCH_ON;
}
else {
FuelDemand = SWITCH_OFF;
if (FuelDemand == SWITCH_ON){
fuel_state_entered = millis();
}
}
if (relay_board == 1){ //when relay board is present auger current sensing is enabled
AugerCurrentValue = (u_sublim(analogRead(ANA_AUGER_CURRENT), 120, 0) * 10)/12; //convert from analog values to current (.1A) values
if (AugerCurrentValue > AugerCurrentLevelBoundary[CURRENT_OFF][0] && AugerCurrentValue < AugerCurrentLevelBoundary[CURRENT_OFF][1]) {
AugerCurrentLevel = CURRENT_OFF;
}
if (AugerCurrentValue > AugerCurrentLevelBoundary[CURRENT_LOW][0] && AugerCurrentValue < AugerCurrentLevelBoundary[CURRENT_LOW][1]) {
AugerCurrentLevel = CURRENT_LOW;
}
if (AugerCurrentValue > AugerCurrentLevelBoundary[CURRENT_ON][0] && AugerCurrentValue < AugerCurrentLevelBoundary[CURRENT_ON][1]) {
AugerCurrentLevel = CURRENT_ON;
}
if (AugerCurrentValue > AugerCurrentLevelBoundary[CURRENT_HIGH][0] && AugerCurrentValue < AugerCurrentLevelBoundary[CURRENT_HIGH][1]) {
AugerCurrentLevel = CURRENT_HIGH;
}
}
}
void AugerReverse(){
if (relay_board == 1){
digitalWrite(FET_AUGER,LOW);
digitalWrite(FET_AUGER_REV, HIGH);
}
}
void AugerForward(){
digitalWrite(FET_AUGER, HIGH);
if (relay_board == 1){
digitalWrite(FET_AUGER_REV, LOW);
}
}
void AugerOff(){
digitalWrite(FET_AUGER,LOW);
if (relay_board == 1){
digitalWrite(FET_AUGER_REV, LOW);
}
}