Skip to content
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

EKF: Miscellaneous yaw estimator improvements #14191

Merged
merged 21 commits into from Jul 7, 2020

Conversation

priseborough
Copy link
Contributor

@priseborough priseborough commented Apr 24, 2020

Fixes the one frame delay in processing velocity measurements.
Updates EKF2_MAG_CAL param description to remove ambiguity when flying without compass use.
Eliminates unnecessary reset operations and state variables and uses more descriptive reset function name and description.
Reduces post takeoff EKF-GSF yaw drift due to large yaw gyro bias.
Fixes #14654

Result from SITL test to verify yaw estimator operation with second reset induced by land, disarm, arm and takeoff again.

Yaw estimates:
Screen Shot 2020-04-25 at 10 19 17 am

Weights:
Screen Shot 2020-04-25 at 10 20 15 am

Velocity innovations:
Screen Shot 2020-04-25 at 10 21 17 am
Screen Shot 2020-04-25 at 10 21 55 am

Also

@priseborough
Copy link
Contributor Author

priseborough commented Apr 25, 2020

There is work required to harmonise the AP_Compass and AP_Declination libraries to prevent a situation where they are returning inconsistent information if COMPASS_AUTODEC = 0, but I will tackle that in a separate PR. This was highlighted when trying to achieve flyaway testing by manually setting COMPASS_DEC.

Edit: Fix submitted here #14196

@priseborough
Copy link
Contributor Author

A couple of quick flight tests using EKF3 and EK3_MAG_CAL = 7.

Screen Shot 2020-04-25 at 1 58 23 pm

Screen Shot 2020-04-25 at 1 58 55 pm

This PR does not address the issue with getting preflight checks to pass when the magnetometer is disabled and EKF2 is being used.

@rmackay9
Copy link
Contributor

we discussed briefly on the call but will review over the next week or so.

