-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflight_computer.cpp
More file actions
64 lines (56 loc) · 1.62 KB
/
Copy pathflight_computer.cpp
File metadata and controls
64 lines (56 loc) · 1.62 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
// flight_computer.cpp
#include "flight_computer.h"
#include "flight_control_vertical.h"
#include "flight_control_horizontal.h"
#include "ground_station.h"
#include "sensors.h"
// Flight Modes
enum FlightMode {
VERTICAL,
HORIZONTAL
};
FlightMode currentMode = VERTICAL;
void initFlightComputer() {
initVerticalController();
initHorizontalController();
initGroundStation();
initSensors();
}
void updateFlightComputer() {
// Check for ground station commands
if (groundStationCommandReceived()) {
GroundStationCommand cmd = getGroundStationCommand();
if (cmd.type == SWITCH_MODE) {
currentMode = (currentMode == VERTICAL) ? HORIZONTAL : VERTICAL;
}
else if (cmd.type == SET_TARGET) {
if (currentMode == VERTICAL) {
setDesiredAltitude(cmd.altitude);
setDesiredOrientation(cmd.pitch, cmd.roll);
} else {
setDesiredHeading(cmd.heading);
setDesiredSpeed(cmd.speed);
}
}
}
// Update the current flight mode
if (currentMode == VERTICAL) {
updateVerticalControl();
} else {
updateHorizontalControl();
}
}
FlightData getFlightData() {
FlightData data;
data.altitude = readBarometer();
data.pitch = getPitch();
data.roll = getRoll();
data.yaw = getYaw();
data.speed = getSpeed();
data.heading = getHeading();
data.verticalSpeed = getVerticalSpeed();
data.acceleration = getAcceleration();
data.motorPower = getMotorPowerLevels();
data.servoAngles = getServoAngles();
return data;
}