Commit Graph

409 Commits

Author SHA1 Message Date
priseborough 76d1378962 AP_NavEKF: Fix compiler warning messages 2015-01-01 23:39:48 +11:00
priseborough 3e3dd9d695 AP_NavEKF: Fix parenthesis error in EKF status reporting and clean up logic
This fixes a bug which could have caused the realative position status to be incorrectly reported under some conditions and also caused a compiler warning message. the logic used to report the filter solution status has been broken down into smaller, easier to understand statements.
2015-01-01 23:39:48 +11:00
priseborough c06f6e105e AP_NavEKF: Consistent initialisation of tuning parameters and variables
Non user adjustable parameters are now declared as 'const' in the header.
The _ prefix has been removed from non user adjustable tuning parameters.
We use a function call rather than a constructor to initialise variables because it enables the filter to be re-started in flight if necessary.
For consistency some signed integer type declarations have been changed to unsigned where appropriate.
2015-01-01 23:39:31 +11:00
priseborough f1dfa282dc AP_NavEKF: Consolidate constant velocity mode decision logic
The decision to switch to constant velocity mode during optical flow operation and te decision to switch back were previously being made in two different places in code. Both decisions are now made in the one place which makes the code easier to follow and maintain.
2015-01-01 19:53:21 +11:00
priseborough 9caf2ac895 AP_NavEKF: Make reversion to no GPS mode unambiguous 2015-01-01 19:53:21 +11:00
priseborough 58e9dd5dcd AP_NavEKF: Enumerate Position and Velocity aiding status 2015-01-01 19:53:21 +11:00
priseborough b016bae445 AP_NavEKF: Clean up reset of constant velocity mode
Move velocity store out of optical flow to velocity and position fusion control as it is a velocity fusion function.
Always clear the previous mode status
2014-12-31 13:16:16 +09:00
priseborough 3d207c316a AP_NavEKF: Change names for position and velocity hold modes
Name change done to avoid confusion with flight modes. modes are now referred to as constant position and constant velocity mode.
2014-12-31 13:16:15 +09:00
priseborough b650ee51a9 AP_NavEKF: Consolidate arming checks 2014-12-31 13:16:15 +09:00
priseborough 48cae0df15 AP_NavEKF: Fall back to attitude and hgt estimation for copter if GPS lost 2014-12-31 13:16:14 +09:00
priseborough b21f9daa90 AP_NavEKF: Update solution status reporting
This patch makes the reporting of an absolute position solution less abbiguaous and ensures that relative position is always true if absolute position is true
2014-12-31 13:16:13 +09:00
priseborough b6d300db19 AP_NavEKF: clean up determination of GPS availability 2014-12-31 13:14:22 +09:00
priseborough 40b02fc19a AP_NavEKF: Ensure filter doesn't try to use GPS after initialisation 2014-12-31 13:14:20 +09:00
priseborough bab1a69f1c AP_NavEKF: make position and velocity resets consistent with GPS usage 2014-12-31 13:14:18 +09:00
priseborough 0dc2356175 AP_NavEKF: Ensure initialisation methods read required sensor data 2014-12-31 13:14:16 +09:00
priseborough 5d1de79f08 AP_NavEKF: Modify initial values to make startup behaviour more consistent 2014-12-31 13:14:14 +09:00
priseborough a63af34d8f AP_NavEKF: Allow 10 seconds for the filter to settle after initialisation
Filter is declared unhealthy and will not arm for first 10 seconds after initialisation
2014-12-31 13:14:12 +09:00
priseborough 0a5de21dc7 AP_NavEKF: Fix bug in reporting of solution status
Because synthetic  position measurements at 0,0 are fused during position hold mode, a position timeout cannot be used as the only means of detecting position solution status.
2014-12-31 13:14:09 +09:00
priseborough 92c3026072 AP_NavEKF: Link process noise to arm status, not pos hold mode 2014-12-31 13:14:07 +09:00
priseborough a535b73a6d AP_NavEKF: Initialise timeout status to true
This status will be cleared when data arrives and is fused successfully
2014-12-31 13:14:04 +09:00
priseborough 363c1e393d AP_NavEKF: Latch use of position hold mode for duration of flight
Required to prevent acquisition of GPS mid flight causing unwanted change in position and velocity
A distinction has been mad between the arm and disarm transition and the decision to use position hold mode (formerly static mode)
2014-12-31 13:14:02 +09:00
priseborough a0a6c0362f AP_NavEKF: Relax timeout check applied to optical flow data
200 msec was too short and could lead to false positives. 5000 msec is the largest time we can go free inertial.
2014-12-31 13:14:00 +09:00
priseborough 5bd4ee9715 AP_NavEKF: Use compensation for baro delay in position hold mode 2014-12-31 13:13:58 +09:00
priseborough 4dc1ee2d66 AP_NavEKF: Rename static mode to avoid confusion with other non-GPS modes
This renames static mode as posHoldMode to make it clearer what this and the other non-GPS modes do
2014-12-31 13:13:54 +09:00
priseborough b160f4c03b AP_NavEKF: Compensate optical flow fusion for GPS glitch recovery offset 2014-12-31 13:13:52 +09:00
priseborough e4c969084d AP_NavEKF: Improve behaviour recovering from a GPS timeout
When regaining GPS after a timeout, an offset is applied when fusing  GPS velocity so that GPS velocity and position data as fused by the EKF is kinematically consistent.
This velocity offset is also accounted for when fusing air data so that wind estimates are not corrupted when the GPS position offset is being pulle back to zero.
The intended behaviour is that the EKF position will be pulled back to the GPS position at a rate of 5m/s for planes and 1 m/s for copters. This avoids large deviations in trajectory when GPS is regained.
2014-12-31 13:13:50 +09:00
priseborough 6eb533121c AP_NavEKF: Add static mode to solution status message 2014-12-31 13:13:48 +09:00
priseborough 5c3a56a087 AP_NavEKF: Fix error in comments 2014-12-31 13:13:46 +09:00
priseborough 3891dada78 AP_NavEKF: remove unnecessary function 2014-12-31 13:13:44 +09:00
priseborough a16253796f AP_NavEKF: Fix bug preventing the non-GPS mode being selected externally
When on the ground it is likely the flow sensor will be returning  data that does not meet the minimum quality requirements selected.
The previous check was for the presence of valid data. This has been loosened to look for the presence of data.
When the vehicle becomes airborne, the quality of flow data normally improves as the image comes into focus.
2014-12-31 13:13:42 +09:00
priseborough a42100e4c5 AP_NavEKF: Improved handling of no GPS
This patch enables indoor operation of the EKF by putting it into static mode if optical flow operation is not enabled and no GPS is available
2014-12-31 13:13:40 +09:00
priseborough 73a06cd0c1 AP_NavEKF: Fix bug causing magnetic field state learning to be forgotten 2014-12-31 13:13:37 +09:00
priseborough bf89c56e54 AP_NavEKF: Fix comments error in description of flow sensor sign conventions 2014-12-31 13:13:35 +09:00
priseborough 4eb19c2324 AP_NavEKF: Rationalise health status reporting
1) Un-used public methods to report height and position drifting have been removed
2) A time-out has been added to the airspeed innovation consistency check so that if we are relying on airspeed to constrain velocity drift, a filter divergence or other fault that causes the airspeed to be continually rejected will trigger a change in health status.
3) A timeout of velocity, position or height measurements does not cause a filter fault to be reported. Timeouts can be due to sensor errors and do not necessarily indicate that the filter has failed.
4) Time-outs of various measurements are used to present a consolidated bitmask which inidicates which parts of the solution can be used, eg attitude, height, velocity, relative position, absolute position, etc.
2014-12-31 13:13:31 +09:00
priseborough 78b30e4ce5 AP_NavEKF: Increase rate at which GPS glitch offsets are reduced for planes 2014-12-31 13:13:29 +09:00
priseborough f2c506339a AP_NavEKF: Reduce time required to recover from GPS timeouts
The time required for GPS to be lost or rejected before vehicles with airspeed sensors either reset to GPS or invoke the zero side-slip assumption to constrain drift has been reduced from 15 to 10 seconds
A duplicate zeroing of the GPS position offset has been removed
If the vehicle is a non hovering vehicle (eg a plane) then the speed at which the GPS offset is pulled back to zero after a reset is increased from 1 to 3  m/s

