Skip to content

Commit

Permalink
Merge pull request #17 from TeamSunride/karman-mini
Browse files Browse the repository at this point in the history
Karman mini
  • Loading branch information
danverstom authored Dec 5, 2022
2 parents 4f19dbd + 1a2df1f commit c254958
Show file tree
Hide file tree
Showing 27 changed files with 50,395 additions and 104 deletions.
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@
[submodule "lib/Protocol"]
path = lib/Protocol
url = https://github.com/TeamSunride/Protocol
[submodule "lib/Arduino-LSM6DSO32"]
path = lib/Arduino-LSM6DSO32
url = https://github.com/TeamSunride/Arduino-LSM6DSO32
[submodule "lib/Fifo"]
path = lib/Fifo
url = https://github.com/TeamSunride/Fifo
[submodule "lib/Arduino-LIS3MDL"]
path = lib/Arduino-LIS3MDL
url = https://github.com/TeamSunride/Arduino-LIS3MDL
Binary file added Ground Station Base board.pdf
Binary file not shown.
Binary file added MRAS-DART v1.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<p align="center">
<img src="assets\images\MRAS_banner\MRAS_Banner.jpg" />
</p>
</p>

During the academic year 2021-2022 the Sunride rocket team worked on
two rocketry projects, Karman Alpha and SpaceDart. These rockets had
Expand Down
2 changes: 1 addition & 1 deletion extra_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def after_upload(source, target, env):
print("Delay while uploading...")
import time
time.sleep(1)
time.sleep(3)
print("Done!")

env.AddPostAction("upload", after_upload)
49,730 changes: 49,730 additions & 0 deletions launch_data/20_11_2022/launch_1.csv

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions launch_data/20_11_2022/plots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pandas
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('TkAgg')
plt.style.use("ggplot")

df = pandas.read_csv("launch_1.csv", usecols=range(1, 20))
df["time_seconds"] = df["timestamp"].subtract(df["timestamp"][0]).div(1000)
print(df)


df.plot("time_seconds", y=["imuAX", "imuAY", "imuAZ"], xlabel="Time (s)", ylabel="Acceleration (m/s)",
title="Acceleration")
plt.show()

df.plot("time_seconds", y=["imuGX", "imuGY", "imuGZ"], xlabel="Time (s)", ylabel="Gyroscope (unit?)",
title="Gyroscope Data")
plt.show()

df.plot("time_seconds", y=["imuMX", "imuMY", "imuMZ"], xlabel="Time (s)", ylabel="Magnetometer value",
title="Magnetometer Data")
plt.show()

df.plot("time_seconds", y=["pressure"], xlabel="Time (s)", ylabel="Pressure (Pa)",
title="Barometer data")
plt.show()

df.plot("time_seconds", y=["h"], xlabel="Time (s)", ylabel="Altitude (m)",
title="Barometric altitude")
plt.show()

df["h_adjusted"] = df["h"] - df["h"][0]
df.plot("time_seconds", y=["h_adjusted"], xlabel="Time (s)", ylabel="Altitude (m)",
title="Barometric altitude (adjusted)")
plt.show()
1 change: 1 addition & 0 deletions lib/Arduino-LIS3MDL
Submodule Arduino-LIS3MDL added at bad1f2
1 change: 1 addition & 0 deletions lib/Arduino-LSM6DSO32
Submodule Arduino-LSM6DSO32 added at 27012d
1 change: 1 addition & 0 deletions lib/Fifo
Submodule Fifo added at d58dad
1 change: 1 addition & 0 deletions lib/buzzer/buzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "buzzer.h"

