Skip to content

Commit

Permalink
Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
crnicholson committed Dec 6, 2024
1 parent 27b4498 commit 1f461b4
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 71 deletions.
86 changes: 43 additions & 43 deletions Code/autopilot/autopilot.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int lastLoRa, loraUpdateRate = LORA_UPDATE_RATE, updateRate = UPDATE_RATE, lastU
bool abortFlight, altitudeLock, lowVoltage, ultraLowVoltage;
float desiredPitch = DESIRED_PITCH, voltage;

struct data packet;
struct data toGliderStruct;

void setup() {
pinMode(GPS_SLEEP_PIN, OUTPUT);
Expand Down Expand Up @@ -353,53 +353,53 @@ void loop2() {
#ifdef USE_LORA
void loop3() {
#ifdef FAST_LORA
packet.lat = lat;
packet.lon = lon;
packet.tLat = targetLat;
packet.tLon = targetLon;
packet.altitude = altitude;
packet.temperature = temperature;
packet.pressure = pressure;
packet.humidity = humidity;
packet.volts = voltage;
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;
sendData(packet);
toGliderStruct.lat = lat;
toGliderStruct.lon = lon;
toGliderStruct.tLat = targetLat;
toGliderStruct.tLon = targetLon;
toGliderStruct.altitude = altitude;
toGliderStruct.temperature = temperature;
toGliderStruct.pressure = pressure;
toGliderStruct.humidity = humidity;
toGliderStruct.volts = voltage;
toGliderStruct.yaw = yaw;
toGliderStruct.pitch = pitch;
toGliderStruct.roll = roll;
toGliderStruct.year = year;
toGliderStruct.month = month;
toGliderStruct.day = day;
toGliderStruct.hour = hour;
toGliderStruct.minute = minute;
toGliderStruct.second = second;
toGliderStruct.txCount++;
toGliderStruct.abortFlight = abortFlight;
sendData(toGliderStruct);
lastLoRa = millis();
#endif
#ifndef FAST_LORA
if (millis() - lastLoRa > loraUpdateRate) {
packet.lat = lat;
packet.lon = lon;
packet.tLat = targetLat;
packet.tLon = targetLon;
packet.altitude = altitude;
packet.temperature = temperature;
packet.pressure = pressure;
packet.humidity = humidity;
packet.volts = voltage;
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;
toGliderStruct.lat = lat;
toGliderStruct.lon = lon;
toGliderStruct.tLat = targetLat;
toGliderStruct.tLon = targetLon;
toGliderStruct.altitude = altitude;
toGliderStruct.temperature = temperature;
toGliderStruct.pressure = pressure;
toGliderStruct.humidity = humidity;
toGliderStruct.volts = voltage;
toGliderStruct.yaw = yaw;
toGliderStruct.pitch = pitch;
toGliderStruct.roll = roll;
toGliderStruct.year = year;
toGliderStruct.month = month;
toGliderStruct.day = day;
toGliderStruct.hour = hour;
toGliderStruct.minute = minute;
toGliderStruct.second = second;
toGliderStruct.txCount++;
toGliderStruct.abortFlight = abortFlight;
#ifdef HAMMING
sendHammingData(packet); // Sends with forward error correction for redundancy over long distances.
sendHammingData(toGliderStruct); // Sends with forward error correction for redundancy over long distances.
#endif
#ifndef HAMMING
normalSend(); // Sends without forward error correction.
Expand Down
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 packet) {
void sendData(struct data toGliderStruct) {
// Wait until the LoRa is ready to send a new packet!
while (LoRa.beginPacket() == 0) {
delay(2);
}

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

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

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

for (size_t i = 0; i < sizeof(packet); ++i) {
for (size_t i = 0; i < sizeof(toGliderStruct; ++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 packet);
void sendHammingData(struct data packet);
void sendData(struct data toGliderStruct);
void sendHammingData(struct data toGliderStruct);
byte hammingEncode(byte data);
void hammingReceive();
byte hammingDecode(byte data);
36 changes: 18 additions & 18 deletions Code/autopilot/sd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,43 @@
// }
// }

// void writeDataToSD(Packet packet) {
// void writeDataToSD(Packet toGliderStruct) {
// File dataFile = SD.open(FILE_NAME, FILE_WRITE);

// if (dataFile) {
// dataFile.print(packet.lat);
// dataFile.print(toGliderStruct.lat);
// dataFile.print(",");
// dataFile.print(packet.lon);
// dataFile.print(toGliderStruct.lon);
// dataFile.print(",");
// dataFile.print(packet.tLat);
// dataFile.print(toGliderStruct.tLat);
// dataFile.print(",");
// dataFile.print(packet.tLon);
// dataFile.print(toGliderStruct.tLon);
// dataFile.print(",");
// dataFile.print(packet.altitude);
// dataFile.print(toGliderStruct.altitude);
// dataFile.print(",");
// dataFile.print(packet.temperature);
// dataFile.print(toGliderStruct.temperature);
// dataFile.print(",");
// dataFile.print(packet.pressure);
// dataFile.print(toGliderStruct.pressure);
// dataFile.print(",");
// dataFile.print(packet.humidity);
// dataFile.print(toGliderStruct.humidity);
// dataFile.print(",");
// dataFile.print(packet.volts);
// dataFile.print(toGliderStruct.volts);
// dataFile.print(",");
// dataFile.print(packet.yaw);
// dataFile.print(toGliderStruct.yaw);
// dataFile.print(",");
// dataFile.print(packet.pitch);
// dataFile.print(toGliderStruct.pitch);
// dataFile.print(",");
// dataFile.print(packet.roll);
// dataFile.print(toGliderStruct.roll);
// dataFile.print(",");
// dataFile.print(packet.hour);
// dataFile.print(toGliderStruct.hour);
// dataFile.print(",");
// dataFile.print(packet.minute);
// dataFile.print(toGliderStruct.minute);
// dataFile.print(",");
// dataFile.print(packet.second);
// dataFile.print(toGliderStruct.second);
// dataFile.print(",");
// dataFile.print(packet.txCount);
// dataFile.print(toGliderStruct.txCount);
// dataFile.print(",");
// dataFile.println(packet.abortFlight);
// dataFile.println(toGliderStruct.abortFlight);

// dataFile.close();
// } else {
Expand Down
2 changes: 1 addition & 1 deletion Code/autopilot/sd.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
// #include <SPI.h>

// void sdSetup();
// void writeDataToSD(Packet packet);
// void writeDataToSD(Packet toGliderStruct);
4 changes: 3 additions & 1 deletion Code/autopilot/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ struct data {
byte year, month, day, hour, minute, second;
short txCount;
bool abortFlight;
int password;
float user1, user2, user3, user4, user5;
char callSign[7] = CALL_SIGN;
};

extern struct data packet;
extern struct data toGliderStruct;

// Other vars.
extern int lastLoRa, abortCounter, loraUpdateRate, updateRate, lastUpdate;
Expand Down

0 comments on commit 1f461b4

Please sign in to comment.