Skip to content

Commit 4cecd80

Browse files
author
Scott Garrison
committed
Added Servo limits page to Display, updated Testing to be less error prone.
1 parent 7394d9a commit 4cecd80

File tree

4 files changed

+123
-37
lines changed

4 files changed

+123
-37
lines changed

Display.pde

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
void DoDisplay() {
22
boolean disp_alt; // Var for alternating value display
33
char buf[20];
4+
char menu1[] = "NEXT ADV + - ";
45
if (millis() % 2000 > 1000) {
56
disp_alt = false;
67
}
@@ -364,6 +365,53 @@ void DoDisplay() {
364365
break;
365366
}
366367

368+
break;
369+
case DISPLAY_SERVO: //need to add constraints for min and max?
370+
item_count = 2;
371+
testing_state = TESTING_SERVO; //necessary so that there isn't any conflicting servo writes
372+
Disp_RC(0,0);
373+
sprintf(buf, "ServoMin%3i", int(throttle_valve_closed));
374+
Disp_PutStr(buf);
375+
Disp_RC(0,11);
376+
sprintf(buf, " Max %3i", int(throttle_valve_open));
377+
Disp_PutStr(buf);
378+
//Row 1
379+
Disp_RC(1,0);
380+
Disp_PutStr(" Careful of Sides! ");
381+
Disp_RC(2,0);
382+
Disp_PutStr(" ");
383+
switch (cur_item) {
384+
case 1: // Servo Min
385+
Servo_Mixture.write(throttle_valve_closed);
386+
if (key == 2) {
387+
if (throttle_valve_closed + 1 < throttle_valve_open){
388+
throttle_valve_closed += 1;
389+
}
390+
}
391+
if (key == 3) {
392+
throttle_valve_closed -= 1;
393+
}
394+
Disp_RC(3,0);
395+
Disp_PutStr(menu1);
396+
Disp_RC(0,0);
397+
Disp_CursOn();
398+
break;
399+
case 2: //Servo Max
400+
Servo_Mixture.write(throttle_valve_open);
401+
if (key == 2) {
402+
throttle_valve_open += 1;
403+
}
404+
if (key == 3) {
405+
if (throttle_valve_open - 1 > throttle_valve_closed) {
406+
throttle_valve_open -= 1;
407+
}
408+
}
409+
Disp_RC(3,0);
410+
Disp_PutStr(menu1);
411+
Disp_RC(0,11);
412+
Disp_CursOn();
413+
break;
414+
}
367415
break;
368416
// case DISPLAY_TEMP2:
369417
// break;
@@ -392,6 +440,9 @@ void TransitionDisplay(int new_state) {
392440
case DISPLAY_TESTING:
393441
cur_item = 1;
394442
break;
443+
case DISPLAY_SERVO:
444+
cur_item = 1;
445+
break;
395446
}
396447
display_state=new_state;
397448
}
@@ -425,8 +476,17 @@ void DoKeyInput() {
425476
}
426477
break;
427478
case DISPLAY_TESTING:
479+
if (engine_state == ENGINE_OFF){
480+
TransitionDisplay(DISPLAY_SERVO);
481+
} else {
428482
TransitionDisplay(DISPLAY_REACTOR);
429483
TransitionTesting(TESTING_OFF);
484+
}
485+
break;
486+
case DISPLAY_SERVO:
487+
WriteServo();
488+
TransitionDisplay(DISPLAY_REACTOR); //assume that engine state is off because we are already in DISPLAY_SERVO
489+
TransitionTesting(TESTING_OFF);
430490
break;
431491
}
432492
key = -1; //key caught

KS_100kW.pde

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ unsigned long ash_on = 0;
135135
#define DISPLAY_LAMBDA 4
136136
#define DISPLAY_GRATE 5
137137
#define DISPLAY_TESTING 6
138+
#define DISPLAY_SERVO 7
139+
138140
String display_string = "";
139141

140142
//Testing States
@@ -152,6 +154,7 @@ String display_string = "";
152154
#define TESTING_ANA_FUEL_SWITCH 11
153155
#define TESTING_ANA_POT1 12
154156
#define TESTING_ANA_POT2 13
157+
#define TESTING_SERVO 14
155158

156159
//Test Variables
157160
int testing_state = TESTING_OFF;
@@ -294,6 +297,7 @@ int lambda_state;
294297
unsigned long lambda_state_entered;
295298

