diff --git a/MIDAS/platformio.ini b/MIDAS/platformio.ini index 96404051..a0113328 100644 --- a/MIDAS/platformio.ini +++ b/MIDAS/platformio.ini @@ -5,6 +5,7 @@ framework = arduino build_flags = -DARDUINO_USB_CDC_ON_BOOT=1 build_src_filter = +<*> - + +lib_deps = sparkfun/SparkFun LSM6DS3 Breakout@^1.0.3 [env:mcu_hilsim] platform = espressif32 diff --git a/MIDAS/src/errors.h b/MIDAS/src/errors.h index 5fe7309c..12b05a50 100644 --- a/MIDAS/src/errors.h +++ b/MIDAS/src/errors.h @@ -3,5 +3,6 @@ enum ErrorCode { NoError, - LowGCouldNotBeInitialized + LowGCouldNotBeInitialized, + GyroCouldNotBeInitialized }; \ No newline at end of file diff --git a/MIDAS/src/hardware/Gyroscope.cpp b/MIDAS/src/hardware/Gyroscope.cpp new file mode 100644 index 00000000..c385d7cc --- /dev/null +++ b/MIDAS/src/hardware/Gyroscope.cpp @@ -0,0 +1,24 @@ +#include "sensors.h" + +// #include sensor library +#include +// 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; +} \ No newline at end of file diff --git a/MIDAS/src/rocket_state.h b/MIDAS/src/rocket_state.h index 71a0aa5e..2708bbe6 100644 --- a/MIDAS/src/rocket_state.h +++ b/MIDAS/src/rocket_state.h @@ -38,6 +38,7 @@ struct RocketState { SensorState low_g; SensorState high_g; + SensorState gyroscope; SensorState barometer; SensorState continuity; SensorState voltage; diff --git a/MIDAS/src/sensor_data.h b/MIDAS/src/sensor_data.h index 7a1727df..c4570e1b 100644 --- a/MIDAS/src/sensor_data.h +++ b/MIDAS/src/sensor_data.h @@ -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; diff --git a/MIDAS/src/sensors.h b/MIDAS/src/sensors.h index 6fe5a450..bfb3eb1e 100644 --- a/MIDAS/src/sensors.h +++ b/MIDAS/src/sensors.h @@ -13,6 +13,11 @@ struct LowGSensor { LowGData read(); }; +struct Gyroscope { + ErrorCode init(); + GyroscopeData read(); +}; + struct HighGSensor { ErrorCode init(); HighGData read(); @@ -40,6 +45,7 @@ struct OrientationSensor { struct Sensors { LowGSensor low_g; + Gyroscope gyroscope; HighGSensor high_g; BarometerSensor barometer; ContinuitySensor continuity; diff --git a/MIDAS/src/systems.cpp b/MIDAS/src/systems.cpp index 7b632216..f61e2ffa 100644 --- a/MIDAS/src/systems.cpp +++ b/MIDAS/src/systems.cpp @@ -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); @@ -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); @@ -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);