Commit Graph

123 Commits

Author SHA1 Message Date
priseborough 397033b7c3 AP_NavEKF2: Add flow sensor body position offset to data buffer 2016-10-27 14:54:42 +11:00
priseborough 92c086b40e AP_NavEKF2: Add rangefinder body position offset to data buffer 2016-10-27 14:54:42 +11:00
priseborough 3148ad4623 AP_NavEKF2: Add GPS antenna position offset data to data buffer 2016-10-27 14:54:42 +11:00
priseborough fd905c23e1 AP_NavEKF2: Add body position offset to optical flow interface 2016-10-27 14:54:42 +11:00
Mathieu OTHACEHE 152edf7189 Global: remove mode line from headers
Using a global .dir-locals.el file is a better alternative than
reincluding the same emacs header in every file of the project.
2016-10-24 09:42:01 -02:00
priseborough 9779511425 AP_NavEKF2: Fix bug in median filter code 2016-10-19 19:45:00 +09:00
priseborough 5d09c78f34 AP_NavEKF2: Always perform optical flow takeoff check when receiving data
A specialised takeoff check is now always performed when we receive new flow data as the default behaviour is to try and use flow data whenever it is received, rather than limit its use to a use to a flow-only mode of operation that had to be selected via user parameter.
2016-10-10 14:49:48 +09:00
Randy Mackay 2ebb81b02f AP_NavEKF2: switching compass message to GCS downgraded to INFO 2016-09-21 21:42:44 +09:00
priseborough 8797714203 AP_NavEKF2: Fix bug in handling of invalid range finder data 2016-09-13 17:44:43 +09:00
priseborough e6f36f04db AP_NavEKF2: Enable automatic use of range finder height
The EK2_RNG_USE_HGT parameter sets the height (expressed as a percentage of the maximum range of the range finder as set by the RNGFND_MAX_CM parameter) below which the range finder will be used as the primary height source when the vehicle is moving slowly.

When using a height reference other than GPS, the height datum can drift due to air pressure changes if using baro, or due to terrain height changes if using range finder as the primary height source. To ensure that a consistent height datum is available when switching between altitude sources, the WGS-84 height estimate of the EKF's local positi norigin is updated using a
single state Bayes estimator,