296299
//Governor
300+
byte servo_min,servo_max;
297301
double throttle_valve_open = 123; //calibrated angle for servo valve open
298302
double throttle_valve_closed = 48; //calibrated angle for servo valve closed (must be smaller value than open)
299303
double governor_setpoint;
@@ -482,6 +486,7 @@ void setup() {
482486
//LoadLambda(); - must save lambda data first?
483487
Serial.begin(57600);
484488
InitSD();
489+
LoadServo();
485490

486491
Disp_Init();
487492
Kpd_Init();
@@ -522,41 +527,48 @@ void setup() {
522527
void loop() {
523528
if (millis() >= nextTime3) {
524529
nextTime3 += loopPeriod3;
525-
// first, read all KS's sensors
526-
Temp_ReadAll(); // reads into array Temp_Data[], in deg C
527-
Press_ReadAll(); // reads into array Press_Data[], in hPa
528-
Timer_ReadAll(); // reads pulse timer into Timer_Data, in RPM ??? XXX
529-
DoPressure();
530-
DoSerialIn();
531-
DoLambda();
532-
//DoGovernor();
533-
DoAuger();
534-
DoRotaryValve();
535-
DoConveyor();
536-
DoEngine();
537-
DoGrate();
538-
DoAshOut();
539-
DoAshGrate();
540-
DoHopperAgitator();
541-
//DoServos();
542-
DoFlare();
543-
DoReactor();
530+
if (testing_state == TESTING_OFF) {
531+
// first, read all KS's sensors
532+
Temp_ReadAll(); // reads into array Temp_Data[], in deg C
533+
Press_ReadAll(); // reads into array Press_Data[], in hPa
534+
Timer_ReadAll(); // reads pulse timer into Timer_Data, in RPM ??? XXX
535+
DoPressure();
536+
DoSerialIn();
537+
DoLambda();
538+
//DoGovernor();
539+
DoAuger();
540+
DoRotaryValve();
541+
DoConveyor();
542+
DoEngine();
543+
DoGrate();
544+
DoAshOut();
545+
DoAshGrate();
546+
DoHopperAgitator();
547+
//DoServos();
548+
DoFlare();
549+
DoReactor();
550+
DoControlInputs();
551+
DoDriveReset(); //reset drive commands to correctly drive AC motors
552+
//TODO: Add OpenEnergyMonitor Library
553+
}
544554
DoKeyInput();
545555
DoHeartBeat(); // blink heartbeat LED
546-
DoControlInputs();
547-
DoDriveReset(); //reset drive commands to correctly drive AC motors
548-
//TODO: Add OpenEnergyMonitor Library
556+
549557
if (millis() >= nextTime2) {
550558
nextTime2 += loopPeriod2;
551559
DoDisplay();
552560
if (millis() >= nextTime1) {
553561
nextTime1 += loopPeriod1;
554-
DoFilter();
555-
DoDatalogging();
556-
DoAlarmUpdate();
562+
if (testing_state == TESTING_OFF) {
563+
DoFilter();
564+
DoDatalogging();
565+
DoAlarmUpdate();
566+
}
557567
if (millis() >= nextTime0) {
558-
nextTime0 += loopPeriod0;
559-
DoAlarm();
568+
if (testing_state == TESTING_OFF) {
569+
nextTime0 += loopPeriod0;
570+
DoAlarm();
571+
}
560572
}
561573
}
562574
}

Servo.pde

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,27 @@ void InitServos() {
1212
}
1313

1414

15+
void LoadServo() {
16+
servo_min = EEPROM.read(23);
17+
if (servo_min != 255) { //if EEPROM in default value, then default to 133
18+
premix_valve_open = int(servo_min);
19+
}
20+
servo_max = EEPROM.read(22);
21+
if (servo_max != 255) { //if EEPROM in default value, then default to 68
22+
premix_valve_closed = int(servo_max);
23+
}
24+
}
25+
26+
void WriteServo(){
27+
if (servo_min != premix_valve_closed) {
28+
EEPROM.write(22,premix_valve_closed);
29+
servo_min = premix_valve_closed;
30+
Serial.println("#Writing Servo Min position setting to EEPROM");
31+
}
32+
if (servo_max != premix_valve_open){
33+
EEPROM.write(23,premix_valve_open);
34+
servo_max = premix_valve_open;
35+
Serial.println("#Writing Servo Max position setting to EEPROM");
36+
}
37+
}
38+

Test.pde

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
void DoTesting() {
2-
while (testing_state != TESTING_OFF) {
3-
//run seperate closed loop while in testing mode, taking all processor cycles
4-
DoDisplay();
5-
DoKeyInput();
6-
DoHeartBeat();
7-
}
8-
}
9-
101
void TransitionTesting(int new_state) {
112
testing_state_entered = millis();
123
Serial.print("#Switching to testing state:");
@@ -112,7 +103,6 @@ void GoToNextTestingState() {
112103
switch (testing_state) {
113104
case TESTING_OFF:
114105
TransitionTesting(TESTING_FET0);
115-
DoTesting();
116106
break;
117107
case TESTING_FET0:
118108
TransitionTesting(TESTING_FET1);

0 commit comments

Comments
 (0)