Skip to content

Commit

Permalink
Rewriting ground station code
Browse files Browse the repository at this point in the history
  • Loading branch information
crnicholson committed Nov 20, 2024
1 parent 3f6018e commit 6d2eeca
Show file tree
Hide file tree
Showing 30 changed files with 2,323 additions and 666 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.gitattributes
secrets.h
*.vscode
*.json
*.DS_Store
Expand Down
9 changes: 5 additions & 4 deletions .vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"board": "arduino:samd:arduino_zero_native",
"port": "/dev/tty.usbmodem12201",
"sketch": "Code/autopilot/autopilot.ino",
"output": "../ArduinoOutput"
"board": "esp32:esp32:esp32",
"port": "/dev/tty.SLAB_USBtoUART",
"sketch": "Code/groundStation/groundStation.ino",
"output": "../ArduinoOutput",
"configuration": "JTAGAdapter=default,PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,LoopCore=1,EventsCore=1,DebugLevel=none,EraseFlash=none"
}
496 changes: 287 additions & 209 deletions .vscode/c_cpp_properties.json

Large diffs are not rendered by default.

Binary file modified Code/.DS_Store
Binary file not shown.
19 changes: 18 additions & 1 deletion Code/autopilot/autopilot.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "waypoint.h"
#include <Scheduler.h>

// Below are global variables. If you edit these, you'll need to edit vars.h as well.

// GPS vars.
float lat, lon, altitude, targetLat = TARGET_LAT, targetLon = TARGET_LON, hdop;
int year, month, day, hour, minute, second, gpsLast;
Expand Down Expand Up @@ -360,10 +362,12 @@ void loop3() {
packet.pressure = pressure;
packet.humidity = humidity;
packet.volts = voltage;
packet.hdop = hdop;
packet.yaw = yaw;
packet.pitch = pitch;
packet.roll = roll;
packet.year = year;
packet.month = month;
packet.day = day;
packet.hour = hour;
packet.minute = minute;
packet.second = second;
Expand All @@ -386,15 +390,28 @@ void loop3() {
packet.yaw = yaw;
packet.pitch = pitch;
packet.roll = roll;
packet.year = year;
packet.month = month;
packet.day = day;
packet.hour = hour;
packet.minute = minute;
packet.second = second;
packet.txCount++;
packet.abortFlight = abortFlight;
#ifdef HAMMING
sendHammingData(packet); // Sends with forward error correction for redundancy over long distances.
#endif
#ifndef HAMMING
normalSend(); // Sends without forward error correction.
#endif
lastLoRa = millis();
#endif
}
#ifdef HAMMING
hammingReceive(); // Receive LoRa data to abort flight or change targetLat and targetLon.
#endif
#ifndef HAMMING
normalReceive(); // Receive LoRa data to abort flight or change targetLat and targetLon.
#endif
}
#endif
12 changes: 6 additions & 6 deletions Code/autopilot/lora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ void loraSetup() {
#endif
}

void sendData(struct data &newPacket) {
void sendData(struct data packet) {
// Wait until the LoRa is ready to send a new packet!
while (LoRa.beginPacket() == 0) {
delay(2);
}

LoRa.beginPacket();
LoRa.write((byte *)&newPacket, sizeof(newPacket));
LoRa.write((byte *)&packet, sizeof(packet));
LoRa.endPacket(true); // Use async send.
}

void sendHammingData(struct data &newPacket) {
byte *byteArray = (byte *)&newPacket; // Convert the packet to a byte array.
void sendHammingData(struct data packet) {
byte *byteArray = (byte *)&packet; // Convert the packet to a byte array.

byte encodedData[2 * sizeof(newPacket)]; // Hamming(7,4) doubles the size!
byte encodedData[2 * sizeof(packet)]; // Hamming(7,4) doubles the size!

for (size_t i = 0; i < sizeof(newPacket); ++i) {
for (size_t i = 0; i < sizeof(packet); ++i) {
byte highNibble = hammingEncode((byteArray[i] >> 4) & 0xF);
byte lowNibble = hammingEncode(byteArray[i] & 0xF);

Expand Down
4 changes: 2 additions & 2 deletions Code/autopilot/lora.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <SPI.h>

void loraSetup();
void sendData(struct data &newPacket);
void sendHammingData(struct data &newPacket);
void sendData(struct data packet);
void sendHammingData(struct data packet);
byte hammingEncode(byte data);
void hammingReceive();
byte hammingDecode(byte data);
3 changes: 2 additions & 1 deletion Code/autopilot/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// #define DROP_START // Don't start the program until the glider has detected a drop in altitude.
#define DISPLAY_DATA // Dump the data on the serial monitor every update.
// #define FLYING_WING // If enabled, the glider uses flying wing kinematics. If not, it uses the traditional rudder and elevator.
// #define SERVO_NONBLOCKING // Use non-blocking code for the servo.
// #define SERVO_NONBLOCKING // Use non-blocking code for the servo.
// #define HAMMING // Use hamming encoding for the LoRa data.

// Pins.
#define LED 13
Expand Down
3 changes: 2 additions & 1 deletion Code/autopilot/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ extern float temperature, pressure, bmeAltitude;
extern int humidity;

struct data {
byte alignment = 100;
float lat, lon, tLat, tLon, altitude, temperature, pressure, humidity, volts, hdop;
short yaw, pitch, roll;
byte hour, minute, second;
byte year, month, day, hour, minute, second;
short txCount;
byte abortFlight;
char callSign[7] = CALL_SIGN;
Expand Down
Loading

0 comments on commit 6d2eeca

Please sign in to comment.