Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sensor Reformatting #5

Merged
merged 3 commits into from
Jan 19, 2024
Merged
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(SOURCES
src/core/fsw.cpp
src/core/flight_mode.cpp
src/core/state.cpp
src/core/modules.cpp
src/rfm/rfm.cpp
src/sd/sd.cpp
src/sd/hw_config.c
Expand Down
2 changes: 1 addition & 1 deletion lib/BNO055-Pico
2 changes: 1 addition & 1 deletion lib/LIS3DH-Pico
2 changes: 1 addition & 1 deletion lib/Si7021-Pico
58 changes: 29 additions & 29 deletions src/core/flight_mode.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
#include "flight_mode.hpp"
#include "../constants.hpp"
#include "../pins.hpp"
#include "../sd/sd.hpp"
#include "hardware/gpio.h"
#include "modules.hpp"
#include "state.hpp"

void FlightMode::execute() {
float x, y, z;
double x, y, z;

state::altimeter::altimeter.read_altitude(&state::altimeter::altitude, constants::altimeter::ref_pressure);
state::altimeter::altimeter.read_pressure(&state::altimeter::pressure);
modules::altimeter.read_altitude(&state::altimeter::altitude, constants::altimeter::ref_pressure);
modules::altimeter.read_pressure(&state::altimeter::pressure);

state::imu::imu.read_gyro(&x, &y, &z);
modules::imu.read_gyro(&x, &y, &z);
state::imu::gyro_x = x;
state::imu::gyro_y = y;
state::imu::gyro_z = z;

state::imu::imu.read_mag(&x, &y, &z);
modules::imu.read_mag(&x, &y, &z);
state::imu::mag_x = x;
state::imu::mag_y = y;
state::imu::mag_z = z;

state::accel::accel.read_accel(&x, &y, &z);
modules::accel.read_accel(&x, &y, &z);
state::accel::accel_x = x;
state::accel::accel_y = y;
state::accel::accel_z = z;

state::therm::temp = state::therm::therm.read_temperature();
state::therm::humidity = state::therm::therm.read_humidity();
modules::therm.read_temperature(&state::therm::temp);
modules::therm.read_humidity(&state::therm::humidity);

if (!state::flight::altitude_armed && state::altimeter::altitude > constants::flight::arming_altitude) {
state::flight::altitude_armed = true;
// TODO: Log event
}

state::sd::sd.log();
state::rfm::rfm.transmit();
// modules::sd.log();
// modules::rfm.transmit();
}

// Startup Mode
Expand All @@ -47,47 +47,47 @@ void StartupMode::execute() {
// TODO: Log event
}
if (!state::altimeter::init) {
if (state::altimeter::altimeter.begin()) {
if (modules::altimeter.begin()) {
state::altimeter::init = true;
} else {
// TODO: Log failure
}
}
if (!state::imu::init) {
if (state::imu::imu.begin()) {
if (modules::imu.begin()) {
state::imu::init = true;
} else {
// TODO: Log failure
}
}
if (!state::accel::init) {
if (state::accel::accel.begin()) {
if (modules::accel.begin()) {
state::accel::init = true;
} else {
// TODO: Log failure
}
}
if (!state::therm::init) {
if (state::therm::therm.begin()) {
if (modules::therm.begin()) {
state::therm::init = true;
} else {
// TODO: Log failure
}
}
if (!state::sd::init) {
if (state::sd::sd.begin()) {
state::sd::init = true;
} else {
// TODO: Log failure
}
}
if (!state::rfm::init) {
if (state::rfm::rfm.begin()) {
state::rfm::init = true;
} else {
// TODO: Log failure
}
}
// if (!state::sd::init) {
// if (modules::sd.begin()) {
// state::sd::init = true;
// } else {
// // TODO: Log failure
// }
// }
// if (!state::rfm::init) {
// if (modules::rfm.begin()) {
// state::rfm::init = true;
// } else {
// // TODO: Log failure
// }
// }
}

void StartupMode::transition() {
Expand Down
6 changes: 3 additions & 3 deletions src/core/flight_mode.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef FLIGHT_MODE_
#define FLIGHT_MODE_
#ifndef FLIGHT_MODE_HPP_
#define FLIGHT_MODE_HPP_

#include <string>

Expand Down Expand Up @@ -63,4 +63,4 @@ class MainDeployedMode : public FlightMode {
std::string name() { return "Main Deployed"; };
};

#endif // FLIGHT_MODE_
#endif // FLIGHT_MODE_HPP_
11 changes: 11 additions & 0 deletions src/core/modules.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "modules.hpp"

namespace modules {
BMP388 altimeter(I2C_PORT);
BNO055 imu(I2C_PORT);
LIS3DH accel(I2C_PORT);
Si7021 therm(I2C_PORT);

SD sd;
RFM rfm;
}; // namespace modules
22 changes: 22 additions & 0 deletions src/core/modules.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef MODULES_HPP_
#define MODULES_HPP_

#include "bmp388.hpp"
#include "bno055.hpp"
#include "lis3dh.hpp"
#include "si7021.hpp"

#include "../rfm/rfm.hpp"
#include "../sd/sd.hpp"

namespace modules {
extern BMP388 altimeter;
extern BNO055 imu;
extern LIS3DH accel;
extern Si7021 therm;

extern SD sd;
extern RFM rfm;
}; // namespace modules

#endif
28 changes: 11 additions & 17 deletions src/core/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace state {
double pressure = -1;
double altitude = -1;

BMP388 altimeter(I2C_PORT);
} // namespace altimeter
namespace gps {
bool init = false;
Expand All @@ -44,39 +43,34 @@ namespace state {
} // namespace gps
namespace imu {
bool init = false;
float mag_x = -1;
float mag_y = -1;
float mag_z = -1;
float gyro_x = -1;
float gyro_y = -1;
float gyro_z = -1;
double mag_x = -1;
double mag_y = -1;
double mag_z = -1;
double gyro_x = -1;
double gyro_y = -1;
double gyro_z = -1;

BNO055 imu(I2C_PORT);
} // namespace imu
namespace accel {
bool init = false;
float accel_x = -1;
float accel_y = -1;
float accel_z = -1;
double accel_x = -1;
double accel_y = -1;
double accel_z = -1;

LIS3DH accel(I2C_PORT);
} // namespace accel
namespace therm {
bool init = false;
float temp = -1;
float humidity = -1;
double temp = -1;
double humidity = -1;

Si7021 therm(I2C_PORT);
} // namespace therm
namespace sd {
bool init = false;
FIL file;

SD sd;
} // namespace sd
namespace rfm {
bool init = false;

RFM rfm;
} // namespace rfm
}; // namespace state
34 changes: 11 additions & 23 deletions src/core/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
#include "flight_mode.hpp"
#include <stdint.h>

#include "bmp388.hpp"
#include "bno055.hpp"
#include "lis3dh.hpp"
#include "si7021.hpp"

#include "../rfm/rfm.hpp"
#include "../sd/sd.hpp"

namespace state {
Expand Down Expand Up @@ -40,7 +34,6 @@ namespace state {
extern double pressure;
extern double altitude;

extern BMP388 altimeter;
} // namespace altimeter
namespace gps {
extern bool init;
Expand All @@ -51,39 +44,34 @@ namespace state {
} // namespace gps
namespace imu {
extern bool init;
extern float mag_x;
extern float mag_y;
extern float mag_z;
extern float gyro_x;
extern float gyro_y;
extern float gyro_z;
extern double mag_x;
extern double mag_y;
extern double mag_z;
extern double gyro_x;
extern double gyro_y;
extern double gyro_z;

extern BNO055 imu;
} // namespace imu
namespace accel {
extern bool init;
extern float accel_x;
extern float accel_y;
extern float accel_z;
extern double accel_x;
extern double accel_y;
extern double accel_z;

extern LIS3DH accel;
} // namespace accel
namespace therm {
extern bool init;
extern float temp;
extern float humidity;
extern double temp;
extern double humidity;

extern Si7021 therm;
} // namespace therm
namespace sd {
extern bool init;

extern SD sd;
} // namespace sd
namespace rfm {
extern bool init;

extern RFM rfm;
} // namespace rfm
}; // namespace state

Expand Down