กลับไปหน้ารวมไฟล์
flightgear-analog-trim-tab-wheel-a1d4ae-en.md

Connecting Arduino to FlightGear is nothing new, but I've found that wikis are outdated and forums give precious hints where you have to work around.

The idea was to have a nice, cheap and compact analog command to control the elevator trim tab wheel of an aircraft in FlightGear. The wiki works until the communication part. Strictly speaking, you cannot directly use serial communication to pass commands from Arduino to FlightGear. You have to workaround with Python to send packets via UDP.

What is a trim wheel? It is an analog device to control the deflection of the trim tab, which is an aerodynamic device to keep a control surface (in this case the elevator controlling the aircraft pitch) in a given position without effort from the pilot. From wikipedia:

Trim tabs are small surfaces connected to the trailing edge of a larger control surface on a boat or aircraft, used to control the trim of the controls, i.e. to counteract hydro- or aerodynamic forces and stabilise the boat or aircraft in a particular desired attitude without the need for the operator to constantly apply a control force. This is done by adjusting the angle of the tab relative to the larger surface.
Trim wheel on a Cessna 172 aircraft. By I, BenFrantzDale, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=2278643

Additional requirements for this project: python with the libraries serial, socket, and sys installed. Assuming that Anaconda has been installed, the missing libraries can be retrieved with Anaconda prompt by typing:

>>> conda install -c anaconda pyserial

the same with serial and socket. Search on the internet for an appropriate package, usually the most downloaded for your platform are good. Once you have python with these libraries (and, of course, FlightGear installed) you may move to the next section.

There are three code scripts: an Arduino sketch, a python executable script, and an XML script. The Arduino sketch must be loaded on your board. The python script must be executed to enable communication between Arduino and FlightGear. The XML script is a FlightGear generic protocol that must be moved to <FlightGearRoot>/data/protocol once for all.

The Arduino sketch requires the U8glib library. As mentioned in the comment, adjust the sketch's line 2 with your display:

#include <U8glib.h>
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI

See U8glib examples and documentation. The sketch should work even without a display, so you may play without visual feedback from your board.

If you are unhappy with direction of rotation, just switch the position of the last two arguments in the following map instructions

w = map(p,0,1023,100,-100);
m = map(p,0,1023,90,0);

so that the values of the potentiometer go from -100 to 100 and the needle's gauge goes from 0 to 90 (this is a trick to draw the needle in the correct position, try yourself if you are curious).

The python script includes the host address and the serial port number. The host should be "localhost" (if it doesn't work, try with 127.0.0.1), the port any (maybe it is better one not in use by other applications, I don't know), the serial port where your board is connected may be read from the Arduino IDE. In my case, it is "COM4". Note: if you test the Arduino with the serial monitor, you may have to disconnect and re-connect your board before executing the python script in order tomakeit work properly.

host = "localhost"
port = 21567
#buf = 1024
addr = (host,port)
UDPSock = socket(AF_INET,SOCK_DGRAM)
tty="COM4"
print("tty is ", tty)

The python script may be located anywhere. You may execute it from the command line of your operative system. In my case (Windows), I type in the command prompt:

python c:\\path\\to\\file\\arduinoElevatorTrim.py

This may be launched before or even after starting FlightGear.

Finally, as previously stated, the XML script must be moved once for all in the protocol folder of your FlightGear installation. Now you are ready to go. Launch FlightGear with your preferred mode (command line or launcher) by adding the following command (no space between chars!):

--generic=socket,in,30,localhost,21567,udp,arduinoElevatorTrim

where we are telling FlightGear to apply a generic protocol via socket, read input 30 times per second, on the address localhost, port 21567, UDP protocol, instructions in the arduinoElevatorTrim.xml file. Enjoy your personal trim wheel!

Demo

EXPANDED TECHNICAL DETAILS

Flight Simulator Hardware Interfacing

This project provides a realistic, physical control interface for the "Elevator Trim" function in the FlightGear flight simulator.

  • Analog Input Resolution: Uses a high-precision multi-turn potentiometer. The Arduino maps the rotation to a 10-bit value (0-1023) and sends it to the PC.
  • Serial Interface Bridge: A Python script or the internal FlightGear "Generic Protocol" listens to the Arduino's USB-Serial data and maps it to the simulator's internal property tree (/controls/flight/elevator-trim).

Tactile Realism

  • Physical Feedback: Unlike using a mouse or keyboard, this physical wheel allows pilots to "Feel" the aircraft's trim state, providing a much higher level of immersion and precision for long cross-country virtual flights.

ข้อมูล Frontmatter ดั้งเดิม

title: "FlightGear Analog Trim Tab Wheel"
description: "I wanted an additional analog control in FlightGear - nice, cheap and compact."
author: "dancili"
category: "Flying Things"
tags:
  - "communication"
  - "planes"
  - "games"
views: 11213
likes: 6
price: 2450
difficulty: "Intermediate"
components:
  - "1x Capacitor 100 µF"
  - "1x Jumper wires (generic)"
  - "1x SSD1306 0.96 inches OLED"
  - "1x Rotary potentiometer (generic)"
  - "1x Arduino Nano R3"
tools: []
apps:
  - "1x FlightGear"
  - "1x Anaconda"
  - "1x Arduino IDE"
downloadableFiles:
  - "https://projects.arduinocontent.cc/18a0c20a-3f57-4ac0-8dcf-32fd31c66118.xml"
  - "https://projects.arduinocontent.cc/18a0c20a-3f57-4ac0-8dcf-32fd31c66118.xml"
  - "https://github.com/dciliberti/arduinoElevatorTrimOLED"
  - "https://projects.arduinocontent.cc/c5c544db-c246-4cba-a07e-c0b789cd5da0.ino"
  - "https://projects.arduinocontent.cc/fa53a5ac-3caa-4dc3-ae48-5f7a69db3bba.py"
  - "https://projects.arduinocontent.cc/c5c544db-c246-4cba-a07e-c0b789cd5da0.ino"
  - "https://projects.arduinocontent.cc/fa53a5ac-3caa-4dc3-ae48-5f7a69db3bba.py"
documentationLinks: []
passwordHash: "eec3e65e5ba06e36053ffa112582225011a6367109696d1ced516506c8bfef4a"
encryptedPayload: "U2FsdGVkX180lTvRsDBiJTI1rOdURGKwiBK5lQOHwxIiGZxHYfxZznx+HZryrMSIVWXlV+Iu0uenkgGLDe4e+Whp5WN1MWRVPNciyUWYLNTxhu4AEaKXTrkQCQFVZwyHThmNaukTSu0OUgsYsaOo4w=="
seoDescription: "Build a cheap, compact FlightGear Analog Trim Tab Wheel for better analog control in FlightGear."
videoLinks:
  - "https://www.youtube.com/embed/hvd_2HRwMwk"
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/flightgear-analog-trim-tab-wheel-a1d4ae_cover.jpg"
lang: "en"