Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
54ae7f0
feat: add OrientationEstimation class and gyro/mag triplet structs
Jshepherd06 Feb 22, 2026
be29df8
Change MadgwikAHRS to OrientationEstimator
Jshepherd06 Feb 24, 2026
5b2dbcc
feat: add data names for roll, pitch, yaw
Jshepherd06 Feb 24, 2026
1d45e02
Adjust OrientationEstimator for martha integration
Jshepherd06 Feb 24, 2026
5181626
Merge branch 'main' of https://github.com/CURocketEngineering/Avionic…
Jshepherd06 Feb 24, 2026
a541e7e
feat: update orientation estimator to use curtime
Jshepherd06 Feb 26, 2026
4a800a3
revamp ahrs status
Jshepherd06 Mar 24, 2026
8e08677
readd getEuler to update, fix getEuler
Jshepherd06 Mar 24, 2026
c4f50b0
correct euler angle calculation
Jshepherd06 Apr 2, 2026
e2be84f
Merge branch 'main' of https://github.com/CURocketEngineering/Avionic…
Jshepherd06 Apr 2, 2026
fb7d3ca
Only use accel and gyro data for ahrs when on pad
Jshepherd06 Apr 2, 2026
f0bccac
feat: implement launchDetected function in orientationEstimator
Jshepherd06 Apr 2, 2026
e6aad12
move orientation estimator tests to avionics
Jshepherd06 Apr 3, 2026
e339a8a
fix: cast double->float operations in orientationEstimator
Jshepherd06 Apr 9, 2026
0de1042
Merge branch 'ahrs' of https://github.com/CURocketEngineering/Avionic…
Jshepherd06 Apr 9, 2026
236c447
feat: add orientation estimator test
Jshepherd06 Apr 9, 2026
b5002d6
update orientation estimator test
Jshepherd06 Apr 9, 2026
f3428de
feat: add check for output file in orientation estimator test
Jshepherd06 Apr 9, 2026
f5ce959
fix: remove unused variables in orientation estimator test
Jshepherd06 Apr 9, 2026
63338bb
some clang tidy checks
Jshepherd06 Apr 9, 2026
e48fe74
Merge branch 'main' of https://github.com/CURocketEngineering/Avionic…
Jshepherd06 Apr 9, 2026
1333b60
reduce magic number use in orientation estimator
Jshepherd06 Apr 9, 2026
64b235b
remove all magic numbers from orientation estimator
Jshepherd06 Apr 9, 2026
1a35098
More readibility improvements to orientation estimator
Jshepherd06 Apr 9, 2026
56b0f9b
fix: seperate variable declarations in orientation estimator
Jshepherd06 Apr 9, 2026
e0b928f
feat: add docstrings to orientation estimator update funcitons
Jshepherd06 Apr 9, 2026
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
3 changes: 3 additions & 0 deletions include/data_handling/DataNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#define EST_VERTICAL_VELOCITY 18
#define EST_ALTITUDE 19
#define TIME_TO_APOGEE 22
#define ROLL 25
#define PITCH 26
#define YAW 27

// Power
#define BATTERY_VOLTAGE 20
Expand Down
83 changes: 83 additions & 0 deletions include/state_estimation/OrientationEstimator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#ifndef ORIENTATION_ESTIMATOR_H
#define ORIENTATION_ESTIMATOR_H

#include "data_handling/DataPoint.h"
#include "state_estimation/StateEstimationTypes.h"
#include "state_estimation/States.h"

/**
* @brief Orientation estimator using Madgwick's algorithm for sensor fusion.
*
* This class estimates the orientation of the rocket in 3D space using data from the accelerometer,
* gyroscope, and magnetometer. When not in flight, it uses the full AHRS algorithm to fuse all three sensors.
* Once launch is detected, it relies on gyro data only for orientation updates to avoid accelerometer and magnetometer
* disturbances during flight.
*/
class OrientationEstimator {
public:
OrientationEstimator(float gainPad = 0.05f, float gainFlight = 0.005f)
: q0(1.0f), q1(0.0f), q2(0.0f), q3(0.0f),
betaPad(gainPad), betaFlight(gainFlight),
roll(0.0f), pitch(0.0f), yaw(0.0f), hasLaunched(false), lastUpdateTime(0) {}

/**
* @brief Update the orientation estimator with new sensor data.
* This method should be called whenever new accelerometer, gyroscope, or magnetometer data is available.
* Calls updateFullAHRS or updateIMU when on pad, directly updates orientation estimate
* from gyro data only when in flight.
* @param accel Acceleration triplet (x, y, z) in m/s^2
* @param gyro Gyroscope triplet (x, y, z) in degrees/s
* @param mag Magnetometer triplet (x, y, z) in microteslas
* @param currentTime Current timestamp in milliseconds
*/
void update(AccelerationTriplet accel, GyroTriplet gyro, MagTriplet mag, uint32_t currentTime);

Quaternion getQuaternion() const{
Quaternion q = {q0, q1, q2, q3};
return q;
}
void launchDetected() { hasLaunched = true;}
float getRoll() const { return roll; }
float getPitch() const { return pitch; }
float getYaw() const { return yaw; }

private:
float q0, q1, q2, q3; // quaternion
float betaPad;
float betaFlight;
float beta; // determines how much the algorithm relies on the accelerometer vs the gyroscope. Higher beta means more reliance on accel.
float roll, pitch, yaw; // Euler angles in degrees
bool hasLaunched;
uint32_t lastUpdateTime; // timestamp of the last update in milliseconds

/**
* @brief Update the orientation estimate using the full AHRS algorithm (gyro + accel + mag).
* This function should never be called directly. Call update() instead, which will route to
* this or the IMU-only update as appropriate.
* @param accel Acceleration triplet (x, y, z) in m/s^2
* @param gyro Gyroscope triplet (x, y, z) in degrees/s
* @param mag Magnetometer triplet (x, y, z) in microteslas
* @param currentTime Current timestamp in milliseconds
*/
void updateFullAHRS(AccelerationTriplet accel, GyroTriplet gyro, MagTriplet mag, uint32_t currentTime);

/**
* @brief Update the orientation estimator using only the IMU (gyro + optional accel).
* This is used when magnetometer data is invalid. Never call directly - call update() instead.
* @param accel Acceleration triplet (x, y, z) in m/s^2
* @param gyro Gyroscope triplet (x, y, z) in degrees/s
* @param mag Magnetometer triplet (x, y, z) in microteslas
* @param currentTime Current timestamp in milliseconds
*/
void updateIMU(AccelerationTriplet accel, GyroTriplet gyro, uint32_t currentTime);

/*
* @brief Compute Euler angles (roll, pitch, yaw) from the current quaternion estimate.
* This is called every update to keep the Euler angles in sync with the quaternion.
* The Euler angles are in degrees and follow the aerospace convention (roll around x-axis, pitch around y-axis, yaw around z-axis).
*/
void getEuler();
};


#endif
19 changes: 19 additions & 0 deletions include/state_estimation/StateEstimationTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,23 @@ struct AccelerationTriplet {
DataPoint z;
};

struct GyroTriplet {
DataPoint x;
DataPoint y;
DataPoint z;
};

struct MagTriplet {
DataPoint x;
DataPoint y;
DataPoint z;
};

struct alignas(16) Quaternion {
float w;
float x;
float y;
float z;
};

#endif // STATE_ESTIMATION_TYPES_H
Loading
Loading