If rngfinder or gps height data is lost whilst being used, there will be a fall-back to baro data.
2016-08-08 10:56:44 +09:00
Andrew Tridgell 567d5cdbe6 AP_NavEKF2: use mavlink messages not printf for state change notifications 2016-07-19 12:16:51 +10:00
priseborough bd7bf21475 AP_NavEKF2: Speed improve switch-over to backup magnetometer
When switching over to a back up magnetometer, ensure that the earth field estimate are reset. other wise mag earth field estimates due to the previous failed mag could cause data from the new mag to be rejected.
2016-07-19 12:16:50 +10:00
priseborough e2b8807260 AP_NavEKF2: Fix bug causing switching in and out of aiding
If the GPS receiver was disconnected and no data received, then then the gpsGoodToAlign check did not get a chance to run and becasue it was previously true the EKF would switch back into aiding.
This prevents this by ensuring that gpsGoodToAlign defaults to false when the check is not being performed.
An additional check has also been dded to ensure that there is GPS data to fuse before we declare ready to use GPS.
2016-07-19 12:16:50 +10:00
priseborough 9a23152ee4 AP_NavEKF2: Fix bugs and consolidate aiding switch logic
Switching in and out of aiding modes was being performed in more than one place and was using two variables.
The reversion out of GPS mode due to prolonged loss of GPS was not working.
This consolidates the logic and ensures that PV_AidingMode is only changed by the setAidingMode function.
2016-07-19 12:16:50 +10:00
priseborough 10470b2dc1 AP_NavEKF2: fix bug in initialisation of declination co-variances
Co-variances were being re-zeroed after being set. This meant that the initial declination learning was sensitive to measurement errors which could result in poor initial yaw accuracy.
2016-07-10 08:21:18 +10:00
priseborough 55dee347e0 AP_NavEKF2: Fix bug in averaged filter delta time
Average EKF time delta was not being updated.
2016-07-09 15:57:36 +10:00
priseborough 191c34612d AP_NavEKF2: Fix bug in use of corrected IMU data
IMU data was being corrected before being used by the co-variance prediction, whereas the delta angles and velocities in the derivation were supposed to be uncorrected.
This patch creates separate variable for the corrected data
2016-07-09 15:57:35 +10:00
Paul Riseborough fe06606193 AP_NavEKF2: Ensure corrected IMU data used by EKF
Don't try to pop new IMU data from the buffer unless we have written data.
Correct IMU data as soon as it is popped from the buffer
2016-06-28 14:20:12 +10:00
Jonathan Challinger bd8c804ab5 AP_NavEKF2: correct comments 2016-06-28 14:20:12 +10:00
Jonathan Challinger 2f709dfe86 AP_NavEKF2: improve inertial prediction 2016-06-28 14:20:11 +10:00
Jonathan Challinger 99f481e098 AP_NavEKF2: always calcGpsGoodForFlight 2016-06-28 14:20:11 +10:00
Paul Riseborough d2694fe5dc AP_NavEKF2: Remove duplicate transition into GPS aiding
This decision is made in one place in setAidingMode()
2016-05-21 15:13:52 +10:00
Paul Riseborough 6be9eaa524 AP_NavEKF2: use receiver estimated accuracy
Adjust the GPS observation noise based on receiver accuracy output if available.
2016-05-21 15:13:50 +10:00
Andrew Tridgell 4080c6091d AP_NavEKF2: fixed an assumption that _ahrs->get_compass() always works
if MAG_ENABLE=0 in plane there is no compass
2016-05-19 14:16:40 +10:00
Andrew Tridgell 223c512188 AP_NavEKF2: added logging of sensor data in EKF2 2016-05-07 18:27:18 +10:00
Andrew Tridgell f92279f436 AP_NavEKF2: allow logging of IMT data from inside EKF2 2016-05-07 18:27:17 +10:00
Andrew Tridgell ac60901b0c AP_NavEKF2: use vector comparison for new mag vector 2016-04-21 09:56:22 +10:00
Jonathan Challinger 1185cd1be7 AP_NavEKF2: move getMagOffsets into outputs 2016-04-21 09:51:41 +10:00
Jonathan Challinger acfaafe276 AP_NavEKF2: detect changes to magnetometer offset parameters and reset states 2016-04-21 09:51:41 +10:00
Andrew Tridgell acb4885989 AP_NavEKF2: use get_delta_angle_dt() API 2016-01-19 09:50:22 +11:00
Paul Riseborough 287ebe8e6a AP_NavEKF2: Fix bug in application of sensor bias corrections
Sensor bias corrections were being applied to the incoming IMU data using the wrong delta time.
This was what was driving the different tuning between plane and copter for gyro bias process noise so the same gyro bias process noise default tuning value can now be used for all platform types.
Sensor bias corrections were being applied a a second time to the output observer inertial data.
2016-01-13 08:05:39 +11:00
Andrew Tridgell 23cef70846 AP_NavEKF2: use get_loop_delta_t() from INS 2015-12-27 14:57:17 +09:00
Lucas De Marchi 2591261af6 Global: rename min and max macros to uppercase
The problem with using min() and max() is that they conflict with some
C++ headers. Name the macros in uppercase instead. We may go case by
case later converting them to be typesafe.

Changes generated with:

	git ls-files '*.cpp' '*.h' -z | xargs -0 sed -i 's/\([^_[:alnum:]]\)max(/\1MAX(/g'
	git ls-files '*.cpp' '*.h' -z | xargs -0 sed -i 's/\([^_[:alnum:]]\)min(/\1MIN(/g'
2015-12-01 16:28:09 -02:00
Paul Riseborough ddb7d92fc8 AP_NavEKF2: Fix timing jitter in airspeed fusion
The airspeed observation buffer was only being checked when new data arrived instead of every frame which introduced some timing jitter. The buffer is now checked every filer update step.
The duplication and inconsistent naming of booleans used to indicate availability f data has been fixed.
2015-11-26 09:22:03 +11:00
Siddharth Purohit and Paul Riseborough 3014eb4001 AP_NavEKF2: Rework measurement buffer refactor
These changes were pair coded an tested by Siddharth Purohit and Paul Riseborough

