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 /src/altimeter.cpp | |
| 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 'src/altimeter.cpp')
| -rw-r--r-- | src/altimeter.cpp | 145 |
1 files changed, 0 insertions, 145 deletions
diff --git a/src/altimeter.cpp b/src/altimeter.cpp deleted file mode 100644 index 9c47ceb..0000000 --- a/src/altimeter.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include "altimeter.hpp" -#include "hardware/gpio.h" - -altimeter::altimeter(i2c_inst_t* inst, uint8_t addr) { - this->inst = inst; - this->addr = addr; -} - -void altimeter::initialize() { - // Select control register(0x26) - // Active mode, OSR = 16, altimeter mode(0xB8) - this->buffer[0] = 0x26; - this->buffer[1] = 0x89; - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); -} - -void altimeter::initialize(float threshold_altitude, uint8_t interrupt_pin, gpio_irq_callback_t callback) { - this->initialize(); - - // Below configures the interrupt for the first transition from PAD to BOOST - // Initial Reading - - sleep_ms(1000); - - float altitude = 0.0f; - - while (altitude == 0.0f) { - altitude = this->get_altitude_converted(); - } - - threshold_altitude += altitude; // 30 meters above ground - - // Select control register 3 (0x28) - // Set bot interrupt pins to active low and enable internal pullups - this->buffer[0] = 0x28; - this->buffer[1] = 0x01; - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); - - // Select pressure target MSB register(0x16) - // Set altitude target to 30 meters above ground altitude - this->buffer[0] = 0x16; - this->buffer[1] = (uint8_t) (((int16_t)(threshold_altitude)) >> 8); - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); - - // Select pressure target LSB register(0x17) - // Set altitude target to 30 meters above ground altitude - this->buffer[0] = 0x17; - this->buffer[1] = (uint8_t) (((int16_t)(threshold_altitude))); - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); - - // Select interrupt enable register (0x29) - // Set interrupt enabled for altitude threshold(0x08) - this->buffer[0] = 0x29; - this->buffer[1] = 0x08; - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); - - // Select interrupt this->bufferuration register (0x2A) - // Set interrupt enabled for altitude threshold to route to INT1 pin(0x08) - this->buffer[0] = 0x2A; - this->buffer[1] = 0x08; - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); - - gpio_set_irq_enabled_with_callback(interrupt_pin, GPIO_IRQ_LEVEL_LOW, true, callback); - // End of configuration of interrupt for first transition from PAD to BOOST -} - -void altimeter::set_threshold_altitude(float threshold_altitude, uint8_t interrupt_pin, gpio_irq_callback_t callback) { - float altitude = 0.0f; - - while (altitude == 0.0f) { - altitude = get_altitude_converted(); - } - - threshold_altitude += altitude; - - // Select control register 3 (0x28) - // Set bot interrupt pins to active low and enable internal pullups - this->buffer[0] = 0x28; - this->buffer[1] = 0x01; - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); - - // Select pressure target MSB register(0x16) - // Set altitude target to 30 meters above ground altitude - this->buffer[0] = 0x16; - this->buffer[1] = (uint8_t) (((int16_t)(threshold_altitude)) >> 8); - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); - - // Select pressure target LSB register(0x17) - // Set altitude target to provided threshold altitude - this->buffer[0] = 0x17; - this->buffer[1] = (uint8_t) (((int16_t)(threshold_altitude))); - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); - - // Select interrupt enable register (0x29) - // Set interrupt enabled for altitude threshold(0x08) - this->buffer[0] = 0x29; - this->buffer[1] = 0x08; - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); - - // Select interrupt this->bufferuration register (0x2A) - // Set interrupt enabled for altitude threshold to route to INT1 pin(0x08) - this->buffer[0] = 0x2A; - this->buffer[1] = 0x08; - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); - - gpio_set_irq_enabled_with_callback(interrupt_pin, GPIO_IRQ_LEVEL_LOW, true, callback); - // End of configuration of interrupt for first transition from PAD to BOOST -} - -void altimeter::unset_threshold_altitude(uint8_t interrupt_pin) { - gpio_set_irq_enabled_with_callback(interrupt_pin, GPIO_IRQ_LEVEL_LOW, false, NULL); - - // Select interrupt enable register (0x29) - // Set interrupt enabled for altitude threshold(0x08) - this->buffer[0] = 0x29; - this->buffer[1] = 0x00; - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); - - // Select interrupt configuration register (0x2A) - // Set interrupt enabled for altitude threshold to route to INT1 pin(0x08) - this->buffer[0] = 0x2A; - this->buffer[1] = 0x00; - i2c_write_blocking(this->inst, this->addr, this->buffer, 2, true); -} - -float altimeter::get_altitude_converted() { - uint8_t reg = 0x01; - i2c_write_blocking(this->inst, this->addr, ®, 1, true); - i2c_read_blocking(this->inst, this->addr, this->altitude_buffer, 4, false); - // Exactly how MPL3115A2 datasheet says to retrieve altitude - float altitude = (float) ((int16_t) ((this->altitude_buffer[0] << 8) | this->altitude_buffer[1])) + (float) (this->altitude_buffer[2] >> 4) * 0.0625; - return altitude; -} - -void altimeter::get_altitude_raw(uint8_t* buffer) { - uint8_t reg = 0x01; - i2c_write_blocking(this->inst, this->addr, ®, 1, true); - i2c_read_blocking(this->inst, this->addr, buffer, 3, false); -} - -uint32_t altimeter::expose_buffer(uint8_t** buffer) { - *buffer = this->altitude_buffer; - return sizeof(this->altitude_buffer); -} - |
