diff options
| author | Dawsyn Schraiber <[email protected]> | 2025-06-20 00:10:22 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-20 00:10:22 -0400 |
| commit | 5375c6d876f115a2bd75ec45796e5333ba928082 (patch) | |
| tree | 51d8701b6e0b10b3171c8a146304a3accf57d150 /include/ms5607.hpp | |
| parent | e07f105022f3ad6e3c6ee2dfe4cc01eb91c1f373 (diff) | |
| download | active-drag-system-5375c6d876f115a2bd75ec45796e5333ba928082.tar.gz active-drag-system-5375c6d876f115a2bd75ec45796e5333ba928082.tar.bz2 active-drag-system-5375c6d876f115a2bd75ec45796e5333ba928082.zip | |
# Dawsyn's Final Commit
This one is a little emotional as this is my final commit in this repository and as a member of Rocketry at Virginia Tech. This merges the changes seen in the branch known as 'big_kahuna' into main. This is the version of the ADS software as seen on [Roadkill](https://drive.google.com/file/d/120BvI-0ntliHo6i9UxcCn2pXAl-JsdP_/view?usp=drive_link) in the 2025 IREC competition. There are bound to be bugs, but I have found it useful to have the final competition version to be the one present on main at the end of every academic year. Hopefully this is useful to the next lead.
## Primary Changes
+ NEW I2C drivers to support sensors present on new ADS custom PCB
+ NEW logging library found in separate repository and pulled in as submodule ([pico-logger](https://github.com/rocketryvt/pico-logger))
+ No longer dependent on different flash chip from one used for code storage! Compile executable as RP2040 'copy-to-ram' type to increase flash read/write speeds!
+ NEW fixed-point libraries to allow for increased performance and sensor sampling speeds on RP2040 that lacks FPU
+ FreeRTOS Simultaneous Multi-processing (SMP) architecture for task handling and easier introduction / testing of new features
+ Serial monitor / command system with task performance monitoring commands
+ WORKING Kalman filter that takes altitude from barometer as measurement and z-axis acceleration from IMU as control to generate state vector containing filtered altitude and vertical velocity
+ NEW CFD equations from the Ben-ogrithm (to replace the Chen-ogrithm) that includes:
+ Apogee prediction model that takes current drag force, altitude, and vertical velocity
+ Current Drag Force equation based on current deployment and vertical velocity to use for Apogee Prediction model
+ Desired Drag force equation based on current altitude and vertical velocity to generate what drag force is needed to reach 10K ft
+ Deployment percentage equation based on current velocity and desired drag force to map to flap deployment percentage
Diffstat (limited to 'include/ms5607.hpp')
| -rw-r--r-- | include/ms5607.hpp | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/include/ms5607.hpp b/include/ms5607.hpp new file mode 100644 index 0000000..d1bdd76 --- /dev/null +++ b/include/ms5607.hpp @@ -0,0 +1,133 @@ +#pragma once + +#include <stdint.h> + +#include "hardware/gpio.h" +#include "pico/stdlib.h" +#include "hardware/i2c.h" + +#include "pico/time.h" + +#if ( USE_FREERTOS == 1 ) +#include "FreeRTOS.h" +#include "FreeRTOSConfig.h" +#include "portmacro.h" +#include "projdefs.h" +#include "task.h" +#include "semphr.h" +#endif + +#define MS5607_I2C_ADDRESS 0x77 + +#define PROM_MANUFACTURER_RESERVED_ADDR 0x0 +#define PROM_CALIBRATION_COEFFICENT_1_ADDR 0x1 +#define PROM_CALIBRATION_COEFFICENT_2_ADDR 0x2 +#define PROM_CALIBRATION_COEFFICENT_3_ADDR 0x3 +#define PROM_CALIBRATION_COEFFICENT_4_ADDR 0x4 +#define PROM_CALIBRATION_COEFFICENT_5_ADDR 0x5 +#define PROM_CALIBRATION_COEFFICENT_6_ADDR 0x6 +#define PROM_CRC_ADDR 0x7 + +#define OSR_CONVERT_256 0x0 +#define OSR_CONVERT_512 0x1 +#define OSR_CONVERT_1024 0x2 +#define OSR_CONVERT_2048 0x3 +#define OSR_CONVERT_4096 0x4 + +#define OSR_256_CONVERSION_TIME_US 600 + +#define TYPE_UNCOMPENSATED_PRESSURE 0 +#define TYPE_UNCOMPENSATED_TEMPERATURE 1 + +#define RESET_COMMAND 0x1E + +#define ADC_READ_COMMAND 0x0 + +#define ALTITUDE_SCALE_F 10.0f +#define PRESSURE_SCALE_F 100.0f +#define TEMPERATURE_SCALE_F 100.0f + +#define ALTITUDE_SCALE 10 +#define PRESSURE_SCALE 100 +#define TEMPERATURE_SCALE 100 + +#define MS5607_SAMPLE_RATE_HZ 500 + +typedef union { + struct { + uint8_t RESERVED: 1; + uint8_t ADDR_OSR: 3; + uint8_t TYPE :1; + bool PROM2 :1; + bool CONVERT :1; + bool PROM: 1; + } fields; + uint8_t data; +} ms5607_cmd; + +typedef enum { + NOT_SAMPLING, + PRESSURE_CONVERT, + TEMPERATURE_CONVERT, + COMPENSATE +} sample_state_t; + +class MS5607 { + public: + MS5607(i2c_inst_t* i2c) : i2c {i2c} {}; + + void initialize(); + + void ms5607_write_cmd(ms5607_cmd* cmd); + + void ms5607_start_sample(); + + void ms5607_sample(); + + static int64_t ms5607_sample_callback(alarm_id_t id, void* user_data); +#if (USE_FREERTOS == 1) + static void ms5607_sample_handler(void* pvParameters); + static void update_ms5607_task(void* pvParameters); +#endif + + int32_t pressure_to_altitude(int32_t pressure); + + int32_t get_pressure() { return pressure; } + int32_t get_temperature() { return temperature; } + int32_t get_altitude() { return altitude; } + + void set_threshold_altitude(int32_t threshold_altitude, alarm_callback_t callback); + + void clear_threshold_altitude(); + +#if ( USE_FREERTOS == 1 ) + TaskHandle_t sample_handler_task_handle = NULL; + TaskHandle_t update_task_handle = NULL; +#endif + private: + void ms5607_compensate(); + + uint8_t buffer[3]; + + uint16_t prom[6]; + + uint32_t uncompensated_pressure; + uint32_t uncompensated_temperature; + + int32_t pressure; + + int32_t temperature; + + int32_t altitude; + + sample_state_t sample_state; + + int32_t threshold_altitude; + + alarm_callback_t threshold_callback = NULL; + + bool positive_crossing; + + i2c_inst_t* i2c; + const uint8_t addr = MS5607_I2C_ADDRESS; +}; |
