# Heading source & Airspeed sensor-less navigation of Fixed Wing - Yaw estimator (EKF-GSF) and Wind Estimator

As noted in PID tuning for a small Flying Wing (~47 cm wingspan) - #3 by junwoo0914, I have been working on getting a fixed wing to work without a magnetometer for autonomous navigation.

All of this would be quite straight forward if we donât consider wind, but when we have significant wind I noticed that thereâs a discrepancy between different airspeed / wind velocity / yaw estimation logic inside PX4, and wanted to bring up the discussion.

## Estimators in PX4

There are 3 main estimators running in PX4 crucial to the mag-less operation of fixed wing:

1. EKF-GSF Yaw estimator (as fallback in EKF2 when magnetometer fails)
2. Wind Estimator (in Airspeed selector, when not using airspeed sensor)
3. Wind prediction in EKF2 (native state variable for the EKF2)

And the pipeline is like following:

### EKF-GSF

Input: based on estimated airspeed, IMU data

Output: âheading estimateâ, which works as an external source of measurement to EKF2, like a magnetometer would.

Results are published on âyaw_estimator_statusâ topic

### Airspeed selector - Wind Estimator

Input: Inertial velocity and attitude estimate

Ouptut: Wind Estimator provides an estimated âwind velocityâ (based on sideslip beta angle fusion)

Results are published on âairspeed_windâ topic

### Airspeed selector - Calculating Ground minus Wind

Input: Inertial velocity, wind velocity (from wind estimator)

Output: Estimation of airspeed (when the ASPD_PRIMARY index is âGroundspeed minus windspeedâ)

Results are published on âairspeed_validatedâ topic

### EKF2 Wind Prediction

It runs on itâs own state prediction algorithm as part of EKF2

## Questions

1. It seems like the Wind Estimator in Airspeed selector is only doing âsideslip beta angle fusionâ, and not the âairspeed fusionâ, why is that?

2. We have different wind prediction mechanisms (one in airspeed selector, and one in EKF2), could we not merge these two? Why did we have them separated?

1. EKF-GSF Yaw Estimator, which is âcrucialâ for the heading estimate, which in turn also affects the wind estimate (in EKF2 and Airspeed Selector-Wind Estimator), does not really utilize any of the âwind estimateâ. Why is that? How are we suppose to really estimate the yaw confidently when we donât acknowledge the presence of wind (since we are taking in inertial velocity data)?

I am especially wondering how trust-worthy the EKF-GSF output is. Can we trust it enough to then propagate itâs estimate (heading), which then affects wind estimate, then the airspeed estimate? Or, are we just piping the data around in our own algorithms, and can end up in a non-sensical heading / airspeed estimate?

1. Could we improve the EKF-GSF perhaps by utilizing wind information?

2. How is EKF2âs wind estimated? How reliable is it? Does it consider the vehicle specific characteristics (e.g. fixed-wingâs coupling between heading and relative airspeed)

Overall, Iâm just wondering if the pipeline is ideal, and whether it can be improved for the fixed wing purposes (where the coupling between airspeed / relative airspeed / heading are more relevant than in multicopters case).

## More thoughts

The core of the question lies in the following phrase:

Given the inertial velocity (IMU + GPS) and attitude (IMU) estimates, can we accurately guess the heading and airspeed correctly?

And collecting opinions from various sources, it leads me to believe that heading & airspeed estimate probably wonât be accurate, and they can possibly end up in completely non-sensical values, which will lead to uncontrolled aircraft (e.g. like toilet bowling in multirotors when heading estimate is off).

### Another way of getting heading estimate?

However, I also think that in a small time horizon (e.g. 10 ~ 20 seconds), by yawing the fixed wing significantly (e.g. 30 degrees), we can probably get a very good heading & airspeed estimate, assuming that wind stays almost constant, by fitting the circle in the inertial velocity estimate XY plot.

But Iâm not certain if this logic is considered already in either EKF2âs wind prediction or Wind Estimate (sideslip) in Airspeed selector. I would love to hear some thoughts!

### Using a magnetometer?

So far, I have excluded usage of the magnetometer, as I wanted to reduce the complexity / probability of failure of the system as much as possible (as magnetometers are known to be a tricky sensor to calibrate & may not provide good heading at times).

However, Iâm wondering if using a magnetometer would in fact enhance the estimate, or make it more error prone. From the industry, I gather that magnetometer should never really be fully trusted as a heading source (as there are so many other disturbances that can affect the reading), but also Iâm open for some new suggestions

### Other