@@ -245,7 +245,7 @@ const AP_Param::GroupInfo NavEKF2::var_info[] = {

// @Param: MAG_CAL
// @DisplayName: Magnetometer default fusion mode
// @Description: This determines when the filter will use the 3-axis magnetometer fusion model that estimates both earth and body fixed magnetic field states, when it will use a simpler magnetic heading fusion model that does not use magnetic field states and when it will use an alternative method of yaw determination to the magnetometer. The 3-axis magnetometer fusion is only suitable for use when the external magnetic field environment is stable. EK3_MAG_CAL = 0 uses heading fusion on ground, 3-axis fusion in-flight, and is the default setting for Plane users. EK3_MAG_CAL = 1 uses 3-axis fusion only when manoeuvring. EK3_MAG_CAL = 2 uses heading fusion at all times, is recommended if the external magnetic field is varying and is the default for rovers. EK3_MAG_CAL = 3 uses heading fusion on the ground and 3-axis fusion after the first in-air field and yaw reset has completed, and is the default for copters. EK3_MAG_CAL = 4 uses 3-axis fusion at all times. NOTE: The fusion mode can be forced to 2 for specific EKF cores using the EK2_MAG_MASK parameter. NOTE: limited operation without a magnetometer or any other yaw sensor is possible by setting the COMPASS_USE parameters to 0. If this is done, the EK2_GSF_RUN and EK2_GSF_USE masks must be set to the same as EK3_IMU_MASK.
// @Description: This determines when the filter will use the 3-axis magnetometer fusion model that estimates both earth and body fixed magnetic field states, when it will use a simpler magnetic heading fusion model that does not use magnetic field states and when it will use an alternative method of yaw determination to the magnetometer. The 3-axis magnetometer fusion is only suitable for use when the external magnetic field environment is stable. EK3_MAG_CAL = 0 uses heading fusion on ground, 3-axis fusion in-flight, and is the default setting for Plane users. EK3_MAG_CAL = 1 uses 3-axis fusion only when manoeuvring. EK3_MAG_CAL = 2 uses heading fusion at all times, is recommended if the external magnetic field is varying and is the default for rovers. EK3_MAG_CAL = 3 uses heading fusion on the ground and 3-axis fusion after the first in-air field and yaw reset has completed, and is the default for copters. EK3_MAG_CAL = 4 uses 3-axis fusion at all times. NOTE: The fusion mode can be forced to 2 for specific EKF cores using the EK2_MAG_MASK parameter. NOTE: limited operation without a magnetometer or any other yaw sensor is possible by setting all COMPASS_USE, COMPASS_USE2, COMPASS_USE3, etc parameters to 0 with COMPASS_ENABLE set to 1. If this is done, the EK2_GSF_RUN and EK2_GSF_USE masks must be set to the same as EK3_IMU_MASK.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that these parameter names are different.
EK3_MAG_CAL -> EK2_MAG_CAL
EK3_IMU_MASK -> EK2_IMU_MASK
EK2_GSF_RUN -> EK2_GSF_RUN_MASK
EK2_GSF_USE -> EK2_GSF_USE_MASK

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, paul?

@priseborough
Copy link
Contributor Author

@rmackay9 ping

@priseborough
Copy link
Contributor Author

I've added the fixes for #14654

The following results are from SITL testing of a hand launch without use of the magnetomer.

EK3_ENABLE = 1
EK2_ENABLE = 0
AHRS_EKF_TYPE = 3
EK3_MAG_CAL = 7
COMPASS_ENABLE = 0
COMPASS_USE = 0
COMPASS_USE2 = 0
COMPASS_USE3 = 0

SITL was started using "sim_vehicle.py --frame plane-throw --console --map -L CMAC_PILOTSBOX" and launched using RC 7 2000 to trigger the throw after the "APM: EKF3 IMU0 origin set" message was received.

Here are the console messages and GPS innovations before the fix showing the delayed yaw alignment and larger than desirable velocity innovations:

2020-06-22 17:17:27 ArduPlane V4.1.0dev (07ad479)
2020-06-22 17:17:27 842f139c1c526d45bafd9f12e8b4c5f0
2020-06-22 17:17:27 Param space used: 581/3840
2020-06-22 17:17:27 RC Protocol: SITL
2020-06-22 17:17:27 New mission
2020-06-22 17:17:27 New rally
2020-06-22 17:17:27 GPS 1: detected as u-blox at 230400 baud
2020-06-22 17:17:32 Armed AUTO, xaccel = 19.4 m/s/s, waiting 0.2 sec
2020-06-22 17:17:33 Triggered AUTO. GPS speed = 0.0
2020-06-22 17:17:33 Takeoff to 30m at 100.0m to 1.0 deg
2020-06-22 17:17:42 EKF3 IMU0 yaw aligned using GPS
2020-06-22 17:17:42 EKF3 IMU0 is using GPS

Screen Shot 2020-06-22 at 6 37 53 pm

After the fixes, the reset is a second after launch and the innovations are small due to the more accurate yaw:

2020-06-22 18:37:04 ArduPlane V4.1.0dev (e64d786b)
2020-06-22 18:37:04 842f139c1c526d45bafd9f12e8b4c5f0
2020-06-22 18:37:04 Param space used: 581/3840
2020-06-22 18:37:04 RC Protocol: SITL
2020-06-22 18:37:04 New mission
2020-06-22 18:37:04 New rally
2020-06-22 18:37:04 GPS 1: detected as u-blox at 230400 baud
2020-06-22 18:37:06 Armed AUTO, xaccel = 19.4 m/s/s, waiting 0.2 sec
2020-06-22 18:37:07 Triggered AUTO. GPS speed = 0.0
2020-06-22 18:37:07 Takeoff to 30m at 100.0m to 0.2 deg
2020-06-22 18:37:08 EKF3 IMU0 yaw aligned using GPS
2020-06-22 18:37:08 EKF3 IMU0 is using GPS

Screen Shot 2020-06-22 at 6 41 50 pm

Copy link
Contributor

@tridge tridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. Just some comment errors

@@ -245,7 +245,7 @@ const AP_Param::GroupInfo NavEKF2::var_info[] = {

// @Param: MAG_CAL
// @DisplayName: Magnetometer default fusion mode
// @Description: This determines when the filter will use the 3-axis magnetometer fusion model that estimates both earth and body fixed magnetic field states, when it will use a simpler magnetic heading fusion model that does not use magnetic field states and when it will use an alternative method of yaw determination to the magnetometer. The 3-axis magnetometer fusion is only suitable for use when the external magnetic field environment is stable. EK3_MAG_CAL = 0 uses heading fusion on ground, 3-axis fusion in-flight, and is the default setting for Plane users. EK3_MAG_CAL = 1 uses 3-axis fusion only when manoeuvring. EK3_MAG_CAL = 2 uses heading fusion at all times, is recommended if the external magnetic field is varying and is the default for rovers. EK3_MAG_CAL = 3 uses heading fusion on the ground and 3-axis fusion after the first in-air field and yaw reset has completed, and is the default for copters. EK3_MAG_CAL = 4 uses 3-axis fusion at all times. NOTE: The fusion mode can be forced to 2 for specific EKF cores using the EK2_MAG_MASK parameter. NOTE: limited operation without a magnetometer or any other yaw sensor is possible by setting the COMPASS_USE parameters to 0. If this is done, the EK2_GSF_RUN and EK2_GSF_USE masks must be set to the same as EK3_IMU_MASK.
// @Description: This determines when the filter will use the 3-axis magnetometer fusion model that estimates both earth and body fixed magnetic field states, when it will use a simpler magnetic heading fusion model that does not use magnetic field states and when it will use an alternative method of yaw determination to the magnetometer. The 3-axis magnetometer fusion is only suitable for use when the external magnetic field environment is stable. EK3_MAG_CAL = 0 uses heading fusion on ground, 3-axis fusion in-flight, and is the default setting for Plane users. EK3_MAG_CAL = 1 uses 3-axis fusion only when manoeuvring. EK3_MAG_CAL = 2 uses heading fusion at all times, is recommended if the external magnetic field is varying and is the default for rovers. EK3_MAG_CAL = 3 uses heading fusion on the ground and 3-axis fusion after the first in-air field and yaw reset has completed, and is the default for copters. EK3_MAG_CAL = 4 uses 3-axis fusion at all times. NOTE: The fusion mode can be forced to 2 for specific EKF cores using the EK2_MAG_MASK parameter. NOTE: limited operation without a magnetometer or any other yaw sensor is possible by setting all COMPASS_USE, COMPASS_USE2, COMPASS_USE3, etc parameters to 0 with COMPASS_ENABLE set to 1. If this is done, the EK2_GSF_RUN and EK2_GSF_USE masks must be set to the same as EK3_IMU_MASK.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, paul?

libraries/AP_NavEKF3/AP_NavEKF3_MagFusion.cpp Show resolved Hide resolved
@vierfuffzig
Copy link
Contributor

vierfuffzig commented Jun 24, 2020

@priseborough @tridge i‘m following this closely as i do fly my trad. FW airframes without mag pretty exclusively. i‘ve done a lot of flights on EK3 now and did notice that after launching it takes a couple of seconds for EK3 yaw to align (2-4 secs usually), as compared to just a few ms on EK2. however, in real-flight conditions (hand launch) i can‘t seem to find the same large innovations and delay that SITL produces:

EK3 hardware:
image

EK2 hardware:
image

EK3 SITL:
image

is this just coincidental?

on a sidenote i wonder if there‘s a more intuitive way to handle yaw-source on no-mag setups using EK3 than having to set _MAG_CAL = 7. there‘s been no separate setting required on EK2 too besides unchecking MAGn_USE. the current EK3 handling imho might be prone to cause relevant support effort.

@priseborough
Copy link
Contributor Author

@priseborough @tridge i‘m following this closely as i do fly my trad. FW airframes without mag pretty exclusively. i‘ve done a lot of flights on EK3 now and did notice that after launching it takes a couple of seconds for EK3 yaw to align (2-4 secs usually), as compared to just a few ms on EK2. however, in real-flight conditions (hand launch) i can‘t seem to find the same large innovations and delay that SITL produces:

This PR should fix the delayed yaw alignment with EKF3.

@priseborough
Copy link
Contributor Author

@vierfuffzig I can modify the EKF3 params so that the EKF-GSF yaw use is enabled automatically if compass is disabled. I think you are right that having to set it to a specific value will increase support queries.

@vierfuffzig
Copy link
Contributor

@priseborough thanks, i think moving GSF to auto will add a lot of convenience.

@priseborough
Copy link
Contributor Author

I've added patch to make the use of the GPS for yaw automatic if COMPASS_USEx and COMPASS_ENABLE are set to 0. This has been tested in SITL using

../Tools/autotest/sim_vehicle.py --console --map --frame plane-throw -L CMAC_PILOTSBOX

to perform a hand launch to the west. EK3_MAG_CAL was set to 0 as was COMPASS_USEx and COMPASS_ENABLE.

The Copter use case was also tested in SITL with COMPASS_USEx and COMPASS_ENABLE set to 0. A takeoff in ALT_HOLD was performed, followed by horizontal movement to align the yaw angle.

@vierfuffzig If you are able to do testing with your setup and share the results, then that would be appreciated.

@vierfuffzig
Copy link
Contributor

@priseborough thanks a lot, that's great! i might get the chance to get some flights in later today, will report back.

@vierfuffzig
Copy link
Contributor

@priseborough are you 100% positive that COMPASS_ENABLE needs to be set to 1 on EK2 for no-mag use?
setting all COMPASS_USE, COMPASS_USE2, COMPASS_USE3, etc parameters to 0 with COMPASS_ENABLE set to 1
as it's 0 on EK3 re MAG_CAL param description.

@vierfuffzig
Copy link
Contributor

@priseborough tested this on EK3 with
MAG_CAL = 0
COMPASS_ENABLE = 0
COMPASS_USE = 0
COMPASS_USE2 = 0
COMPASS_USE3 = 0

image

fast yaw alignment within a few ms into flight, MAG_CAL on default works. excellent, thanks a lot!

@priseborough
Copy link
Contributor Author

I did some testing with my Nano Goblin today running a MatekF765 wing board and on one launch ran into a condition where the yaw aligned rapidly, but the use of GPS was delayed a few seconds due to the bias state convergence check. Commit 4799fba fixes this.

@vierfuffzig
Copy link
Contributor

@priseborough did a couple of launches on my nanoTalon yesterday, will take a closer look at each log, don‘t think i ran into delayed GPS fusion though from what i saw on OSD.

plus i think i missed a previous PR of yours that already fixed the requirement to set MAG_CAL = 7 explicitely. sorry bout that.

priseborough and others added 19 commits June 29, 2020 21:11
Instruction now explicitly specifies that all COMPASS_USE parameters must be set to 0 and COMPASS_ENABLE must be set to 1
The setting of EKF state variances is only required when commencing or recommencing velocity fusion.
The function that resets the EKF and GSF class variables has been renamed to be more consistent with its function.
Enables yaw bias to be learned when sitting stationary on ground.
Enables yaw bias to be learned when sitting stationary on ground.
The EKF can build up large yaw errors on ground so it is safer to stop using GPS and re-align after launch as per first launch.
Don't require user to separately set EK3_MAG_CAL to fly without a magnetomer
Fixed wing should not wait for bias state convergence after in-flight yaw alignment
@priseborough
Copy link
Contributor Author

I've rebased and fixed the conflict in the AP_NavEKF2.cpp EK2_MAG_CAL parameter description

@priseborough priseborough requested a review from tridge July 2, 2020 01:07
Copy link
Contributor

@tridge tridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, just needs to pass CI

@peterbarker peterbarker merged commit 24fccd5 into ArduPilot:master Jul 7, 2020
@peterbarker
Copy link
Contributor

Well, it passed CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EKF3 FW launch without a compass is not reliable
6 participants