Reduce angle drift adding level correction to the estimator

Utilize a-priori knowledge that the overall average attitude of the flying drone is level.
This commit is contained in:
Oleg Kalachev
2026-05-04 16:48:20 +03:00
parent dbf24ea611
commit 26b639dfbc
3 changed files with 13 additions and 0 deletions
+11
View File
@@ -13,11 +13,13 @@ Quaternion attitude; // estimated attitude
bool landed; bool landed;
float accWeight = 0.003; float accWeight = 0.003;
float levelWeight = 0.0002;
LowPassFilter<Vector> ratesFilter(0.2); // cutoff frequency ~ 40 Hz LowPassFilter<Vector> ratesFilter(0.2); // cutoff frequency ~ 40 Hz
void estimate() { void estimate() {
applyGyro(); applyGyro();
applyAcc(); applyAcc();
applyLevel();
} }
void applyGyro() { void applyGyro() {
@@ -42,3 +44,12 @@ void applyAcc() {
// apply correction // apply correction
attitude = Quaternion::rotate(attitude, Quaternion::fromRotationVector(correction)); attitude = Quaternion::rotate(attitude, Quaternion::fromRotationVector(correction));
} }
void applyLevel() {
if (landed) return;
// assume the pilot keeps the drone more or less level in flight
Vector up = Quaternion::rotateVector(Vector(0, 0, 1), attitude);
Vector correction = Vector::rotationVectorBetween(Vector(0, 0, 1), up) * levelWeight;
attitude = Quaternion::rotate(attitude, Quaternion::fromRotationVector(correction));
}
+1
View File
@@ -73,6 +73,7 @@ Parameter parameters[] = {
{"IMU_GYRO_BIAS_A", &gyroBiasFilter.alpha}, {"IMU_GYRO_BIAS_A", &gyroBiasFilter.alpha},
// estimate // estimate
{"EST_ACC_WEIGHT", &accWeight}, {"EST_ACC_WEIGHT", &accWeight},
{"EST_LVL_WEIGHT", &levelWeight},
{"EST_RATES_LPF_A", &ratesFilter.alpha}, {"EST_RATES_LPF_A", &ratesFilter.alpha},
// motors // motors
{"MOT_PIN_FL", &motorPins[MOTOR_FRONT_LEFT], setupMotors}, {"MOT_PIN_FL", &motorPins[MOTOR_FRONT_LEFT], setupMotors},
+1
View File
@@ -27,6 +27,7 @@ void step();
void computeLoopRate(); void computeLoopRate();
void applyGyro(); void applyGyro();
void applyAcc(); void applyAcc();
void applyLevel();
void control(); void control();
void interpretControls(); void interpretControls();
void controlAttitude(); void controlAttitude();