Howto:Build and run FlightGear on Raspberry Pi 4
It is now possible to run FlightGear on a Raspberry Pi, starting with the model Pi 4. The objective of Build and run FlightGear on Raspberry Pi 4 is to introduce Pi users to FlightGear and possibly FlightGear useres to the Raspberry Pi family. One of the main objectives of the Raspberry Pi is education. Hopefully this marriage will introduce some young programmers to FlightGear. Although this will mainly deal with the Pi 4, other models may find applications in the area of flight panels and instruments, hence FGPanel.
Use the below commands to update your Raspberry Pi:
sudo apt-get update sudo apt-get full-upgrade
Do not use the below update command unless you know how and why to use it. This command will install experimental software that has a good chance of breaking your operating system. It is like flying into a thunder storm cloud.
sudo rpi-update (DO NOT USE)
You will find that controlling your aircraft, with the official Raspberry Pi keyboard and mouse, too be rather difficult. A joystick will solve this problem. The Logitech Extreme 3D PRO is plug and play, for the most part, with FlightGear. Most modern joysticks should also work. There is a dialog box to assign common joystick controls, in FlightGear. Controls are also properties, however that is for later. This joystick dialog box is found in the top menu bar under 'Files'. Next you will find 'Joystick Configuration' to click on and that will bring up the desired dialog box.
If the joystick’s travel is not being used efficiently or the neutral dead band is not right, the joystick can be calibrated. Install jstest-gtk through the Raspbian software installer or use the terminal and apt-get install command.
sudo apt-get install jstest-gtk
After running jstest-gtk click on your joystick within the jstest-gtk window. Next click on the 'Calibration' button. The calibration can be performed within this dialog box. Consider making note of these values before performing the calibration. Do not forget to cycle the hat switch that is on top of the stick. This is because this switch is considered as a proportional input just like the stick axis. In order to save these new settings, after a reboot or new power up, do not close jstest-gtk at this moment. First open a terminal and enter the below command in order to save the new calibration values. The 'device_name' of the joystick is in the first dialog box of jstest-gtk. It will be something like js0, js1 etc.
sudo jscal-store /dev/input/js0
Some or most Linux distributions will need more work to store these new calibration values, in the way of RULES. However, it seems that Raspbian doesn’t require anymore work.
The above calibration may not adjust for any center dead band. Notice that the calibration values are representing binary numbers in that the maximums are in power of two’s. Except where the maximum value is 1 or -1. It is common to see these values close to 512 or 1024. Consider the values below. To find the maximum value add the RangeMin to the RangeMax. For example; 0 + 1024 = 1024. Since this scheme starts with 0, not 1, 1022 or 510 might be the maximum value. The first pair of numbers, not considering the axis number, should add up to the maximum value.
In order to introduce a dead band consider the values below:
Or the values in the calibration dialog box screenshot, entitled "Joystick calibration using jstest-gtk dialog box".
Axis 4 and 5 are examples of the hat switch.
Saitek Saitek Pro Flight Quadrant
This throttle quadrant is now produced by Logitech and works with FG and the Raspberry Pi4. If used with a single engine aircraft or a multi engine aircraft where the engines are controlled with one stick on the quadrant, this will be a plug and play setup. However, there will be a noticeable dead band in the middle of the travel. Furthermore, it is possible that all the usable stick travel is not utilized. Both of these issues can be addressed by calibrating the quadrant as in the joystick example above. Below is the calibration data before calibration and below that is the data after calibration. Notice that the center dead band is removed.
After calibration below:
If this quadrant is used with a multi engine aircraft and each engine throttle is controlled by a separate quadrant lever, the levers will only use half of its travel. In order to resolve this, the joystick configuration file will need a small edit. This file is located in homepi/.fgfs/Input, assuming your user name is ‘pi’. Notice that ‘.fgfs’ is a hidden folder in your Home folder. Only edit the joystick configuration files that are in your Home folder. Do not edit the files that are native to FlightGear. In this example we will be editing ‘Saitek-Saitek-Pro-Flight-Quadrant.xml’.
Let us assume that this configuration is for the twin engine DC-3 Dakota and axis-0 will be assigned to ALL engine mixture levers, axis-1 will be assigned to ‘Throttle Engine 0’ and axis-2 is assigned to ‘Throttle Engine 1’. Note that within this .XML configuration file that <axis> is another way to express <axis n=’0’>. The axis-0 doesn’t need the n=’0’. Find <axis n=’1’> and change the ‘offset’ from 0 to -1 also change ‘factor’ from 1 to -0.5. Do the same for <axis n='2'>.
<axis> <desc type="string">Mixture All Engines</desc> <binding> <command type="string">property-scale</command> <property type="string">/controls/engines/mixture-all</property> <factor type="double">1</factor> <offset type="double">0</offset> </binding> </axis> <axis n="1"> <desc type="string">Throttle Engine 0</desc> <binding> <command type="string">property-scale</command> <property type="string">/controls/engines/engine/throttle</property> <offset type="double">-1.0</offset> <factor type="double">-0.5</factor> </binding> </axis> <axis n="2"> <desc type="string">Throttle Engine 1</desc> <binding> <command type="string">property-scale</command> <property type="string">/controls/engines/engine/throttle</property> <offset type="double">-1.0</offset> <factor type="double">-0.5</factor> </binding> </axis>
Now the Quadrant will move the throttle levers as they should. The levers and props should follow the levers on the Quadrant. However, you might notice that the throttles do not seem to feel like they are independent to each other when taxing or in the air. There is another adjustment to look into and this is the property throttles-coupled='true'(bool).
In this example, the DC-3 Dakota will need a small edit. The file that needs this edit is named ‘controls.xml’ and it's location can be found at /Aircraft/Douglas-Dc3/Systems/controls.xml. The bellow command will be found near the bottom of this file.
The Boolean value 1 needs to be changed to a 0, as in the below example.
Of course the file needs to be saves. Depending where the file is located, permissions might need to be dealt with.
Thrustmaster Flight Rudder Pedals
There could be two adjustments needed for these rudder pedals. The toe brakes are reversed and delete the toe brake center dead band. Use the same method to delete the dead band as in the above throttle quadrant. Do not delete the dead band for the rudder unless that is what you want to do. Below is a calibration data example:
Reversing the toe brake direction in FlightGear, using it's joystick dialog box, does't work. The easiest method is to reverse them using jstest-gtk and check the invert box for axes 0 and axes 1.
Depending on the version of FlightGear, there could be a bug where one of the toe brakes do not show up in the FlightGear joystick dialog box. If so this is easy to edit in the configuration file. It might also be beneficial to delete controls that are not part of this rudder pedal so not to produce any conflicts. See below:
<name type="string">Thrustmaster T-Rudder</name> <axis> <desc type="string">Brake Right</desc> <binding> <command type="string">property-scale</command> <property type="string">/controls/gear/brake-right</property> <factor type="double">0.5</factor> <offset type="double">1</offset> </binding> </axis> <axis n="1"> <desc type="string">Brake Left</desc> <binding> <command type="string">property-scale</command> <property type="string">/controls/gear/brake-left</property> <factor type="double">0.5</factor> <offset type="double">1</offset> </binding> </axis> <axis n="2"> <desc type="string">Rudder</desc> <binding> <command type="string">property-scale</command> <property type="string">/controls/flight/rudder</property> <factor type="double">1</factor> <offset type="double">0</offset> </binding> </axis>
A much more in-depth study of joystick programming can be found at the below link:
|Package||Version (ref. only, as of 03-28-2020)||Notes|
|git||1:2.20.1-2+deb10u1||Needs a user account at www.github.com|
When running FlightGear, using the full screen option, 1024 X 768 resolution works well. Possibly because this is FlightGear's native resolution. In order to choose this resolution go to the Raspbian program menu 'Preferences' and run 'Screen Configuration'. Now right click on the screen that needs to be adjusted to 1024 X 768, on the Screen Layout Editor seen to the right. If using two screens, it might be best to set both screens to the same resolution. Also, it is best to have the two HDMI boxes touching so that the mouse cursor doesn't have a dead spot. Click on the green check to finish.
Expanding the flight simulator system beyond the primary Raspberry Pi4, that is running FlightGear, is one way to increase the computing power of such a small computer.
Avare is a free aviation app, with no ads, that works well with FlightGear. It is an app that is used by many pilots. It will provide a moving map of the FlightGear aircraft, using all FAA charts and a lot more. These charts are for the USA, however some of these FAA Charts cover Puerto Rico, plus parts of Canada, Mexico and the Caribbean. For other parts of the world, there are other apps that might work. Avare can be downloaded from Google Play Store. A tablet is a good choice for running this app.
FlightGear and Avare are easy to bind together. Along with the main Avare app, the I/O app will also need to be installed on the tablet. This app is ‘Avare External I/O Plugin’. The scheme is that the Raspberry Pi4 and FlightGear will become the GPS signal used by the Avare app, this position is transferred via WiFi. So, the tablets internal GPS needs to be OFF. Avare will always prompt you to turn ON the internal GPS, so when asked to ‘Turn On GPS’, choose ‘No’. In ‘Preferances’ the GPS position source can and should be set to ‘Avare IO Module Only’, however the prompt to turn ON the internal GPS will still pop up when starting the app.
The below command tells FlightGear what to connect to and it's protocol. This can be placed in the GFly type programs or if in Terminal, place the command after fgfs. The address, 192.168.??.?, needs to be the address of the tablet running Avare. Some home networks will randomly choose an address, hence this could change. It will be displayed in the IO app. The number 49002 needs to be the same number that is in the Avare IO app. Use the Xplane option.
|Comm||Comm Type||Direction||Hertz||Machine Address||Port||Style||Protocol|
The table above helps to explain the command line below.
After FlightGear has started with the above command, open the Avare External I/O Plugin app. Choose the Xplane option and then tap on ‘Listen’. There should be lines of communication being displayed after ‘Listen’ is enabled. Leave this running and now open the main Avare app. Do not choose to use the internal GPS. Now your FlightGear aircraft placement should be displayed on the FAA map of choice.
Official 7" Touch Screen
There is the Official 7” Touch Screen for the Raspberry Pi. This screen will work with a number of different models of the Raspberry Pi’s. There is a case for it (there is no Official case) and the Pi, however the new Pi4 doesn’t fit this case, seen in the photo at the right. This combination does resemble a modern aircraft instrument. There is a new case that will fit the Pi4 and other models, SmartPi Touch 2.
Phi will work with almost any device with a browser. In this example the Touch Screen is used with a Raspberry Pi3 B+. There is a screen touch keyboard, however only the numeric keyboard is needed to operate the Radio Stack and the full keyboard doesn’t make efficient use of the screen area. To the right, an external numeric keypad is being used. It makes an interesting combination to touch on screen hot spots and use the external keyboard to input the radio frequencies. A numeric touch screen keypad is being looked into.
Pass the below command to FlightGear, during startup, using your favorite method:
In the browser address bar, the one with the 7” Touch Screen, type the below address. Replace the '??' with your numbers. This address needs to be the address of the Raspberry Pi4 that is running FlightGear. Some home networks randomly assign addresses, so when launching FlightGear it is good practice to check the address. To easily find this address, place the mouse cursor on the WiFi/Network icon that is on the top menu bar. It is to the far right.
In order to adjust the screen brightness use the below command to write a value into the brightness file. Adjusting the number ‘128’ to a lower value will reduce the brightness of the screen.
sudo sh -c ‘echo “128”>/sys/class/backlight/rpi_backlight/brightness’
Other, less expensive, models of Raspberry Pi’s should also work. As long as it has the port for the Official Touch Screen and can run a browser. There are also third party touch screens on the market. However, purchasing official Raspberry products help to support the Raspberry Foundation promote computer education. Hopefully some of the young budding computer scientists will find value in FlightGear!
The video core GPU temperature can be read with the use of the terminal and the below command:
The Raspberry Pi4 starts to throttle at 80c, and will be fully throttled when it hits 85. When flying the DC-3 Dakota at a steady cruse altitude, in a low scenery dense area, the core temperature was reported to be ~75c. This was with ambient temperature of ~24c. The temperature rapidly dropped to ~45c when the cooling fan was energized. There was no heat sink installed for this test. FlightGear was running in fullscreen mode on monitor 1 and terminal was running on monitor 2. Screen resolution was possibly 1024 x 768.
The fan in the photo is a Noctua NF-A4x10 5V. It is installed with two rubber bands forming an X. Then the fan is simply sandwiched in the middle of the X. The ends of the rubber bands are looped over the ends of the four standoffs. The rubber bands, in addition to holding the fan, help to isolate vibrational noise. In this setup the fan was powered by an orphaned cell phone charger.
There are also inexpensive heat sink kits. Some opt for no after market cooling options at all, however it has been reported the the Pi4 will self cool the best when placed/mounter in the vertical direction.
For casual running of FlightGear, a quality SD card works well. Look for Class A1 cards. The 'A' is for applications. In addition to a write speed of 10MB/s, these support at least 1500 read operations and 500 write operations per second. Do not use cheap fake SD cards. Interestingly, there is a new tool to test your SD cards. This new tool is called agnostics and can be installed with the below commands:
sudo apt update sudo apt install agnostics
To learn much more about the SD cards and agnostics, see the below link: