-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMainControlLoop.cpp
More file actions
208 lines (181 loc) · 5.55 KB
/
MainControlLoop.cpp
File metadata and controls
208 lines (181 loc) · 5.55 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
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
#include "MainControlLoop.hpp"
MainControlLoop::MainControlLoop()
: battery_monitor(),
button_monitor(),
camera_report_monitor(),
command_monitor(),
current_monitor(),
imu_monitor(),
imu_downlink(),
normal_report_monitor(),
imudownlink_report_monitor(),
photoresistor_monitor(),
rockblock_report_monitor(),
temperature_monitor(),
acs_control_task(),
burnwire_control_task(),
camera_control_task(),
rockblock_control_task(),
eeprom_control_task(),
mission_manager(),
clock_manager()
{
delay(1000);
(void)Watchdog.enable(constants::watchdog::max_period_ms);
}
void MainControlLoop::execute()
{
sfr::mission::cycle_start = millis();
#ifdef VERBOSE
Serial.println("--------------------START LOOP--------------------");
// mission mode
Serial.print("Current Mission Mode: ");
Serial.println(sfr::mission::current_mode->get_name().c_str());
// button
if (sfr::button::pressed) {
Serial.println("Button pressed");
} else {
Serial.println("Button UNpressed");
}
if (sfr::button::button_pressed->is_valid()) {
Serial.println("Button valid");
} else {
Serial.println("Button INvalid");
}
// photoresistor
if (sfr::photoresistor::covered) {
Serial.println("Photoresistor covered");
} else {
Serial.println("Photoresistor UNcovered");
}
if (sfr::photoresistor::light_val_average_standby->is_valid()) {
Serial.println("Photoresistor valid");
} else {
Serial.println("Photoresistor INvalid");
}
// ACS
Serial.print("ACS Mode: ");
switch (sfr::acs::mode) {
case ((uint8_t)acs_mode_type::simple):
Serial.println("SIMPLE");
break;
case ((uint8_t)acs_mode_type::detumble):
Serial.println("DETUMBLE");
break;
}
if (sfr::acs::off) {
Serial.println("ACS OFF");
} else {
Serial.println("ACS ON");
}
// battery
if (sfr::battery::voltage_average->get_value(&val)) {
Serial.print("Battery Voltage: ");
Serial.print(val);
Serial.println(" V");
} else {
Serial.println("Battery INvalid");
}
// IMU
if (sfr::imu::powered) {
Serial.println("IMU powered");
} else {
Serial.println("IMU UNpowered");
}
if (sfr::imu::mag_x_value->get_value(&val)) {
Serial.print("MAG X: ");
Serial.println(val);
}
if (sfr::imu::mag_y_value->get_value(&val)) {
Serial.print("MAG Y: ");
Serial.println(val);
}
if (sfr::imu::mag_z_value->get_value(&val)) {
Serial.print("MAG Z: ");
Serial.println(val);
}
if (sfr::imu::gyro_x_value->get_value(&val)) {
Serial.print("GYRO X: ");
Serial.println(val);
}
if (sfr::imu::gyro_y_value->get_value(&val)) {
Serial.print("GYRO Y: ");
Serial.println(val);
}
if (sfr::imu::gyro_z_value->get_value(&val)) {
Serial.print("GYRO Z: ");
Serial.println(val);
}
val = sfr::imu::gyro_x_value->get_value(&val) && sfr::imu::gyro_y_value->get_value(&val) && sfr::imu::gyro_z_value->get_value(&val) && sfr::imu::mag_x_value->get_value(&val) && sfr::imu::mag_y_value->get_value(&val) && sfr::imu::mag_z_value->get_value(&val);
if (!val) {
Serial.println("IMU INvalid");
} else {
Serial.println("IMU valid");
}
Serial.print("IMU initialization failed attempts: ");
Serial.println(sfr::imu::failed_times);
// Camera
if (sfr::camera::powered) {
Serial.println("Optical sensor powered");
} else {
Serial.println("Optical sensor UNpowered");
}
Serial.print("Optical sensor initialization failed attempts: ");
Serial.println(sfr::camera::failed_times);
// Temp
if (sfr::temperature::temp_c_average->get_value(&val)) {
Serial.print("Temp: ");
Serial.print(val);
Serial.println(" C");
} else {
Serial.println("Temp INvalid");
}
// Solar Current
if (sfr::current::solar_current_average->get_value(&val)) {
Serial.print("Solar Current: ");
Serial.print(val);
Serial.println(" mA");
} else {
Serial.println("Solar Current INvalid");
}
// RockBLOCK
if (sfr::rockblock::sleep_mode) {
Serial.println("RockBLOCK sleeping");
} else {
Serial.println("RockBLOCK NOT sleeping");
}
Serial.print("RockBLOCK Mode: ");
Serial.println(sfr::rockblock::mode.get());
// EEPROM
Serial.print("Total time alive (across all boots): ");
Serial.println(sfr::eeprom::time_alive);
#endif
mission_manager.execute();
burnwire_control_task.execute();
rockblock_control_task.execute();
command_monitor.execute();
camera_control_task.execute();
acs_control_task.execute();
imu_monitor.execute();
battery_monitor.execute();
button_monitor.execute();
current_monitor.execute();
photoresistor_monitor.execute();
rockblock_report_monitor.execute();
temperature_monitor.execute();
imu_downlink.execute();
normal_report_monitor.execute();
camera_report_monitor.execute();
imudownlink_report_monitor.execute();
eeprom_control_task.execute();
// Clock Manager MUST run last
clock_manager.execute();
// Pet watchdog
Watchdog.reset();
#ifdef VERBOSE
Serial.print("Cycle time (ms): ");
Serial.println(millis() - sfr::mission::cycle_start);
Serial.println("--------------------END LOOP--------------------");
Serial.println(" ");
#endif
}