mirror of
https://github.com/okalachev/flix.git
synced 2026-06-28 14:06:32 +00:00
Reduce angle drift by adding level correction to the estimator
Leverage a priori knowledge that the drone's average attitude is level. Explanation: https://t.me/opensourcequadcopter/158.
This commit is contained in:
@@ -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));
|
||||||
|
}
|
||||||
|
|||||||
@@ -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},
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user