Fix indexing errors
Move buffer code into a separate file
Split observer and IMU/output buffers and remove duplicate sample time
Optimise observation buffer search
Reduce maximum allowed fusion age to 100 msec
2015-11-23 19:42:06 +11:00
Siddharth Bharat Purohit b3c8dcee34 AP_NavEKF2: measurement buffer refactor 2015-11-23 19:34:50 +11:00
Caio Marcelo de Oliveira Filho 8d882b06dd AP_NavEKF2: use millis/micros/panic functions 2015-11-20 12:32:41 +09:00
Paul Riseborough 04228e0b3b AP_NavEKF2: Rework selection of height measurements for fusion
GPS height has been added as a measurement option along with range finder and baro
Selection of the height measurement source has been moved into a separate function
Each height source is assigned its own measurement noise
If GPS or baro alt is not able to be used, it reverts to baro
When baro is not being used, an offset is continually calculated which enables a switch to baro without a height step.
2015-11-18 11:18:42 +11:00
Paul Riseborough 4c72a14e22 AP_NavEKF2: Add function to LPF and spike filter baro data 2015-11-18 11:18:17 +11:00
Paul Riseborough 34311bedfa AP_NavEKF2: Add data buffers for range finder data 2015-11-18 11:18:17 +11:00
Andrew Tridgell 99da195e37 AP_NavEKF2: make IMU buffer length depend on main loop rate
this fixes a problem with Replay and baro data
2015-11-18 10:20:39 +11:00
Paul Riseborough 9b82b2200c AP_NavEKF2: Fix plane in-flight yaw reset
The copter method was being used for plane and the plane method was not being run due to the change in flight status not being detected.
The plane reset method did not trigger if the EKF had already dragged the velocity states along with the GPS or could align to an incorrect heading.
The method has been reworked so that it resets to the GPS course, but only if there are inconsistent angles and large innovations.
To stop a failed magnetometer causing a loss of yaw reference later in flight, if all available sensors have been tried in flight and timed out, then no further magnetoemter data will be used
2015-11-16 09:05:42 +11:00
Paul Riseborough 577670ccee AP_NavEKF2: Reduce memory required by 6KB when running at 400Hz
Down-sample the IMU and output observer state data to 100Hz for storage in the buffer.
This reduces storage requirements for Copter by 75% or 6KB
It does not affect memory required by plane which already uses short buffers due to its 50Hz execution rate.
This means that the EKF filter operations operate at a maximum rate of 100Hz.
The output observer continues to operate at 400Hz and coning and sculling corrections are applied during the down-sampling so there is no loss of accuracy.
2015-11-10 15:51:18 +11:00
Paul Riseborough 3d8e74df26 AP_NavEKF2: Don't switch magnetometers when on the ground or just started
Large magnetometer innovations on the ground could be caused by factors that will disappear when flying, eg:

a) Bad initial gyro bias
b) External magnetic field disturbances (adjacent metal structures, placement of hatches with magnets, etc)

To avoid unnecessary switches, we inhibit switching until off-ground and when sufficient time has lapsed from power on to learn gyro bias offsets.
2015-11-09 22:07:10 +11:00
Paul Riseborough 3099d94e78 AP_NavEKF2: Retrieve correct time-stamp for active compass 2015-11-09 22:07:10 +11:00
Paul Riseborough 7294c8004b AP_NavEKF2: Enable use of backup magnetometers after a timeout
If the magnetometer fails innovation consistency checks for too long (currently 10 sec), then the next available sensor approved for yaw measurement will be used.
2015-11-09 22:07:09 +11:00
Paul Riseborough afeadfca51 AP_NavEKF2: Don't attempt to compensate for external mag calibration
This was problematic to implement with magnetometer switching. It is likely that slow magnetometer learning can still be performed externally (eg plane) but this will need to be monitored to see if it causes issues.
2015-11-09 22:07:09 +11:00
Paul Riseborough f08a4af751 AP_NavEKF2: Remove redundant if statement
Thank you to OXINARF for picking up this one
2015-11-08 17:06:57 +11:00
Paul Riseborough a8983d075f AP_NavEKF2: Enable clean entry into GPS aiding in-flight
The setting of the EKF origin and the entry into GPS aiding mode have been separated to make the logic clear.
The order of operations has been changed to ensure that when a reset to GPS is performed, a valid GPS measurement is available in the buffer
Declaration of GPS availability is not made unless the GPS data has been entered into the buffer
2015-11-08 16:26:04 +11:00
Paul Riseborough 2340e18fdc AP_NavEKF2: Offset the fusion time horizon between multiple instances
Prevents frame over-runs due to simultaneous fusion of measurements on each instance.
The offset is only applied if less than 5msec available between frames
2015-11-08 15:37:26 +11:00
Paul Riseborough d48454ee2d AP_NavEKF2: Use nominated IMU unless unavailable
We now run a separate instance of the EKF for each IMU, so input data fusion of IMU's is no longer required.
2015-11-08 15:37:26 +11:00
Andrew Tridgell 2ab2afc86a AP_NavEKF2: added EK2_IMU_MASK for multiple IMUs
no voting between multiple IMUs yet
2015-11-06 10:42:58 +11:00
Paul Riseborough b15bf3243e AP_NavEKF2: Remove potential for division by zero 2015-10-30 15:34:26 +09:00
Paul Riseborough f539b597a3 AP_NavEKF2: Improve initialisation of magnetic field learning
Use the more robust, but less accurate compass heading fusion up to 5m altitude
Wait for the magnetometer data fusion time offset to be correct before using data to reset states
Don't reset magnetic field states if the vehicle is rotating rapidly as timing offsets will produce large errors
When doing the yaw angle reset, apply the reset increment to all quaternions stored in the output buffer to avoid transients produced by yaw rotations and the 0.25 second fusion time horizon offset.
Only do the one yaw and mag reset at 5m, not two at 1.5 and 5.0m
Always re-do the yaw and mag reset when leaving the ground.
2015-10-30 15:34:20 +09:00
Paul Riseborough b459d937ad AP_NavEKF2: Clean up GPS fusion timeout logic and comments 2015-10-30 12:24:19 +09:00
Paul Riseborough 0b1a6a2157 AP_NavEKF2: Clean up GPS timeout logic 2015-10-30 12:24:06 +09:00
Paul Riseborough 74da4d8e57 AP_NavEKF2: Remove GPS glitch offset logic
Correction for steps in position and velocity caused by resets following GPS glitches and other events are now handled by the control loops.
2015-10-30 12:24:04 +09:00
Paul Riseborough b08817554e AP_NavEKF2: Ensure consistent position and velocity fusion rates when not using GPS
This sets the fusion of the synthetic position and velocity to occur at the same time as the barometer

