Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions include/config.h → include/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@

#include "ArduinoHAL.h"

#include "telemetry.h"
#include "servointerface.h"
#include "state_estimation/ApogeePredictor.h"
#include "state_estimation/BurnoutStateMachine.h"
#include "data_handling/DataNames.h"
#include "data_handling/DataPoint.h"
#include "data_handling/DataSaverBigSD.h"

#define TEST_FIN_DEPLOYMENT 1 // for testing fins

// mission configuration variables
Expand Down
31 changes: 31 additions & 0 deletions include/common/globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "telemetry.h"
#include "servointerface.h"
#include "state_estimation/ApogeePredictor.h"
#include "state_estimation/BurnoutStateMachine.h"
#include "data_handling/DataNames.h"
#include "data_handling/DataPoint.h"
#include "data_handling/DataSaverBigSD.h"

VerticalVelocityEstimator* verticalVelocityEstimator;
LaunchPredictor *lp;
ApogeeDetector *ad;
ServoInterface ms24;

// these values when initialized are going to be pointing to null val - they're better definined in setup
BurnoutStateMachine* sm = nullptr;
ApogeePredictor* ap = nullptr; // 0.2 is the alpha for the EMA, 1.0 is the minimum climb velocity

DataSaverBigSD* dataSaver;
DataPoint aclX, aclY, aclZ, alt, temp, pres, gyroX, gyroY, gyroZ;

Telemetry telemetry;
TelemetryData telemData;

extern float servoAngle;
extern float targetServoAngle;
extern double baseAlt;
extern unsigned long previousTime;
extern bool sd_init;
extern uint32_t startCoastTime;
extern ServoInterface ms24;
extern float currAlt;
11 changes: 11 additions & 0 deletions include/core/CommunicationVerification.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "common/config.h"
#include "common/globals.h"

/***
* initally deploys fins to show that we are in the communicate verification function
* retracts fins before entering loop
* if fins deploy after that point, we have an error
*/
void commsVerification(bool sd_init);
7 changes: 7 additions & 0 deletions include/core/Setup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "common/config.h"
#include "common/globals.h"
#include "simulation/Serial_Sim.h"

void setup();
7 changes: 7 additions & 0 deletions include/core/TelemetryProcessing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "common/config.h"
#include "common/globals.h"
#include "simulation/Serial_Sim.h"

void updateTelem();
21 changes: 21 additions & 0 deletions src/CommunicationVerification.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "core/CommunicationVerification.h"

/***
* initally deploys fins to show that we are in the communicate verification function
* retracts fins before entering loop
* if fins deploy after that point, we have an error
*/
void commsVerification(bool sd_init) {
ms24.setAngle(MAX_DEPLOYMENT_ANGLE);
delay(COMMUNICATION_VERIFICATION_DELAY);
ms24.setAngle(MIN_DEPLOYMENT_ANGLE);
delay(COMMUNICATION_VERIFICATION_DELAY);

SensorsActivated sensorsActivated = telemetry.getSensorsActivated();
std::vector<bool> verifiables = {sensorsActivated.mag, sensorsActivated.bmp, sensorsActivated.imu, sd_init};
for (bool verifiable : verifiables) {
ms24.setAngle(verifiable ? MIN_DEPLOYMENT_ANGLE : MAX_DEPLOYMENT_ANGLE);
delay(COMMUNICATION_VERIFICATION_DELAY);
}
delay(COMMUNICATION_VERIFICATION_DELAY);
}
33 changes: 33 additions & 0 deletions src/Setup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "core/Setup.h"

void setup() {
Serial.begin(BAUD_RATE);
delay(SETUP_DELAY);

ms24.setup(SERVO_PIN, SERVO_RANGE, SERVO_LOWER_PULSE, SERVO_UPPER_PULSE);
telemetry.setupSensors();

// be wary, as we're putting data onto the heap with these new statements. may need to be reconfigured if we have to save space in the future
dataSaver = new DataSaverBigSD(SD_CHIP_SELECT);
verticalVelocityEstimator = new VerticalVelocityEstimator();
ad = new ApogeeDetector(1.0f);
lp = new LaunchPredictor(ACCEL_THRESHOLD_MS2, LAUNCH_WINDOW_SIZE_MS, LAUNCH_WINDOW_INTERVAL_MS);
sm = new BurnoutStateMachine(dataSaver, lp, ad, verticalVelocityEstimator);
ap = new ApogeePredictor(*verticalVelocityEstimator, EMA_ALPHA, MINIMUM_CLIMB_VELOCITY);


sd_init = dataSaver->begin(); // super super important for comms verification


pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
previousTime = millis();
targetServoAngle = MIN_DEPLOYMENT_ANGLE;
startCoastTime = 0;

#ifdef SIM
SerialSim::getInstance().begin(&Serial, sm);
#endif

delay(SETUP_DELAY); // wait for setup to finish
}
48 changes: 48 additions & 0 deletions src/TelemetryProcessing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "core/TelemetryProcessing.h"

void updateTelem()
{
#ifdef SIM
SerialSim::getInstance().update();
delay(10);
#endif

// init telem & telem sensor recording
telemData = telemetry.getTelemetry();

// if you ever change the orientation of the sensors, this WILL probably need to be adjusted
telemData.sensorData["magnetometer"].magnetic.x = telemData.sensorData["magnetometer"].magnetic.y * -1;
telemData.sensorData["magnetometer"].magnetic.y = telemData.sensorData["magnetometer"].magnetic.x;

currAlt = telemData.sensorData["altitude"].altitude; // will be used later so store

// update data points
aclX.data = telemData.sensorData["acceleration"].acceleration.x;
aclY.data = telemData.sensorData["acceleration"].acceleration.y;
aclZ.data = telemData.sensorData["acceleration"].acceleration.z;
alt.data = currAlt;

gyroX.data = telemData.sensorData["gyro"].gyro.x;
gyroY.data = telemData.sensorData["gyro"].gyro.y;
gyroZ.data = telemData.sensorData["gyro"].gyro.z;
temp.data = telemData.sensorData["temperature"].temperature;
pres.data = telemData.sensorData["pressure"].pressure;

// give everything the same timestamp for eventual byte5 integration
unsigned long currTime = millis();
aclX.timestamp_ms = aclY.timestamp_ms = aclZ.timestamp_ms = alt.timestamp_ms = currTime;
gyroX.timestamp_ms = gyroY.timestamp_ms = gyroZ.timestamp_ms = currTime;
temp.timestamp_ms = currTime;
pres.timestamp_ms = currTime;

// save the data points to their respective data names
dataSaver->saveDataPoint(aclX, ACCELEROMETER_X);
dataSaver->saveDataPoint(aclY, ACCELEROMETER_Y);
dataSaver->saveDataPoint(aclZ, ACCELEROMETER_Z);
dataSaver->saveDataPoint(alt, ALTITUDE);
dataSaver->saveDataPoint(temp, TEMPERATURE);
dataSaver->saveDataPoint(pres, PRESSURE);
dataSaver->saveDataPoint(gyroX, GYROSCOPE_X);
dataSaver->saveDataPoint(gyroY, GYROSCOPE_Y);
dataSaver->saveDataPoint(gyroZ, GYROSCOPE_Z);
}
Loading