-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
88 lines (75 loc) · 2.38 KB
/
Copy pathmain.cpp
File metadata and controls
88 lines (75 loc) · 2.38 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
#include <Arduino.h>
#include "flight_control_vertical.h"
#include "flight_control_horizontal.h"
#include "LoRa.h" // Include LoRa library
#include <usb_seremu.h>
#include "barometer.h"
#include "../../.platformio/packages/framework-arduinoteensy/libraries/RadioHead/RadioHead.h"
// Flight Modes
enum FlightMode { IDLE, VERTICAL, HORIZONTAL };
FlightMode currentMode = IDLE; // Start in IDLE mode
// Target Values
float targetAltitude = 115.0; // Target altitude in meter
float targetPitch = 0.0; // Target pitch for horizontal mode
float targetRoll = 0.0; // Target roll for horizontal mode
// LoRa Settings
#define LORA_SS 10
#define LORA_RST 9
#define LORA_DIO0 2
// Arming Status
bool isArmed = false;
// Function to initialize LoRa communication
void initLoRa() {
LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0);
if (!LoRa.begin(915E6)) { // Frequency: 915 MHz
Serial.println("LoRa initialization failed!");
while (1);
}
Serial.println("LoRa initialized successfully.");
}
void setup() {
Serial.begin(9600);
initLoRa();
initBarometer();
initVerticalController();
initHorizontalController();
Serial.println("VTOL System Initialized. Waiting for Ground Station Command...");
}
void loop() {
float pressure = readBarometer();
Serial.println(pressure); // Test output
delay(1000);
// 🛡️ Arming Sequence (Triggered by Ground Station)
if (!isArmed) {
int packetSize = LoRa.parsePacket();
if (packetSize) {
String command = "";
while (LoRa.available()) {
command += (char)LoRa.read();
}
if (command == "ARM") {
isArmed = true;
currentMode = VERTICAL;
Serial.println("VTOL ARMED by Ground Station. Launching in Vertical Mode...");
}
}
return; // Skip flight control if not armed
}
// 🛩️ Flight Mode Switching Logic (placeholder conditions)
if (/* condition to switch to horizontal mode */ false) {
currentMode = HORIZONTAL;
Serial.println("Switching to Horizontal Flight Mode.");
}
else if (/* condition to switch to vertical mode */ false) {
currentMode = VERTICAL;
Serial.println("Switching to Vertical Flight Mode.");
}
// 🚀 Flight Control Based on Current Mode
if (currentMode == VERTICAL) {
updateVerticalControl();
}
else if (currentMode == HORIZONTAL) {
updateHorizontalControl();
}
delay(20); // Control loop refresh rate (~50 Hz)
}