This makes filter tuning more consistent between GPS and non-GPS useage
2015-10-21 17:27:00 +11:00
Paul Riseborough 1c347e8859 AP_NavEKF: Prevent high measurement data rates from overflowing buffers
High measurement data rates can fill buffers with data that is always new and never fused because it is over-written before it falls behind the measurement time horizon.
2015-10-21 17:27:00 +11:00
Paul Riseborough d1a090dda8 AP_NavEKF: Fix bug fetching data from measurement buffers
This bug can result in valid data being rejected and fused at the wrong time horizon.
2015-10-21 17:27:00 +11:00
Paul Riseborough e6312d91ce AP_NavEKF2: Correct variable name 2015-10-21 17:27:00 +11:00
Paul Riseborough 4640673cb1 AP_NavEKF2: Fix bug causing incorrect fusion timing 2015-10-21 17:27:00 +11:00
Paul Riseborough ab8c28a7cc AP_NavEKF: Fix bug allowing takeoff in GPS modes without aiding
The legacy EKF switches GPs aiding on on arming, whereas the new EKF switches it on based on GPS data quality.
This means the decision to arm and therefore the predicted solution flags must now reflect the actual status of the navigation solution as it will no longer change when motor arming occurs.
2015-10-20 20:16:00 +11:00
Paul Riseborough e076ed7f66 AP_NavEKF2: Remove compiler warning message 2015-10-20 18:16:16 +11:00
Paul Riseborough 0f530bb5a0 AP_NavEKF2: Correct comments 2015-10-20 15:21:40 +11:00
Andrew Tridgell d1dfd5fd01 AP_NavEKF2: use common header for optimisation level and irq disable 2015-10-20 15:21:40 +11:00
Paul Riseborough 2fbd050418 AP_NavEKF2: Use blended accelerometer data
If high vibration levels cause offsets between the two, it switches to the accelerometer with lower vibration levels. The default behaviour is to use the average of both accelerometers.
2015-10-20 15:21:40 +11:00
Paul Riseborough 225b81baf4 AP_NavEKF2: Prevent users breaking filter by setting excessive time delays
If time deelays greater than the IMU buffer length are used, then it is possible for measurements to be dropped.
2015-10-20 15:21:39 +11:00
Paul Riseborough 35b08849f7 AP_NavEKF2: Reduce effect of rounding errors on covariance prediction 2015-10-20 15:21:37 +11:00
Paul Riseborough 67a669fcdc AP_NavEKF2: Correct comments for height measurement 2015-10-20 15:21:36 +11:00
Paul Riseborough db4dfce7b1 AP_NavEKF2: Add fix status to GPS check report message 2015-10-10 14:49:07 +09:00
Paul Riseborough 22920aafad AP_NavEKF2: Improve GPS status reporting 2015-10-10 14:48:59 +09:00
Paul Riseborough b142cc7fd2 AP_NavEKF2: Rename files and re-distribute content 2015-10-10 14:48:50 +09:00