-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ino
108 lines (96 loc) · 2.67 KB
/
main.ino
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
/**
* @file main.ino
* @author Dean Sellas (dean@deansellas.com)
* @brief Main Execution Code for the flight controller. This will handle all the flight specific code and link together all the subsystems.
* @version 0.1
* @date 2022-09-18
*
* @copyright GNU General Public License v3.0
*
*/
#include "src/pch.h"
#include "src/Sensors/MPU6050/mpu6050.h"
#include "src/Sensors/BME280/bme280.h"
FAR::StateController::StateController *stateController;
Logger::Logger *mainLogger;
BasicLED::BasicRGB *computerStatusLED_main = new BasicLED::BasicRGB(12, 11, 10);
Sensors::MPU6050 *mainMPU;
Sensors::BME280 *mainBME;
bool endLoop = false, isLanded = false;
void setup(void)
{
mainLogger = mainLogger->GetInstance(Logger::States::Debug);
mainLogger->Writeln("FAR Initializing...");
stateController = stateController->GetInstance();
computerStatusLED_main->ledSetup();
mainMPU = new Sensors::MPU6050();
mainBME = new Sensors::BME280();
if (stateController->getFailureCode() == FAILURE_NONE)
{
stateController->setState(ON_PAD_TESTS);
}
}
void loop(void)
{
if(isLanded)
{
landed();
return;
}
// if error is thrown and logged, stop all code execution.
switch (stateController->getCurrentState())
{
// if failure do nothing
case (FAILURE):
if (!endLoop)
{
//mainLogger->Write("Failure Code: ", Logger::States::Error);
mainLogger->Writeln(stateController->getCurrentFailureToString(), Logger::States::Error);
}
computerStatusLED_main->redOn();
delay(1000);
computerStatusLED_main->redOff();
delay(1000);
endLoop = true;
return;
case (ON_PAD_TESTS):
computerStatusLED_main->blueOn();
mainMPU->Calibrate();
mainBME->Calibrate();
computerStatusLED_main->blueOff();
//stateController->setFailure(UNDEFINED_ERROR);
mainLogger->Writeln("On Pad Tests Done... All Systems GO for launch!", Logger::States::Info);
stateController->setState(READY_FOR_LAUNCH);
return;
case (ASCENT):
computerStatusLED_main->turnOffAll();
return;
case (COAST):
return;
case (CHUTE_DEPLOYMENT):
return;
case (DESCENT):
return;
case (LANDING):
return;
case (TOUCHDOWN):
// cleanup unneeded classes to save memory and battery life while waiting for recovery
cleanup();
landed();
}
}
void cleanup()
{
delete mainMPU;
delete mainBME;
mainMPU = NULL;
mainBME = NULL;
isLanded = true;
return;
}
void landed()
{
// TODO: IMPLEMENT
computerStatusLED_main->greenOn();
return;
}