-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolarController.h
134 lines (111 loc) · 3.08 KB
/
SolarController.h
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
#ifndef _SOLARCONTROLLER_h
#define _SOLARCONTROLLER_h
#define MAIN_LOOP_FREQ 100
class SolarController;
#include "Arduino.h"
#include "Display.h"
#include "Stepper.h"
#include "GPS.h"
#include "Pins.h"
#include "Menu.h"
#include "Melexis.h"
#include "DataLink.h"
#include "filter.h"
#include <EEPROM.h>
#ifndef MAX6675_H
#define MAX6675_H
#include <max6675.h>
#endif
#define ELEV_CALCULATION_INTERVAL 1000
#define DISPLAY_REFRESH_INTERVAL_MS 500
#define FOCUS_SOFT_LIMIT_LOW_INCHES 0.0
#define FOCUS_SOFT_LIMIT_HIGH_INCHES 22.25
#define FOCUS_SOFT_LIMIT_HIGH_INCHES_NOT_HOMED 0.5
#define FOCUS_SOFT_LIMIT_BUFFER_INCHES 0.10
#define FOCUS_LIMIT_HOME_OFFSET -0.15
#define ELEV_SOFT_LIMIT_LOW_DEGREES 0.0
#define ELEV_SOFT_LIMIT_HIGH_DEGREES 75.0
#define ELEV_SOFT_LIMIT_HIGH_DEGREES_NOT_HOMED 20.0
#define ELEV_SOFT_LIMIT_BUFFER_DEGREES 0.5
#define ELEV_LIMIT_HOME_OFFSET -3.0
#define ELEV_HOME_ANGLE 88.6
#define THERMOCOUPLE_BUFFER_COUNT 10
// settings for raw temperature probe
//#define FOCUS_P_COEFF 10.0
//#define FOCUS_I_COEFF 0.0
//#define FOCUS_D_COEFF 15.0
// settings for iron kettle
//#define FOCUS_P_COEFF 4.0
//#define FOCUS_I_COEFF 0.0
//#define FOCUS_D_COEFF 15.0
class SolarController {
public:
void setup(Display *_displaypanel, Stepper *_stepper_elev, Stepper *_stepper_focus_left, Stepper *_stepper_focus_right, GPS *_gps, MAX6675 *_thermocouple, MelexisTempProbe *_irProbe, DataLink *_datalink);
void run();
void khz();
void setHomeElev();
void setHomeFocus();
void setIRTempExists(bool value);
float loadPIDP();
float loadPIDI();
float loadPIDD();
float loadPIDInputCutoff();
float loadPIDDCutoff();
void savePIDP(float value);
void savePIDI(float value);
void savePIDD(float value);
void savePIDInputCutoff(float value);
void savePIDDCutoff(float value);
private:
float pCoeff = 0;
float iCoeff = 0;
float dCoeff = 0;
float inputCutoff = 0;
float dCutoff = 0;
Menu *menu;
Display *displaypanel;
Stepper *stepper_elev;
Stepper *stepper_focus_left;
Stepper *stepper_focus_right;
GPS *gps;
MAX6675 *thermocouple;
MelexisTempProbe *irProbe;
DataLink *datalink;
biquad_t inputFilter;
biquad_t dFilter;
bool isSetup = false;
bool autoFocus = false;
bool autoElev = false;
bool autoFocusHomed = false;
bool autoElevHomed = false;
unsigned long lastDisplayTime = 0;
bool displayResetNeeded = true;
float tempSetPoint = 150.0;
float tempThermocouple = 0;
float tempCurrent = 0;
float tempIR = 0;
float focusSetMaxExtension = 99.9;
float autoElevOffset = 0;
bool homingFocus = 0, homingElev = 0;
void applyLimitsAndEStops();
void updateDisplay();
void resetDisplay();
void updateGPS();
float DEGREES(float rad);
float RADIANS(float deg);
void errorDisplay(String message);
int timezoneOffset;
int tempSource;
float ISum = 0;
float lastD = 0;
float setLat, setLon;
float calcSunElev();
void doTempSetPointAdjustments();
void doModeSwitches();
bool doThermocouple();
bool doIRThermometer();
void doTemperatureControl(bool gotSample);
void doElevationControl();
void enableAutoElev();
};
#endif