Skip to content

Commit

Permalink
[AV-1055] MIDAS Gyro / Backup LowG (#14)
Browse files Browse the repository at this point in the history
* implemented backup low g sensor

* renamed backuplowg to gyroscope

* changed thread sleep from 16 to 10

* "balls" - rbhog

* "sad emoji" - eisha
  • Loading branch information
eisha007 authored Oct 7, 2023
1 parent 825e153 commit 5a121e9
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions MIDAS/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ framework = arduino
build_flags =
-DARDUINO_USB_CDC_ON_BOOT=1
build_src_filter = +<*> -<silsim/> +<hardware/>
lib_deps = sparkfun/SparkFun LSM6DS3 Breakout@^1.0.3

[env:mcu_hilsim]
platform = espressif32
Expand Down
3 changes: 2 additions & 1 deletion MIDAS/src/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

enum ErrorCode {
NoError,
LowGCouldNotBeInitialized
LowGCouldNotBeInitialized,
GyroCouldNotBeInitialized
};
24 changes: 24 additions & 0 deletions MIDAS/src/hardware/Gyroscope.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "sensors.h"

// #include sensor library
#include <SparkFunLSM6DS3.h>
// global static instance of the sensor
LSM6DS3 LSM;

ErrorCode Gyroscope::init() {
// do whatever steps to initialize the sensor
// if it errors, return the relevant error code
if (!LSM.begin()) {
return ErrorCode::GyroCouldNotBeInitialized;
}
return ErrorCode::NoError;
}

GyroscopeData Gyroscope::read() {
// read from aforementioned global instance of sensor
GyroscopeData result;
result.gx = LSM.readFloatGyroX();
result.gy = LSM.readFloatGyroY(),
result.gz = LSM.readFloatGyroZ();
return result;
}
1 change: 1 addition & 0 deletions MIDAS/src/rocket_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct RocketState {

SensorState<LowGData> low_g;
SensorState<HighGData> high_g;
SensorState<GyroscopeData> gyroscope;
SensorState<Barometer> barometer;
SensorState<Continuity> continuity;
SensorState<Voltage> voltage;
Expand Down
6 changes: 6 additions & 0 deletions MIDAS/src/sensor_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ struct HighGData {
float gz = 0;
};

struct GyroscopeData {
float gx = 0;
float gy = 0;
float gz = 0;
};

struct Barometer {
float temperature = 0;
float pressure = 0;
Expand Down
6 changes: 6 additions & 0 deletions MIDAS/src/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ struct LowGSensor {
LowGData read();
};

struct Gyroscope {
ErrorCode init();
GyroscopeData read();
};

struct HighGSensor {
ErrorCode init();
HighGData read();
Expand Down Expand Up @@ -40,6 +45,7 @@ struct OrientationSensor {

struct Sensors {
LowGSensor low_g;
Gyroscope gyroscope;
HighGSensor high_g;
BarometerSensor barometer;
ContinuitySensor continuity;
Expand Down
11 changes: 11 additions & 0 deletions MIDAS/src/systems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ DECLARE_THREAD(low_g, RocketSystems* arg) {
vTaskDelete(NULL);
}

DECLARE_THREAD(gyroscope, RocketSystems* arg) {
while (true) {
THREAD_SLEEP(10);
// Serial.println("LOWG");
arg->rocket_state.gyroscope.update(arg->sensors.gyroscope.read());
}
vTaskDelete(NULL);
}

DECLARE_THREAD(high_g, RocketSystems* arg) {
while (true) {
THREAD_SLEEP(16);
Expand Down Expand Up @@ -111,6 +120,7 @@ bool init_sensors(Sensors& sensors) {
// todo message on failure
INIT_SENSOR(sensors.low_g);
INIT_SENSOR(sensors.high_g);
INIT_SENSOR(sensors.gyroscope);
INIT_SENSOR(sensors.barometer);
INIT_SENSOR(sensors.continuity);
INIT_SENSOR(sensors.orientation);
Expand All @@ -132,6 +142,7 @@ void begin_systems(RocketSystems& config) {
START_THREAD(data_logger, DATA_CORE, &config);
START_THREAD(barometer, SENSOR_CORE, &config);
START_THREAD(low_g, SENSOR_CORE, &config);
START_THREAD(gyroscope, SENSOR_CORE, &config);
START_THREAD(high_g, SENSOR_CORE, &config);
START_THREAD(orientation, SENSOR_CORE, &config);
START_THREAD(magnetometer, SENSOR_CORE, &config);
Expand Down

0 comments on commit 5a121e9

Please sign in to comment.