The gyro data accumulation needs to be across the same integration period as the flow sensor. The previous code didn't sample the accumulation until the midpoint of the flow data had fallen behind the fusion time horizon.
This PR changes the optical flow time stamp definition so that flow data is retrieved when the leading edge of the flow accumulation period falls behind the fusion time horizon. This enables the accumulated gyro data to be sampled at the correct time. Fusion is then delayed until the mid sample time has fallen behind the fusion time horizon.
High rate optical flow data could make flow fusion to run every major update cycle, resulting in the calculation of bias errors in the body rates used to compensate flow data failing time validity checks and not running. This resulted in a slow drift of the nav solution if bias errors were present in the in the gyro data used for flow sensor motion compensation.
This is required because it can take several seconds for an optical flow sensor operation to be confirmed and there are also many use cases for indoor operation where no optical flow is used.
If magnetometer use is being inhibited because an indoor condition has been detected (optical flow and poor or no GPS) and the optical flow fusion checks fail causing the EKF to stop navigating, we do not want the EKF to start using the magnetometer.
* pr-ekfOptFlowFixes:
EKF: fix bug causing height offset when GPS use stops
EKF: Don't reject saturated flow data when it is the only aiding source
EKF: Prevent flow motion check false positives
EKF: Don't assume large position uncertainty when starting optical flow nav
EKF: relax terrain update requirements for continuing optical flow use
EKF: Relax minimum required range finder measurement rate
EKF: relax optical flow on ground motion checks
EKF: range finder aiding logic fixes
EKF: Decouple range finder use criteria checking and selection
EKF: Don't auto select range finder for height when on ground.
EKF: Fix false triggering of optical flow bad motion checks
EKF: update comments
EKF: Don't use optical flow if GPS is good and the vehicle is not using range finder for height
EKF: Stop using EV for yaw when GPS fusion starts
EKF: Add persistence criteria to GPS fail check
EKF: allow GPS fallback if quality bad and alternative aiding available
EKF: always run GPS checks