There is one WindEstimator instance using sideslip only plus one instance per airspeed sensor (encapsulated it AirspeedValidator. The instance with sideslip only is there to detect a failure of the airspeed sensor.

They both have pro and cons. In EKF2, having the airspeed estimate as a state allows us to extend out inertial dead-reckoning in fixed-wing through the airspeed fusion and allows multirotors to estimate wind using a drag model. The standalone wind estimator on its side is not directly coupled with other states so itâs much faster to run and we can create an instance per airspeed sensor which allows us to monitor the health of each of them. It can also estimate the scale factor, which is really useful as most drones have a large scale factor error (adding this to EKF2 would require to add a state, which comes with a high computational cost).

There is no need to know the wind strength not its direction to determine the heading of an object. The yaw estimator is not estimating the course over ground (i.e.: the direction of motion) but the actual heading of the vehicle. It finds it by matching the inertial data with the GNSS velocity measurements, all of this works regardless of the current wind.

The heading provided by the yaw estimator is usually really good as long as the heading is observable (accelerations are required to be observable). The accuracy can also be decreased while flying really long coordinated turns, but this can be counteracted by using an airspeed sensor. The estimate doesnât depend on the wind, so it wonât be affected by a bad wind estimate.

Not at all, as said above, the wind doesnât enter in the equation at all.

Same as for the standalone wind estimator: airspeed fusion and zero sideslip assumption.

Thanks for the info! I definitely wasnât aware that EKF-GSF Yaw Estimator is using mainly the detected acceleration and interpolate that to match the inertial velocity changes (aligned via estimating the yaw), so it is indeed not affected by wind easily!

### Calculations workflow

Then, also considering absence of airspeed sensor, it seems like the magnetometer & airspeed sensor-less fixed wingâs guidance will happen like following:

1. EKF-GSF Yaw Estimator provides yaw estimate from IMU acceleration & inertial velocity measurements (as we donât have magnetometer)
2. Airspeed selectorâs Wind Estimator calculates the wind velocity estimate
3. Airspeed selector calculates Airspeed from inertial velocity - wind velocity (as we donât have airspeed sensor)
4. EKF-GSF Yaw Estimator then uses that updated Airspeed estimate to come up with better yaw estimate (and the cycle continues). However, as noted below, this is actually not the case as it gets reset to EKFGSF_tas_default parameter value.

And on the side, EKF2 utilizes that estimated airspeed (but only when real airspeed sensor is present, check comment below) to calculate itâs own wind velocity estimate (and has itâs own airspeed estimate, which isnât published).

## Further discussions

### Wind estimator sideslip

It seems like the wind estimator in airspeed selector seems to be only related to providing the wind velocity estimate, which gets used in estimating airspeed by using inertial velocity. Hence, I couldnât find part where it âdetects the failure of airspeed sensorâ, which part would correspond to that?

### EKF2 not considering ground speed - wind speed valid

It seems that EKF2 will actually not push the âairspeed_validatedâ data into airspeed sample queue when the âselected_airspeed_indexâ is 0 (Airspeed deduced from Ground speed - Wind speed), leading to âestimator_status_flags/cs_fuse_aspdâ being set to false, as thereâs no valid airspeed data to fuse.

And as you stated in the PR ekf2: use validated airspeed from airspeed sensor only by bresch Âˇ Pull Request #20293 Âˇ PX4/PX4-Autopilot Âˇ GitHub, it is to remove the circular dependency (I guess what you meant was this causing changes in EKF2âs wind estimate, thus indirectly affecting the other EKF2 states, which gets used for airspeed estimate via ground speed - wind speed?)

### EKF-GSF Yaw Estimator not getting real time airspeed estimate

As noted above, currently the âestimator_status_flags/cs_fuse_aspdâ is set to false (donât fuse airspeed), which then triggers condition to not set the estimated airspeed to EKF-GSF yaw estimator:

This means that only having an actual airspeed sensor would allow EKF-GSF yaw estimator to have estimated airspeed piped through properly, which I believe would lead to sub optimal behavior, as we can have varying airspeed in fixed wing.

## Questions

1. Whatâs the risk of reverting that circular dependency prevention commit (and thus enabling EKF2 airspeed fusion, allowing yaw Estimator to use ground speed - wind speed based airspeed estimate)? Could the airspeed and wind estimate reach non-sensical value?

The module that contains it all is called âairspeed selectorâ. It contains one âairspeed validatorâ per airspeed sensor, which in turn each contain one âwind estimatorâ. The checks are then run for each airspeed validator instance, see https://github.com/PX4/PX4-Autopilot/blob/6bd13c551498d9701ffc92f88e9dbf1425820220/src/modules/airspeed_selector/AirspeedValidator.cpp#L214

Fusing the airspeed_validated in case that the source is not an airspeed sensor wouldnât give the EKF any new data, as in that case the airspeed_validated was just constructed using position and heading (which are already fused into the EKF).

Hope that helps already, for all the GSF stuff @bresch is the better person to answer.

1 Like