This also improves recovery from bad inertial data for planes
2014-12-18 21:50:40 +11:00
priseborough f73816dbb5 AP_NavEKF: Improve robustness to long periods without GPS 2014-12-18 21:07:45 +11:00
priseborough 3afde0061f AP_NavEKF: Use named states for velocity reset
Readibility improvement
2014-12-18 17:29:50 +11:00
priseborough f6ce25df2a AP_NavEKF: Do not reset vertical velocity state from GPS
Doing this can cause large height and height rate errors if large GPS velocity errors cause the GPS tn be rejected for long enough to cause a timeout and reset of states.
2014-12-18 17:29:47 +11:00
Randy Mackay e581e81da5 AP_NavEKF: reorder declation to fix compiler warning
No functional change
2014-12-11 15:37:56 +09:00
Andrew Tridgell cb9c518ab8 Revert "AP_NavEKF : Reduce ripple in estimates that can cause copter motor 'pulsing'"
This reverts commit 13df6fb1c9.

This patch was a result of an incorrect merge of the optflow branch
into master. It reintroduced the bug fixed by this commit:

  AP_NavEKF : Fix bug in reset of GPS glitch offset
  8aa267f75f
2014-12-08 07:53:47 +11:00
priseborough a2bd3b4a42 AP_NavEKF: Add public method returning height above ground level 2014-12-06 18:16:51 +11:00
priseborough d701cfcb75 AP_NavEKF: Output terrain relative PosD when relying on Optical Flow 2014-12-06 18:16:51 +11:00
priseborough 0156d846f1 AP_NavEKF: Increase height at which nav gain reduction starts
Compensates for optical flow induced noise increase with height.
2014-12-06 18:16:51 +11:00
priseborough a905432ffe AP_NavEKF: reduce height at which nav gain reduction starts 2014-12-06 18:16:51 +11:00
priseborough 5785272933 AP_NavEKF: Improve robustness to corrupted flow sensor data 2014-12-06 18:16:51 +11:00
priseborough b1d44d4dde AP_NavEKF: Add protection for negative height above ground 2014-12-06 18:16:50 +11:00
priseborough d994da0886 AP_NavEKF: Expand EKF speed limit public method to handle control limits 2014-12-06 18:16:50 +11:00
priseborough bc2255d6b1 AP_NavEKF: Improve comments in setInhibitGPS public method 2014-12-06 18:16:50 +11:00
priseborough 416eaf4633 AP_NavEKF: Apply single definition of using optical flow 2014-12-06 18:16:50 +11:00
priseborough b56b68ce10 AP_NavEKF: Add public method reporting horizontal speed limit
This is required if using optical flow, as depending on height, the speed must be limited to prevent the sensor saturating
2014-12-06 18:16:50 +11:00
priseborough c8fb376cc4 AP_NavEKF: Fix bug in bias rate of change limiting
This doesn't change the behaviour, but means the result is achieved using the correct parameters, and comments are consistent
2014-12-06 18:16:50 +11:00
priseborough 599e53f3f2 AP_NavEKF: Prevent flow scale factor updating on ground 2014-12-06 18:16:49 +11:00
priseborough 083e22966c AP_NavEKF: Add public method to report available output data 2014-12-06 18:16:49 +11:00
priseborough e53d28854e AP_NavEKF: Add public method to inhibit GPS use and clean-up GPS use logic
This provides the calling vehicle software the abiity to request the EKF to not use GPS.
An integer is returned that indicates the type of operation available:
0 = request rejected (request will only be accepted if the EKF is in static mode, eg pre-armed)
1 = request accepted, attitude, vertical velocity and position estimates available
2 = request accepted, attitude, height rate, height, horizontal velocity and relative position estimates available
2014-12-06 18:16:49 +11:00
priseborough 8fb1d9cf8d AP_NavEKF: Fix bug preventing opt flow scale factor estimation
Also removes un-used variable declarations
2014-12-06 18:16:49 +11:00
priseborough a78920761c AP_NavEKF: Update comments in flow data interface 2014-12-06 18:16:49 +11:00
priseborough 52c7e56a4a AP_NavEKF: Add parameter for max valid optical flow rate magnitude 2014-12-06 18:16:49 +11:00
priseborough 6f8971d80a AP_NavEKF: Speed up flow sensor gyro bias correction 2014-12-06 18:16:49 +11:00
priseborough d7ad45ebda AP_NavEKF: Don't fuse flow measurements if too big 2014-12-06 18:16:49 +11:00
priseborough 84944fdd4e AP_NAvEKF: Revert back to 10Hz fusion 2014-12-06 18:16:49 +11:00
priseborough 1f78a73cdb AP_NavEKF: Make flow measurement delay vehicle specific
This takes into account the inter-sampling delay between the flow driver and the APM software which depends on the rate at which the dirver is being checked. This is 50Hz for plane and rover, and 200Hz for Copter.
2014-12-06 18:16:49 +11:00
priseborough 5f941655a8 AP_NavEKF: changes to support to 20Hz flow fusion rate 2014-12-06 18:16:48 +11:00
priseborough 0bf991eef9 AP_NavEKF: Fix bug in optical flow fusion smoothing 2014-12-06 18:16:48 +11:00
priseborough 839b814d12 AP_NavEKF : Inhibit flow and range fusion in static mode 2014-12-06 18:16:47 +11:00
priseborough 9b9934ac06 AP_NavEKF : fix velocity timeout bug during optical flow operation 2014-12-06 18:16:47 +11:00
priseborough 517026980b AP_NavEKF : Add fault and timeout logging 2014-12-06 18:16:47 +11:00
priseborough f640ec30ff AP_NavEKF : Reset held velocity on arming
This held velocity is used to constrain the drift in the optical flow solution before the vehicle is high enough for the optical flow sensor to work.
2014-12-06 18:16:47 +11:00
priseborough 06c19a3a4d AP_NavEKF : Update optical flow debug logging 2014-12-06 18:16:47 +11:00
priseborough 1791dec622 AP_NavEKF : Fix velocity hold mode 2014-12-06 18:16:47 +11:00
priseborough 84421e0a35 AP_NavEKF : Adjust initial flow scale factor and limits 2014-12-06 18:16:47 +11:00
priseborough 573633daf7 AP_NavEKF : Fix incorrect use of flow sensor time-stamp
flow sensor time stamp is now issued by the flow sensor and is on a different time-base
2014-12-06 18:16:47 +11:00
priseborough 9ea97c1a38 AP_NavEKF : Modify optical flow data interface
Sign conventions have changed
2014-12-06 18:16:46 +11:00
priseborough 8faeb190de AP_NavEKF : Rework logic to cope with bad flow data 2014-12-06 18:16:46 +11:00
priseborough 41f0231cfb AP_NavEKF : improve logic dealing with lack of flow or range data 2014-12-06 18:16:46 +11:00
priseborough 9ba46ad795 AP_NavEKF : Improve handling of flow sensor failure 2014-12-06 18:16:46 +11:00
priseborough 2ee1c549be AP_NavEKF : improve criteria used to inhibit scale factor estimation 2014-12-06 18:16:46 +11:00
priseborough e09ff84218 AP_NavEKF : Don't estimate focal length scale factor without reliable velocity 2014-12-06 18:16:46 +11:00
priseborough 4c92a5f23f AP_NavEKF : Use GPS velocity if PX4Flow sensor fails 2014-12-06 18:16:46 +11:00
priseborough 283811edcb AP_NavEKF : stop velocity change when flow measurements drop out 2014-12-06 18:16:46 +11:00
priseborough 9132fcfe43 AP_NavEKF : Change mag fusion to use corrected compass values
This enables compass units to be switched in-flight
2014-12-06 18:16:46 +11:00
priseborough c3be486c29 AP_NavEKF : Enable inhibiting of GPS measurements 2014-12-06 18:16:45 +11:00
priseborough 79698f7742 AP_NavEKF : improvements to range finder fusion 2014-12-06 18:16:45 +11:00
priseborough 1222559da0 AP_NavEKF : Fix bug affecting sonar fusion 2014-12-06 18:16:45 +11:00
priseborough 117bd2a998 AP_NavEKF : Add time based noise to terrain offset state 2014-12-06 18:16:45 +11:00
priseborough b1d3d5d9a3 AP_NavEKF : Don't update focal length scale factor at low speeds 2014-12-06 18:16:45 +11:00
priseborough 8dd1081f54 AP_NavEKF : Add range measurement to EKF debug message 2014-12-06 18:16:45 +11:00
priseborough 744c72d40b AP_NavEKF : Updates to range finder fusion 2014-12-06 18:16:45 +11:00
priseborough a20729f60f AP_NavEKF : Update names in optical flow debug logging 2014-12-06 18:16:45 +11:00
priseborough 235b3bebda AP_NavEKF : Add range finder health and enable range finder fusion
The 2-state auxiliary filter is also renamed.
2014-12-06 18:16:45 +11:00
priseborough 988de2a898 AP_NavEKF : Add smoothing to optical flow fusion 2014-12-06 18:16:44 +11:00
priseborough 70c779dbc2 AP_NavEKF : Optical flow numerical optimisations 2014-12-06 18:16:44 +11:00
priseborough 2a1420171a AP_NavEKF : reduce minimum accepted flow quality 2014-12-06 18:16:44 +11:00
priseborough 3fbedc9f98 AP_NAvEKF : update comments 2014-12-06 18:16:44 +11:00
priseborough 81b09c9361 AP_NavEKF : temporary mods to test use of flow sensor internal gyro data 2014-12-06 18:16:44 +11:00
priseborough cd418c946c AP_NavEKF : preliminary implementation for optical flow and range finder fusion
Range finder measurements are not input to EKF at this time, however the method for fusing them is
implemented.
2014-12-06 18:16:44 +11:00
priseborough 13df6fb1c9 AP_NavEKF : Reduce ripple in estimates that can cause copter motor 'pulsing'
This patch reduces the level of 5Hz and 10Hz 'pulsing' heard in motors due to GPS and altimeter fusion which cause a small 5Hz and 10Hz ripple on the output under some conditions. Attitude, velocity and position state corrections from GPS, altimeter and magnetometer measurements are applied incrementally in the interval from receiving the measurement to the predicted time of receipt of the next measurement. Averaging of attitude state corrections is not performed during periods of rapid rotation.

