All About AHRS - cyoung/stratux GitHub Wiki

What AHRS Provides

Enabling AHRS on your Stratux will provide the following data to your EFB (not all EFB's use all data):

  • Roll, Pitch, Heading
  • Slip/Skid
  • G-Load
  • Rate of Turn
  • Pressure Altitude
  • Rate of Climb

In a future release:

  • Magnetic Heading

The attitude indicator and G-meter on the GPS/AHRS page will also be enabled if you don't have an EFB that uses AHRS information.

(If you don't have an IMU, Stratux will still send "pseudo-AHRS" pitch, yaw and roll. These are derived purely from the GPS. They will lag your actual attitude, and the pitch information is not very good.)

EFB Support

App Roll, Pitch Slip/Skid G-Load Rate of Turn Magnetic Heading Pressure Altitude Rate of Climb
Stratux UI Yes Yes Yes Yes No Yes No
iFly GPS Yes No No No Yes No Yes
DroidEFB Yes Yes No No No No No
FlyQ Yes No No No No No No
ForeFlight Yes No No No Unsure, needs flight test N/A Yes
Airmate (iOS) Yes Yes Yes No No No Yes

Note on ForeFlight's pressure altitude: Some iPads, such as some Minis, have a built-in barometric pressure sensor. ForeFlight is capable of determining pressure altitude from this sensor, so I am not sure whether the pressure altitude display I see on my iPad is from the iPad's sensor or from Stratux.

(Please add known support for other EFB's. EFB authors: ask on the Slack #ahrs channel if you'd like to add support for another feature!)

Requirements

All that is required to enable AHRS on your Stratux is to add a Stratux AHRS board (IMU, or Inertial Measurement Unit). You can just plug these in directly. You can also buy a bare MPU9250 board from SparkFun, AdaFruit, etc. if you want to do a little soldering.

GPS is also required for AHRS.

MPU9250 Pinout:

MPU-9250 Pin Raspberry Pi Pin
VDD Pin 01
GND Pin 06
FSYNC Pin 09
SDA1 Pin 03
SCL1 Pin 05

If you would also like to calculate pressure altitude and rate of climb, you can add a Bosch BMP280 Pressure Sensor. Most of the boards containing the MPU9250 will also contain a BMP280. The pinout is similar to the above, but you should connect to SDA2/SCL2 instead if you have a separate board.

AHRS is still in beta but has been merged into the Stratux master branch as of 1.4r1.

Setup

Mounting

Before firing up your Stratux with AHRS for the first time, give some thought to how you will place it in the aircraft.

One axis of the Stratux (assuming the IMU is mounted squarely inside the Stratux) must be pointed toward the nose of the airplane as nearly as possible. It should be turned left/right as little as possible (up to about 5° should be fine). It can be tiled up or down up to 30° or so.

I have done most of my flights with the Stratux placed on my glare shield. This is fine as long as you don't expect to hit any turbulence that could shift it around - if it shifts in flight, it will lose its orientation information and you may have to re-level.

It is recommended to semi-permanently mount it somewhere, perhaps with velcro, so that it can't shift around.

Here's how I usually place my Stratux in my airplane:

Orientation Procedure

In order for the AHRS to work properly, you must tell the AHRS algorithm how it is oriented in the aircraft. It needs one piece of information: which sensor axis is pointed forward.

In order to tell the AHRS algorithm which axis you intend to point forward, you have to go through an Orientation procedure. This procedure uses gravity (which the sensor can measure) to identify the axis that will be pointed forward.

Once you have decided how you will place (or mount, if semi-permanently mounted) the Stratux in the airplane, then start up your Stratux, go to the Settings page and press the "Set AHRS Sensor Orientation" button. (If this button is disabled, check that your "Attitude Sensor" toggle is enabled.)

A dialog box will be shown telling you to hold the Stratux with the end that will be pointing in the direction of flight pointed straight up. Do this, and then press the "Set Forward Direction" button.

You are then asked to place the Stratux in the position it will be in during flight and press the "Done" button.

Don't press the "Done" button until it is stationary as it will run a calibration process to determine which direction is level once you have pressed "Done"! Don't worry if you are doing this at your desk and not in the airplane--you can set off this level calibration process manually later. In fact, it is best to play around with it at your desk before putting it in the airplane anyway.

You should only have to perform this Orientation procedure once, when you first set up your Stratux for AHRS, or if you decide to mount/place it in a different orientation in your aircraft. It is not necessary to do this before every flight.

TODO: Link to a video of the orientation process.

Level Procedure

The Level procedure is akin to "Caging" or leveling a mechanical attitude indicator. It needs to be done any time you reposition your Stratux, if the CG or weight changes substantially, or if you are flying at an unusual airspeed (slow flight, possibly approach speeds if you last leveled at cruise), just like with a mechanical attitude indicator.

The Level procedure is kicked off by pressing the "Reset/Level" button just under the attitude indicator on the GPS/AHRS page of the web UI. You should only press this button when the airplane is in level flight, just like caging a mechanical attitude indicator. Don't press it in a turn or a climb! Once you press it, the attitude indicator will be replaced by a large red X for one second as the sensors gather data to average, and then it will display the new level.

From now on, pitch and roll will be defined relative to this new level.

Eventually, the Stratux may auto-level, so this process may be removed.

Calibration Procedure

Finally, the major challenge for providing AHRS with consumer sensors like the MPU9250 is that their gyros have a substantial zero bias. In other words, even when the sensor is sitting still, its gyros will think you are turning somewhat around all three axes. When you first powered up your Stratux, it took some preliminary calibration measurements to be able to zero out this bias. However, as the temperature of the IMU chip changes, the biases will change too. You may want to re-calibrate the gyros after your Stratux has been turned on for an hour or so.

To manually re-calibrate the gyros, press the "Calibrate Gyros" button on the Settings page. Be sure the Stratux is as stationary as possible for at least one second after pressing this button, or you will get bad calibration data (or no data at all if the algorithm decides you were moving it too much).

If in flight the attitude indicator doesn't seem to want to keep a level even though you just pressed "Reset/Level", it is probably because the gyro zero bias has changed too much. If this happens, just find some still air and press this button while holding the aircraft as steady as possible.

Eventually, the Stratux may auto-calibrate, so this process may be removed.

How well does it work?

I and others have performed numerous flight tests. Under most circumstances it performs comparably to my certified Aspen. Pitch and roll are usually accurate to within 2 degrees or so and there isn't much lag.

I have found that at extreme pitches (20 degrees or more) it can deviate a bit more, by maybe 5 degrees.

Pitch, roll and slip/skid seem to indicate quite well even in uncoordinated flight.

Because the algorithm assumes that your direction of flight is along the nose of the airplane, it may start to show some errors at low airspeeds with high winds (especially crosswinds), or in very severely uncoordinated flight such as a spin. My recommendation: if you enter an inadvertent spin, don't stare at your tablet! Follow the POH recovery procedure.

TODO: link to video of performance during typical maneuvers.

How the AHRS Algorithm Works

AHRS with consumer sensors is not easy. This is mainly due to the aforementioned gyro drift. Because of this drift, attitude cannot be calculated purely based on gyro data. It must be supplemented by some other data.

This AHRS algorithm is what I call a Simple AHRS algorithm. The best AHRS algorithm would use an Extended Kalman Filter to fuse all the available data. The Simple AHRS algorithm fuses the data in a more heuristic manner.

In a nutshell, the Simple AHRS works by first calculating what your attitude should be based on the IMU's gyro readings. It then calculates a second attitude to confirm or correct this initial gyro-based estimate. This second estimate is obtained by matching up the GPS-derived speed with the forward sensor axis, and the GPS-derived acceleration with the acceleration measured by the Stratux.

These two estimates both have strengths and weaknesses.

The first (gyro-based) estimate responds very quickly to control inputs--it has very little lag. It is also very accurate over short timescales. However, due to the changing gyro bias, over longer timescales (possibly only a few seconds if the gyro calibration is way off), it will drift so much that it will be completely off.

The second (GPS+accelerometer-based) estimate responds with a lag. The GPS itself has a bit of lag, and then calculating a change in speed (i.e. an acceleration) from the GPS data introduces a further lag. The accelerometer itself has very little lag, at least. Howver, this estimate cannot be too far off from your actual attitude, even over long timescales. (Note: in a spin, or any flight condition in which your velocity is not pretty close to the nose of the airplane, it will be wrong.)

So these two attitude estimates have complementary strengths and weaknesses, and can be combined to give a pretty good estimate of your actual attitude. Under most circumstances, the reported attitude will be based mostly on the first (gyro-based) calculation. However, if the two methods differ too much, the second calculation takes over. The end result is an attitude that shouldn't be off by very much, yet responds very quickly.

Work is in progress on a EKF-based approach. I initially wrote the AHRS algorithm based on an EKF, but found it a bit too difficult to troubleshoot and get parameters right. Also, just the integration of the AHRS code with Stratux has been a very big job. With this Simple AHRS solution working pretty well and the experience gained from developing it, a Kalman-based approach should be easier to implement.

Disclaimer

This AHRS will not save your life.

I was partially motivated to develop this software due to losing my vacuum pump-driven attitude indicator system (including standby pump within an hour each time!) no less than three times over the course of 2700 hours of flying. The last time, at night over the Egyptian Saharan desert, I at least had a clear sky above (there was oftentimes not a single light in the desert below). My autopilot was also driven by the attitude indicator, so I had to both keep upright and hand-fly through the pitch black for hours.

Fortunately, this last time I also had a MidCon LifeSaver electrical backup. Even surrounded by inky blackness above and below, with no horizon visible outside, between the stars above and the MidCon certified backup, I was able to continue without any loss of situational awareness. However, the thought crossed my mind many times as I flew on through the dark for hours that the MidCon was my last and only backup. If I had to do an instrument approach, I would be partial panel. I would really have loved to have had at least one potential additional and fully independent backup system, if only to provide me some comfort and an independent check for my partial panel flying.

It goes without saying that a self-built attitude indicator system that can potentially be thrown willy nilly up on the glareshield, in a severely uncontrolled environment, and running software that has never been certified by any independent agent should not be relied upon in any but the most dire of circumstances. Even then, you would be very wise to fly partial panel on certified instruments and use any such system as this only as a cross-reference.

If this software ever serves just to provide some comfort to a pilot in an event such as I experienced, it will have served its purpose. Its purpose is not to save your life.