mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-23 16:25:26 +03:00
[IMU] Decouple Mag/CoG; Prefer MAG if available, if not - use CoG
This commit is contained in:
parent
7685d04ca2
commit
a0e6c7e847
1 changed files with 8 additions and 15 deletions
|
@ -493,13 +493,15 @@ static void imuCalculateEstimatedAttitude(float dT)
|
|||
if (STATE(FIXED_WING)) {
|
||||
bool canUseCOG = isGPSHeadingValid();
|
||||
|
||||
if (canUseCOG) {
|
||||
// Prefer compass (if available)
|
||||
if (canUseMAG) {
|
||||
useMag = true;
|
||||
gpsHeadingInitialized = true; // GPS heading initialised from MAG, continue on GPS if compass fails
|
||||
}
|
||||
else if (canUseCOG) {
|
||||
if (gpsHeadingInitialized) {
|
||||
// Use GPS heading if error is acceptable or if it's the only source of heading
|
||||
if (ABS(gpsSol.groundCourse - attitude.values.yaw) < DEGREES_TO_DECIDEGREES(MAX_GPS_HEADING_ERROR_DEG) || !canUseMAG) {
|
||||
courseOverGround = DECIDEGREES_TO_RADIANS(gpsSol.groundCourse);
|
||||
useCOG = true;
|
||||
}
|
||||
courseOverGround = DECIDEGREES_TO_RADIANS(gpsSol.groundCourse);
|
||||
useCOG = true;
|
||||
}
|
||||
else {
|
||||
// Re-initialize quaternion from known Roll, Pitch and GPS heading
|
||||
|
@ -509,15 +511,6 @@ static void imuCalculateEstimatedAttitude(float dT)
|
|||
// Force reset of heading hold target
|
||||
resetHeadingHoldTarget(DECIDEGREES_TO_DEGREES(attitude.values.yaw));
|
||||
}
|
||||
|
||||
// If we can't use COG and there's MAG available - fallback
|
||||
if (!useCOG && canUseMAG) {
|
||||
useMag = true;
|
||||
}
|
||||
}
|
||||
else if (canUseMAG) {
|
||||
useMag = true;
|
||||
gpsHeadingInitialized = true; // GPS heading initialised from MAG, continue on GPS if possible
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue