FlightGear (to be completed)

Input from a Potentiometer

Let's say you want to control FlightGear's throttle with Arduino. You need a sensor that can measure variable values within a certain range. A slide potentiometer would be usefull for that. We'll start with that now. It's cheap and easy to handle.
There are lots of more complex and less cheap sensors out there in the market. We'll investigate them later on.


Wiring Arduino and the Input Sensor

Find a slide potentiometer, maybe a 10KOhm one (higher values will be good too if you're not looking for top performances and high precision), a few cables and connect it to Arduino like that:

We're going to mimic the "Analog Read Serial" tutorial since that's all we need. Read the details here: http://arduino.cc/en/Tutorial/AnalogReadSerial

That's basically a voltage divider, the potentiometer splits the 5V in two. The middle pin senses a voltage proportional to the wiper position.
Arduino translates this voltage into a digital value with its internal ADC (Analog to Digial Converter) returning to the programmer a value between 0 and 1023 (Arduino's ADC has a 10bit resolution).

We're going to use this measured value to control FlightGear's throttle position.


Attribute Values: Throttle

How do we change the throttle position in FlightGear? Simply by changing its attribute in the property tree. Let's see how.

Start up FlightGear without worrying about any serial connection right now. Choose a simple aircraft like the C172 which has only one engine.
From the Main Menu on top choose Debug -> Browse Internal Properties. A window will open up, that's a browser that lets you inspect (and update) FlightGear's property tree.
Dive into the /controls/engines/engine node, you'll finally see the throttle node, it's zero when you start FlightGear, and it can be increase up to 1.

Notice it's a "double" (consider that like a "float" value as of now).
This is a "normalized" property, i.e. its values are in the 0..1 range. You'll see many properties are normalized inside FlightGear. To any normalized property, 0 and 1 are its extreme values; 0 generally meaning min/empty/start and 1 generally meaning max/full/end.

All we need to do now is to make Arduino send a normalized value over the serial line, make Flightgear read it and assign it to /controls/engines/engine/throttle property.


Remapping Arduino's analog reading.

....


Wiring Arduino and the Input Sensor

....


Coding Arduino

As usual, very basic stuff. Copy this code inside the Arduino IDE; compile it and upload it to your Arduino board.

  1. /*
  2.   FGFS Slide Potentiometer Input
  3.   Reads an analog input on pin A0, prints the result
  4.   to the serial port
  5.  
  6.   This example code is in the public domain.
  7.  */
  8.  
  9. void setup() {
  10.   Serial.begin(9600);
  11. }
  12.  
  13. void loop() {
  14.   int sensorValue = analogRead(A0);
  15.   Serial.println(sensorValue);
  16. }

The sketch is reading Arduino's pin A0 analog input and sending the value over the serial line.

Open up the Serial Monitor and check what happens while moving the slider in opposite directions.


Making FlightGear listen to the serial input

...


Writing an Input Protocol File

...


Starting FlightGear

...


Side notes

...

Share