-
Notifications
You must be signed in to change notification settings - Fork 1
On-board Ahrs (orientation estimator) #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 be29df8
Change MadgwikAHRS to OrientationEstimator
Jshepherd06 5b2dbcc
feat: add data names for roll, pitch, yaw
Jshepherd06 1d45e02
Adjust OrientationEstimator for martha integration
Jshepherd06 5181626
Merge branch 'main' of https://github.com/CURocketEngineering/Avionic…
Jshepherd06 a541e7e
feat: update orientation estimator to use curtime
Jshepherd06 4a800a3
revamp ahrs status
Jshepherd06 8e08677
readd getEuler to update, fix getEuler
Jshepherd06 c4f50b0
correct euler angle calculation
Jshepherd06 e2be84f
Merge branch 'main' of https://github.com/CURocketEngineering/Avionic…
Jshepherd06 fb7d3ca
Only use accel and gyro data for ahrs when on pad
Jshepherd06 f0bccac
feat: implement launchDetected function in orientationEstimator
Jshepherd06 e6aad12
move orientation estimator tests to avionics
Jshepherd06 e339a8a
fix: cast double->float operations in orientationEstimator
Jshepherd06 0de1042
Merge branch 'ahrs' of https://github.com/CURocketEngineering/Avionic…
Jshepherd06 236c447
feat: add orientation estimator test
Jshepherd06 b5002d6
update orientation estimator test
Jshepherd06 f3428de
feat: add check for output file in orientation estimator test
Jshepherd06 f5ce959
fix: remove unused variables in orientation estimator test
Jshepherd06 63338bb
some clang tidy checks
Jshepherd06 e48fe74
Merge branch 'main' of https://github.com/CURocketEngineering/Avionic…
Jshepherd06 1333b60
reduce magic number use in orientation estimator
Jshepherd06 64b235b
remove all magic numbers from orientation estimator
Jshepherd06 1a35098
More readibility improvements to orientation estimator
Jshepherd06 56b0f9b
fix: seperate variable declarations in orientation estimator
Jshepherd06 e0b928f
feat: add docstrings to orientation estimator update funcitons
Jshepherd06 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.