void buzzer_tone(uint32_t frequency, uint32_t duration, bool block) {
if (!MRAS_ENABLE_BUZZER) return;
tone(BUZZER_PIN, frequency, duration);

if (block) {
Expand Down
9 changes: 9 additions & 0 deletions lib/buzzer/buzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@

#include "Arduino.h"

#ifdef GS_V1_PINS
#define BUZZER_PIN A5
#elif DART_PINS
#define BUZZER_PIN 37
#elif MRAS_DART_PINS
#define BUZZER_PIN 2
#endif

#define MRAS_ENABLE_BUZZER true
#define MRAS_ENABLE_BEEPING true

void buzzer_tone(uint32_t frequency, uint32_t duration, bool block=false);

Expand Down
25 changes: 25 additions & 0 deletions lib/downlink/Payload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Created by Tom Danvers on 16/11/2022.
//

#ifndef MRAS_PAYLOAD_H
#define MRAS_PAYLOAD_H

#include <cstdint>

enum PayloadType : uint8_t {
UNDEFINED,
Test_Payload_t,
DARTDebugPayload_t,
};

class Payload {
protected:
PayloadType type = PayloadType::UNDEFINED;
public:
PayloadType get_type() {
return type;
}
};

#endif //MRAS_PAYLOAD_H
6 changes: 6 additions & 0 deletions lib/downlink/downlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace downlink {
#ifdef DART_PINS
SX1262 radio = new Module(CHIP_SELECT_PIN, DIO1_PIN, RESET_PIN,
BUSY_PIN, SPI1);
#elif MRAS_DART_PINS
SX1262 radio = new Module(CHIP_SELECT_PIN, DIO1_PIN, RESET_PIN,
BUSY_PIN, SPI1);
#else
SX1262 radio = new Module(CHIP_SELECT_PIN, DIO1_PIN, RESET_PIN,
BUSY_PIN);
Expand All @@ -33,8 +36,11 @@ namespace downlink {
int downlink::setupRadio(bool explicitHeader) {
#ifdef DART_PINS
SPI1.begin(); // DART uses SPI1 for SX1262
#elif MRAS_DART_PINS
SPI1.begin();
#endif


Serial.println("Calling radio.begin()");
radioState = radio.begin(frequency, bandwidth, spreadingFactor, codeRate, syncWord, power,
8, 0, true);
Expand Down
13 changes: 11 additions & 2 deletions lib/downlink/downlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace downlink {
const uint8_t spreadingFactor = 5; // LoRa spreading factor
const uint8_t codeRate = 5; // LoRa coding rate denominator.
const uint8_t syncWord = 0x22; // 2-byte LoRa sync word
const int8_t power = 12; // output power in dBm
const int8_t power = 22; // output power in dBm

// ===[ RADIO PIN DEFINITIONS ]===

Expand Down Expand Up @@ -50,7 +50,7 @@ namespace downlink {
#define RX_ENABLE_PIN 10
#define TX_ENABLE_PIN 9

#elif GS_V1_RADIO_PINS
#elif GS_V1_PINS

#define CHIP_SELECT_PIN 0
#define DIO1_PIN 1
Expand All @@ -59,6 +59,15 @@ namespace downlink {
#define RX_ENABLE_PIN 6
#define TX_ENABLE_PIN 5

#elif MRAS_DART_PINS

#define CHIP_SELECT_PIN 31
#define DIO1_PIN 33
#define RESET_PIN 32
#define BUSY_PIN 34
#define RX_ENABLE_PIN 36
#define TX_ENABLE_PIN 35

# else

// Default pin values for radio (with ARDUINO):
Expand Down
84 changes: 53 additions & 31 deletions lib/downlink/payloads/DARTDebugPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
#include "IMU.h"
#include "GPS.h"
#include "Barometer.h"
#include "Accelerometer.h"

struct DARTDebugPayload {
downlink::PayloadType type = downlink::PayloadType::DARTDebugPayload;
#include "Payload.h"
#include "Int64String.h"

// MPU6050 data
Vector<float, 3> mpuAccel {0,0,0};
Vector<float, 3> mpuGyro {0,0,0};
class DARTDebugPayload : public Payload {
public:
// IMU data
Vector<float, 3> imuAccel {0, 0, 0};
Vector<float, 3> imuGyro {0, 0, 0};
Vector<float, 3> imuMag {0, 0, 0};

// GPS data
float latitude = 0;
Expand All @@ -32,45 +34,61 @@ struct DARTDebugPayload {
float pressure = 0;
float temperature = 0;

// accelerometer data
Vector<float, 3> adxlAccel{};

uint8_t DAQTime = 0;


uint64_t timestamp = 0;

void toLineProtocol(char* output) const {
char timestamp_str[20];
int64String(timestamp).toCharArray(timestamp_str, sizeof timestamp_str);
sprintf(output, "DARTDebugPayload "
"mpuAX=%f,"
"mpuAY=%f,"
"mpuAZ=%f,"
"mpuGX=%f,"
"mpuGY=%f,"
"mpuGZ=%f,"
"imuAX=%f,"
"imuAY=%f,"
"imuAZ=%f,"
"imuGX=%f,"
"imuGY=%f,"
"imuGZ=%f,"
"imuMX=%f,"
"imuMY=%f,"
"imuMZ=%f,"
"lat=%f,"
"long=%f,"
"altGPS=%f,"
"SIV=%du,"
"fixType=%du,"
"SIV=%d,"
"fixType=%d,"
"pressure=%f,"
"temp=%f,"
"DAQTime=%du,"
"adxlX=%f,"
"adxlY=%f,"
"adxlZ=%f",
mpuAccel[0], mpuAccel[1], mpuAccel[2],
mpuGyro[0], mpuGyro[1], mpuGyro[2],
latitude, longitude, altitude, satellitesInView, fixType,
pressure, temperature,
DAQTime,
adxlAccel[0], adxlAccel[1], adxlAccel[2]);
"DAQTime=%d,"
"h=%f"
" %s",
imuAccel[0], imuAccel[1], imuAccel[2],
imuGyro[0], imuGyro[1], imuGyro[2],
imuMag[0], imuMag[1], imuMag[2],
latitude, longitude, altitude, satellitesInView, fixType,
pressure, temperature,
DAQTime, getAltitude(), timestamp_str);
}

void toCSVformat(char* output) const {
char timestamp_str[20];
int64String(timestamp).toCharArray(timestamp_str, sizeof timestamp_str);
sprintf(output, "DARTDebugPayload,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%d,%d,%f,%f,%d,%f,%s",
imuAccel[0], imuAccel[1], imuAccel[2],
imuGyro[0], imuGyro[1], imuGyro[2],
imuMag[0], imuMag[1], imuMag[2],
latitude, longitude, altitude, satellitesInView, fixType,
pressure, temperature,
DAQTime, getAltitude(), timestamp_str);
}

DARTDebugPayload(IMU *imu, GPS *gps, Barometer *barometer, Accelerometer *accelerometer) {
DARTDebugPayload(IMU *imu, GPS *gps, Barometer *barometer) {
type = PayloadType::DARTDebugPayload_t;

// 6dof IMU data
mpuAccel = imu->getAcceleration();
mpuGyro = imu->getGyroVector();
imuAccel = imu->getAcceleration();
imuGyro = imu->getGyroVector();
imuMag = imu->getMagnetometerVector();

// GPS data
latitude = gps->getLatitude();
Expand All @@ -82,8 +100,12 @@ struct DARTDebugPayload {
// barometer data
pressure = barometer->getPressure();
temperature = barometer->getTemperature();
}

adxlAccel = accelerometer->getAcceleration();
float getAltitude() const {
if (pressure == 0) return -1;
double p = 1013.25/(pressure/100);
return (float) (153.84615*(pow(p,0.19) - 1)*(temperature+273.15));
}

DARTDebugPayload() = default;
Expand Down
6 changes: 4 additions & 2 deletions lib/downlink/payloads/Test_Payload.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

#include "downlink.h"
#include "LineProtocolBuilder.h"
#include "Payload.h"

struct Test_Payload {
downlink::PayloadType type = downlink::PayloadType::Test_Payload_Type;
class Test_Payload : public Payload {
public:
uint8_t x = 0;
uint8_t y = 0;
uint8_t z = 0;
Expand All @@ -27,6 +28,7 @@ struct Test_Payload {
}

Test_Payload(int16_t _x, int16_t _y, int16_t _z) {
type = PayloadType::Test_Payload_t;
x = _x;
y = _y;
z = _z;
Expand Down
16 changes: 13 additions & 3 deletions lib/sensor_hardware/Accelerometer_ADXL375.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
#include "Accelerometer_ADXL375.h"

int8_t Accelerometer_ADXL375::begin() {
Serial.println("Starting up ADXL375");
device->protocol_begin();
Serial.println("ADXL375 protocol_begin() called");

delay(10);

uint8_t deviceID = device->read_reg(0x00);
Serial.printf("ADXL375 device ID: %x\n", deviceID);

// device ID should equal 0xE5
if (deviceID != 0xE5) return 1;

// BW_RATE should equal 00001010
uint8_t bw_rate = device->read_reg(0x2C);
Serial.printf("ADXL375 BW_RATE: %x\n", bw_rate);
if (bw_rate != 0b00001010) return 6;

// put device in standby mode
if (device->write_reg(0x2D, 0b0000) != 0) return 5;

Expand Down Expand Up @@ -41,9 +51,9 @@ int8_t Accelerometer_ADXL375::readData() {


Vector<int16_t, 3> rawAccel = {
(int16_t) (buffer[1] << 8 | buffer[0]),
(int16_t) (buffer[3] << 8 | buffer[2]),
(int16_t) (buffer[5] << 8 | buffer[4])
(int16_t) ((uint16_t)buffer[1] << 8 | ((uint16_t)buffer[0])),
(int16_t) ((uint16_t)buffer[3] << 8 | (uint16_t)buffer[2]),
(int16_t) ((uint16_t)buffer[5] << 8 | (uint16_t)buffer[4])
};


Expand Down
4 changes: 4 additions & 0 deletions lib/sensor_hardware/Accelerometer_ADXL375.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Accelerometer_ADXL375 : public Accelerometer {
device = new I2CProtocol(address, pipe, freq);
};

Accelerometer_ADXL375(byte chipSelect, SPIClass& spi, uint32_t frequency) {
device = new SPIProtocol(chipSelect, spi, SPISettings(frequency, MSBFIRST, SPI_MODE3), 0x80 | 0x40, 0x80 | 0x40);
}

// SPI constructor to be added in future when needed
};

Expand Down
Loading

0 comments on commit c254958

Please sign in to comment.