Skip to content

AOA indicator example

12 January, 2015

In response to some guy from the .org forums, who wants to build an AOA indicator. It’s dead easy. I’d always recommend going through PJRC’s Teensyduino tutorial before doing anything with X-Plane, as it is fun and teaches you most of what you need to know to build hardware for X-Plane.

1: Plug in your Teensy, launch the Arduino IDE, and load the ‘blink’ example sketch – as described in the tutorial. It’s always good to start by doing this; it confirms the board is working and that you can upload code to it, and gives you a blank slate.

2: Wire up some LEDs to the Teensy. Pick three arbitrary I/O pins – these are the ones which have a number on the pinout diagram (e.g. not “GND”, “+5V”, “AREF” etc). Wire them to ground using a resistor – again as described in the tutorial.

IMG_20150112_135353

I’m using a Teensy 2.0++ and arbitrarily picked pins 13, 15, and 17 for orange, green and red.

3: In the Teensy IDE, in the Tools menu, set USB Type to “Flight Sim Controls”. (This is necessary to communicate with X-Plane later on.) You’ll already have the right board type selected, as otherwise you wouldn’t be able to run the Blink example.

4: First we’ll make a sketch which just turns the LEDs on and off, to prove we can and that the physical stuff is wired up correctly.

/*
AOA Indexer example
*/

// Indexer LED pins: 
const int Amber = 13;
const int Green = 15;
const int Red = 17;

void setup() {
  pinMode(Amber, OUTPUT);
  pinMode(Green, OUTPUT);
  pinMode(Red, OUTPUT);
}

void loop() {
  // just test the LEDs light up OK.
  digitalWrite(Red, LOW);
  digitalWrite(Amber, HIGH);
  delay(1000);
  digitalWrite(Amber, LOW);
  digitalWrite(Green, HIGH);
  delay(1000);
  digitalWrite(Green, LOW);
  digitalWrite(Red, HIGH);
  delay(1000);
}

You should see merry little blinkenlights.

5: Let’s look around the datarefs for angle-of-attack information. The easiest way is to search the SDK dataref page, which turns up sim/flightmodel2/misc/AoA_angle_degrees and not much else. This is unfortunate – we’ll have to simulate the behaviour of the indexer on the Teensy. Ideally, X-Plane and its plugins determine exactly when the lights should be on or off (including other factors, such as electrical power, failures, is the system turned on etc) and all the Teensy needs to do is make the LEDs go on and off to match. But in this case, with only the AoA angle to go on, we’ll simulate the indexer in code on the Teensy.

6: This page about AoA indexers suggests the indicator should show green between 11 and 15 degrees, with amber for less than 11 and red for greater than 15. So now we’ll extend the code to do the same:

/*
AOA Indexer example

"The angle of attack indexer is used during final approach to
landing. In order to land the aircraft correctly, your angle of
attack should be between 11 and 15 degrees. At these AOAs, the
green circle on the indexer will be lit up. If your AOA is below
11 degrees, the amber symbol will be lit up, and if it is above
15 degrees, the red symbol will be lit up (and you are getting
close to stalling)."
*/

// Input dataref from X-Plane:
FlightSimFloat aoa_degrees;

// Indexer LED pins: 
const int Amber = 13;
const int Green = 15;
const int Red = 17;

void setup() {
  aoa_degrees = XPlaneRef("sim/flightmodel2/misc/AoA_angle_degrees");
  
  pinMode( Amber, OUTPUT );
  pinMode( Green, OUTPUT );
  pinMode( Red, OUTPUT );
}

void loop() {
  FlightSim.update();
  
  if( aoa_degrees < 11 ) {
    digitalWrite( Amber, HIGH );
    digitalWrite( Green, LOW );
    digitalWrite( Red,   LOW );
  }

  if( 11 <= aoa_degrees && aoa_degrees < 15 ) {
    digitalWrite( Amber, LOW );
    digitalWrite( Green, HIGH );
    digitalWrite( Red,   LOW );
  }

  if( 15 <= aoa_degrees) {
    digitalWrite( Amber, LOW );
    digitalWrite( Green, LOW );
    digitalWrite( Red,   HIGH );
  }
}

This works! Flying in the XP10 F-4, it matches the AoA indicators next to the HUD. However,  when parked and with a tailwind, the lights flicker annoyingly as the AoA passes from -179 to +179 degrees. Probably the best thing to do is to get the airspeed dataref and only light the LEDs when the airspeed is above, say, 50kts, but here it’s much simpler to put a lower limit on the amber and an upper limit on the red lights:

/*
AOA Indexer example

"The angle of attack indexer is used during final approach to
landing. In order to land the aircraft correctly, your angle of
attack should be between 11 and 15 degrees. At these AOAs, the
green circle on the indexer will be lit up. If your AOA is below
11 degrees, the amber symbol will be lit up, and if it is above
15 degrees, the red symbol will be lit up (and you are getting
close to stalling)."
*/

// Input dataref from X-Plane:
FlightSimFloat aoa_degrees;

// Indexer LED pins: 
const int Amber = 13;
const int Green = 15;
const int Red = 17;

void setup() {
  aoa_degrees = XPlaneRef("sim/flightmodel2/misc/AoA_angle_degrees");
  
  pinMode( Amber, OUTPUT );
  pinMode( Green, OUTPUT );
  pinMode( Red, OUTPUT );
}

void loop() {
  FlightSim.update();
  
  if( -45 <= aoa_degrees && aoa_degrees < 11 ) {
    digitalWrite( Amber, HIGH );
    digitalWrite( Green, LOW );
    digitalWrite( Red,   LOW );
  }

  if( 11 <= aoa_degrees && aoa_degrees < 15 ) {
    digitalWrite( Amber, LOW );
    digitalWrite( Green, HIGH );
    digitalWrite( Red,   LOW );
  }

  if( 15 <= aoa_degrees && aoa_degrees < 45 ) {
    digitalWrite( Amber, LOW );
    digitalWrite( Green, LOW );
    digitalWrite( Red,   HIGH );
  }
}

When you’ve got the blinkenlights working happily, the next step is to build some kind of enclosure and take this off the breadboard – but I’ll leave that as an exercise for the reader!

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s