Time stamps are now explicitly initialised to the current IMU time to avoid unwanted activation of timeout logic on filter start and the various calls to the hal.scheduler->millis() object have been consolidated.

Unused variables have been removed
2014-12-06 18:16:43 +11:00
priseborough dcb252cc05 AP_NavEKF : Fix bug in reset of position and velocity states
If the inertial solution velocity or position needs to be reset to the GPS, the stored state history for the corresponding states should also be reset.
Otherwise the next GPS measurement will be compared to an invalid previous state and will be rejected.
The position state should be reset to a GPS position corrected for velocity and measurement latency. This will make a noticeable difference for high speed flight vehicles, eg 11m at 50m/s
2014-12-06 18:16:43 +11:00
Jonathan Challinger 7692761f34 AP_NavEKF: Added getAccelNED function 2014-12-05 19:40:01 +09:00
priseborough 874d0780aa AP_NavEKF: Reduce vulnerability to ground fixed magnetic interference
Re-initialisation of the magnetic field states and yaw angle is now only performed a maximum of two times after start-up.

Once when coming out of static modefor the first time (first arm event)
Again (for copter only) when the altitude gain above the arming altitude exceeds 1.5m

this prevents magnetic interference present at arming (eg arming on a metal roof)from corrupting the magnetic field states enough to cause bad heading errors and toilet bowling on copter
2014-12-05 14:33:04 +11:00