Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
OrientationEstimator.h
Go to the documentation of this file.
1#ifndef ORIENTATION_ESTIMATOR_H
2#define ORIENTATION_ESTIMATOR_H
3
7
17public:
18 OrientationEstimator(float gainPad = 0.05f, float gainFlight = 0.005f)
19 : q0(1.0f), q1(0.0f), q2(0.0f), q3(0.0f),
20 betaPad(gainPad), betaFlight(gainFlight),
21 roll(0.0f), pitch(0.0f), yaw(0.0f), hasLaunched(false), lastUpdateTime(0) {}
22
33 void update(AccelerationTriplet accel, GyroTriplet gyro, MagTriplet mag, uint32_t currentTime);
34
36 Quaternion q = {q0, q1, q2, q3};
37 return q;
38 }
39 void launchDetected() { hasLaunched = true;}
40 float getRoll() const { return roll; }
41 float getPitch() const { return pitch; }
42 float getYaw() const { return yaw; }
43
44private:
45 float q0, q1, q2, q3; // quaternion
46 float betaPad;
47 float betaFlight;
48 float beta; // determines how much the algorithm relies on the accelerometer vs the gyroscope. Higher beta means more reliance on accel.
49 float roll, pitch, yaw; // Euler angles in degrees
50 bool hasLaunched;
51 uint32_t lastUpdateTime; // timestamp of the last update in milliseconds
52
62 void updateFullAHRS(AccelerationTriplet accel, GyroTriplet gyro, MagTriplet mag, uint32_t currentTime);
63
72 void updateIMU(AccelerationTriplet accel, GyroTriplet gyro, uint32_t currentTime);
73
74 /*
75 * @brief Compute Euler angles (roll, pitch, yaw) from the current quaternion estimate.
76 * This is called every update to keep the Euler angles in sync with the quaternion.
77 * The Euler angles are in degrees and follow the aerospace convention (roll around x-axis, pitch around y-axis, yaw around z-axis).
78 */
79 void getEuler();
80};
81
82
83#endif
Quaternion getQuaternion() const
void update(AccelerationTriplet accel, GyroTriplet gyro, MagTriplet mag, uint32_t currentTime)
Update the orientation estimator with new sensor data. This method should be called whenever new acce...
OrientationEstimator(float gainPad=0.05f, float gainFlight=0.005f)