https://wiki.flightgear.org/w/api.php?action=feedcontributions&user=Vaipe&feedformat=atomFlightGear wiki - User contributions [en]2024-03-29T12:09:31ZUser contributionsMediaWiki 1.39.6https://wiki.flightgear.org/w/index.php?title=User:Vaipe&diff=113444User:Vaipe2017-12-29T05:52:51Z<p>Vaipe: </p>
<hr />
<div>Interested in homecockpit building.<br />
<br />
[http://wiki.flightgear.org/Howto:Use_Arduino_with_FlightGear Howto: Use Arduino with Flightgear]<br />
<br />
[http://wiki.flightgear.org/Howto:Create_WebPanel_instrument HowTo: Create WebPanel instrument]<br />
<br />
[[IDG-A32X]]<br />
<br />
[http://wiki.flightgear.org/Howto:Multi-computing_FlightGear Howto:Multi-computing_FlightGear]<br />
<br />
[http://wiki.flightgear.org/Howto:Configure_camera_view_windows Howto:Configure_camera_view_windows]<br />
<br />
[http://wiki.flightgear.org/Howto:Use_multiple_screens_under_linux Howto:Use_multiple_screens_under_linux]<br />
<br />
===== Multiple monitors: =====<br />
If you want to use it with the launcher, in defaults.xml you should change <rendering> to <rendering include="YourFileName.xml"><br />
and put the YourFileName.xml in the data folder. This makes sure your file gets loaded on the initial startup.<br />
<br />
https://forum.flightgear.org/viewtopic.php?f=24&t=27716&hilit=split+screen<br />
<br />
https://forum.flightgear.org/viewtopic.php?f=2&t=7368</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=User:Vaipe&diff=113390User:Vaipe2017-12-28T17:15:08Z<p>Vaipe: </p>
<hr />
<div>Interested in homecockpit building.<br />
<br />
[http://wiki.flightgear.org/Howto:Use_Arduino_with_FlightGear Howto: Use Arduino with Flightgear]<br />
<br />
[http://wiki.flightgear.org/Howto:Create_WebPanel_instrument HowTo: Create WebPanel instrument]<br />
<br />
[[IDG-A32X]]<br />
<br />
[http://wiki.flightgear.org/Howto:Multi-computing_FlightGear Howto:Multi-computing_FlightGear]<br />
<br />
[http://wiki.flightgear.org/Howto:Configure_camera_view_windows Howto:Configure_camera_view_windows]<br />
<br />
[http://wiki.flightgear.org/Howto:Use_multiple_screens_under_linux Howto:Use_multiple_screens_under_linux]<br />
<br />
===== Multiple monitor: =====<br />
If you want to use it with the launcher, in defaults.xml you should change <rendering> to <rendering include="YourFileName.xml"><br />
and put the YourFileName.xml in the data folder. This makes sure your file gets loaded on the initial startup.</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=User:Vaipe&diff=113384User:Vaipe2017-12-28T07:21:45Z<p>Vaipe: </p>
<hr />
<div>Interested in homecockpit building.<br />
<br />
[http://wiki.flightgear.org/Howto:Use_Arduino_with_FlightGear Howto: Use Arduino with Flightgear]<br />
<br />
[http://wiki.flightgear.org/Howto:Create_WebPanel_instrument HowTo: Create WebPanel instrument]<br />
<br />
[[IDG-A32X]]<br />
<br />
[http://wiki.flightgear.org/Howto:Multi-computing_FlightGear Howto:Multi-computing_FlightGear]<br />
<br />
[http://wiki.flightgear.org/Howto:Configure_camera_view_windows Howto:Configure_camera_view_windows]<br />
<br />
[http://wiki.flightgear.org/Howto:Use_multiple_screens_under_linux Howto:Use_multiple_screens_under_linux]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=Howto:Use_Arduino_with_FlightGear&diff=113334Howto:Use Arduino with FlightGear2017-12-26T05:35:51Z<p>Vaipe: Added simple 2-axis tutorial by Scott.</p>
<hr />
<div>Thanks to FlightGear's [[generic protocol]], [[:Category:Hardware|hardware]] can easily interface with [[FlightGear]]. This hardware can be used to improve the immersion and/or realism of the simulation. Arduino is no exception.<br />
<br />
== About Arduino ==<br />
'''[http://www.arduino.cc/ Arduino]''' is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. The hardware is a microcontroller designed around an 8-bit or 32-bit microcontroller, with several digital and analog {{Abbr|I/O|Input/Output}} ports. The software is the [http://arduino.cc/en/Main/Software Arduino {{Abbr|IDE|Integrated Development Environment}}].<br />
<br />
== Example 1: 2-axis joystic ==<br />
<big>By ScottBouch</big><br />
<br />
This example demonstrates use of two potentiometers (2-axis joystic) with a simple calibration in arduino code. Example is done with Linux Mint. To see more detailed version of this quide go to [http://www.scottbouch.com/flightgear-sim-arduino-serial-hardware-2-axis-potentiometer-joystick.html 2-Axis Potentiometer Joystick:Integration With Flightgear Flight Sim].<br />
<br />
=== Wiring ===<br />
Connect 5V to other terminal of potentiometers and 0V to other terminal. Connect potentiometers wiper terminals to Arduino boards A0 and A1.<br />
<br />
=== Arduino code ===<br />
<syntaxhighlight lang="c"><br />
/*<br />
Flightgear hardware integration 01: Stick X and Y only so far.<br />
<br />
Scott Bouchard UK www.scottbouch.com 14-06-2017<br />
*/<br />
<br />
const int stickxio = A0; //Define stick aileron (x) input<br />
const int stickyio = A1; //Define stick elevator (y) input<br />
<br />
float stickx = 0; //Start aileron (x) central<br />
float sticky = 0; //Start elevator (y) central<br />
<br />
void setup() {<br />
Serial.begin(9600); //Open up serial communication to PC<br />
}<br />
<br />
void loop() {<br />
stickx = (analogRead(stickxio)/512.0)-0.99; //Calibration span and offset<br />
sticky = (analogRead(stickyio)/512.0)-0.99; //Calibration span and offset<br />
<br />
Serial.print(stickx); //Send aileron position<br />
Serial.print(","); //Variable (var) separator<br />
Serial.print(sticky); //Send elevator position<br />
Serial.print("\n"); //Line separator <br />
}<br />
</syntaxhighlight><br />
<br />
=== Calibration ===<br />
Use Arduino serial monitor to see that serial data acquired from Arduino board is between -1.00...1.00 when potentiometers are rotated. Potentiometers middle position should send 0.00. If potentiometers are not giving good readings, modify Arduino code "Calibration span and offset" row to fix it.<br />
<br />
=== Flightgear protocol code ===<br />
Create a file called hardware.xml to /usr/share/games/flightgear/Protocol directory and paste following lines to it:<br />
<br />
<syntaxhighlight lang="xml"><br />
<?xml version="1.0"?><br />
<br />
<PropertyList><br />
<br />
<generic><br />
<br />
<input><br />
<line_separator>\n</line_separator><br />
<var_separator>,</var_separator><br />
<br />
<chunk><br />
<name>aileron</name><br />
<type>float</type><br />
<node>/controls/flight/aileron</node><br />
</chunk><br />
<br />
<chunk><br />
<name>elevator</name><br />
<type>float</type><br />
<node>/controls/flight/elevator</node><br />
</chunk><br />
<br />
</input><br />
<br />
</generic><br />
<br />
</PropertyList><br />
</syntaxhighlight><br />
<br />
=== Make Flightgear to read serial data ===<br />
Find port where Arduino is connected. Look from Arduino IDE Tools... Serial Port... Should be something like ttyACM. (Note: Scott Bouch tutorial uses FGRUN which is not used anymore) Start Flightgear and paste following code to Settings... Additional settings... when starting Flightgear. Change serial port to correct port name.<br />
<br />
<syntaxhighlight><br />
--generic=serial,in,30,/dev/ttyACM0,9600,hardware.xml<br />
</syntaxhighlight><br />
<br />
== Example 2: Controlling internal properties ==<br />
<big>By {{usr|Vaipe}}</big><br />
<br />
This example demonstrates the use of a switch and a potentiometer to control the [[Property Tree]].<br />
<br />
=== Equipment and software ===<br />
The following equipment was used for this example:<br />
* [[Changelog_3.2|FlightGear 3.2]]<br />
* [[FGRun]]<br />
* [[Cessna 172P|Cessna 172P Skyhawk]] (default aircraft) <br />
* [http://arduino.cc/en/Main/ArduinoBoardUno Arduino Uno]<br />
* Linux ([http://en.wikipedia.org/wiki/List_of_Ubuntu_releases#Ubuntu_10.04_LTS_.28Lucid_Lynx.29 Ubuntu 14.04])<br />
* Simple on/off switch<br />
* Potentiometer<br />
<br />
=== Input protocol file ===<br />
Input protocol file is used to specify how serial information is read by Flightgear. In Ubuntu protocol files are found in:<br />
<code>''/usr/share/games/flightgear/protocol''</code> directory.<br />
<br />
==== Protocol file structure ====<br />
Create <code>''controltest.xml''</code> file in your protocol folder and paste code from below to it.<br />
<syntaxhighlight land="xml"><br />
<?xml version="1.0"?><br />
<br />
<PropertyList><br />
<br />
<generic><br />
<input> <br />
<line_separator>\n</line_separator><br />
<var_separator>,</var_separator><br />
<br />
<chunk><br />
<name>Strobe</name><br />
<node>/controls/lighting/strobe</node><br />
<type>bool</type><br />
</chunk><br />
<br />
<chunk><br />
<name>Throttle</name><br />
<node>/controls/engines/engine/throttle</node><br />
<type>float</type><br />
</chunk><br />
<br />
</input><br />
</generic><br />
<br />
</PropertyList><br />
</syntaxhighlight><br />
See [[Generic protocol]] for a description of the various XML tags.<br />
<br />
=== Wiring and coding ===<br />
<br />
==== Wiring ====<br />
A potentiometer is connected to Arduinos ground and +5 volts. The potentiometer's middle connector is connected to A0 analoq input. Switch is connected to ground with 10 kOhms pull-down resistor and +5 and digital pin 7. The diagram below illustrates the setup.<br />
[[File:Arduino switch and potentiometer wiring.png|frame|none|Wiring schematic for connecting the potentiometer and switch to Arduino]]<br />
<br />
==== Code ====<br />
Copy this C code to Arduino IDE and send it to the Arduino Uno:<br />
<syntaxhighlight lang="c"><br />
/*<br />
FGFS Input Test<br />
Reads a digital input on pin 7, prints the result to the serial port.<br />
Reads a potentiometer input on A0 and print result to serial port.<br />
This example code is in the public domain.<br />
*/<br />
<br />
int potPin = 0; // potentiometer on A0<br />
int switchPin = 7; // switch on pin 7<br />
float potValue = 0; // float variable to store potentiometer value<br />
<br />
void setup() {<br />
Serial.begin(9600); // open serial connection<br />
pinMode(switchPin, INPUT); // pin 7 declared as input<br />
}<br />
<br />
<br />
void loop() {<br />
<br />
Serial.print(digitalRead(switchPin)); // read and print switch state<br />
Serial.print(","); // print ,<br />
potValue = analogRead(potPin); // read potentiometer and store it to potValue<br />
potValue = potValue / 1024; // divide potValue with 1024 to make it between 0 and 1<br />
PrintDouble(potValue, 2); // pass potValue to PrintDouble-function, read from below what magic happens<br />
Serial.print("\n"); // print new line<br />
delay(500); // delay only for making this guide easier to follow on serial monitor<br />
<br />
}<br />
<br />
<br />
void PrintDouble(double val, byte precision){<br />
// prints val with number of decimal places determine by precision<br />
// precision is a number from 0 to 6 indicating the desired decimial places<br />
// example: lcdPrintDouble( 3.1415, 2); // prints 3.14 (two decimal places)<br />
// From http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207226548<br />
<br />
if(val < 0.0){<br />
Serial.print('-');<br />
val = -val;<br />
}<br />
<br />
Serial.print (int(val)); //prints the int part<br />
if( precision > 0) {<br />
Serial.print("."); // print the decimal point<br />
unsigned long frac;<br />
unsigned long mult = 1;<br />
byte padding = precision -1;<br />
while(precision--)<br />
mult *=10;<br />
<br />
if(val >= 0)<br />
frac = (val - int(val)) * mult;<br />
else<br />
frac = (int(val)- val ) * mult;<br />
unsigned long frac1 = frac;<br />
while( frac1 /= 10 )<br />
padding--;<br />
while( padding--)<br />
Serial.print("0");<br />
Serial.print(frac,DEC) ;<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
==== Testing serial output ====<br />
Use Arduino IDE's serial monitor and you should see something like this:<br />
[[File:Flightgear arduino serial monitor.png|frame|none|Arduino IDE's serial monitor output]]<br />
<br />
The first number is switch data, so it's either 0 (switch off) or 1 (switch on). After the "," mark is our throttle data. First it's 0.00, which meaning idle throttle and then potentiometer is gradually turned until it reaches 0.99.<br />
<br />
{{Note|Remember to '''unplug Arduino's USB cable and plug it back'''.<br />
<br />
FlightGear will not be able to read serial without doing this!<br />
<br />
You have to do this every time after you use the Arduino IDE.}}<br />
<br />
==== Starting FlightGear ====<br />
<br />
===== Method 1: Command line =====<br />
FlightGear needs to be started with a correct command line option for it to be able to read serial connection. This example uses following option:<br />
<syntaxhighlight><br />
--generic=serial,in,30,/dev/ttyACM0,9600,controltest<br />
</syntaxhighlight><br />
<br />
===== Method 2: FGRun =====<br />
Alternatively, you can use FlightGear's graphical user interface (FGRun) to launch FlightGear. See the image below for the correct settings.<br />
[[File:Starting Flightgear with input options enabled.jpg|thumb|none|Starting Flightgear with FGRun, selecting input/output options]]<br />
<br />
If you don't know your correct port is , you can check it with a following command in terminal:<br />
<syntaxhighlight><br />
dmesg | tail<br />
</syntaxhighlight><br />
It should give you a message something like <code>ttyACM0: USB ACM device</code> or <code>ttyACM1: USB ACM device</code>. That is your port. Finally, save setting by clicking "OK" and click "Run" to start FlightGear. For a more detailed guide, see [https://sites.google.com/site/flightgeararduinoandlinux/home Flightgear, Arduino and Linux]<br />
<br />
== Example 3: Outputting properties ==<br />
<big>By {{usr|Rubdos}}</big><br />
[[File:Arduinofgfs.jpg|thumb|270px|Arduino LCD panel displaying speed, heading and altitude.]]<br />
This example uses the example using the [[Generic protocol]] and an [http://arduino.cc/en/Main/arduinoBoardMega2560 Arduino Mega 2560].<br />
Below is the protocol XML file used to control the Arduino.<br />
<syntaxhighlight lang="xml"><br />
<?xml version="1.0"?><br />
<br />
<PropertyList><br />
<br />
<generic><br />
<output><br />
<binary_mode>false</binary_mode><br />
<line_separator>newline</line_separator><br />
<var_separator>newline</var_separator><br />
<preamble></preamble><br />
<postamble></postamble><br />
<br />
<chunk><br />
<name>Altitude</name><br />
<node>/position/altitude-ft</node><br />
<type>integer</type><br />
<format>altitude=%i</format><br />
</chunk><br />
<br />
<chunk><br />
<name>RPM</name><br />
<node>/engines/engine/rpm</node><br />
<type>integer</type><br />
<format>rpm=%i</format><br />
</chunk><br />
<br />
</output><br />
<br />
<!-- <input><br />
<line_separator>newline</line_separator><br />
<var_separator>tab</var_separator><br />
<chunk><br />
</chunk><br />
</input> --><br />
<br />
</generic><br />
<br />
</PropertyList><br />
</syntaxhighlight><br />
<br />
Below is the C code used for the example, taken from https://gist.github.com/rubdos/5422870.<br />
<syntaxhighlight lang="c"><br />
//PIN 0 -> 7 has positive segment part<br />
<br />
// the setup routine runs once when you press reset:<br />
void setup() { <br />
// initialize the digital pin as an output.<br />
pinMode(2, OUTPUT);<br />
pinMode(3, OUTPUT);<br />
pinMode(4, OUTPUT); <br />
pinMode(5, OUTPUT); <br />
pinMode(6, OUTPUT); <br />
pinMode(7, OUTPUT); <br />
pinMode(8, OUTPUT); <br />
pinMode(9, OUTPUT); <br />
<br />
pinMode(49, OUTPUT); <br />
pinMode(50, OUTPUT);<br />
pinMode(51, OUTPUT);<br />
pinMode(52, OUTPUT);<br />
pinMode(53, OUTPUT);<br />
<br />
Serial.begin(9600);<br />
}<br />
<br />
void writeNumber(int nr)<br />
{<br />
if(nr == 0)<br />
{<br />
digitalWrite(2, LOW); // midden<br />
digitalWrite(3, HIGH); // lt<br />
digitalWrite(4, HIGH); // t<br />
digitalWrite(5, HIGH); // rt<br />
digitalWrite(6, HIGH); // lb<br />
digitalWrite(7, HIGH); // b<br />
digitalWrite(8, HIGH); // rb<br />
digitalWrite(9, LOW); // dot<br />
}<br />
else if(nr == 1)<br />
{<br />
digitalWrite(2, LOW); // midden<br />
digitalWrite(3, LOW); // lt<br />
digitalWrite(4, LOW); // t<br />
digitalWrite(5, HIGH); // rt<br />
digitalWrite(6, LOW); // lb<br />
digitalWrite(7, LOW); // b<br />
digitalWrite(8, HIGH); // rb<br />
digitalWrite(9, LOW); // dot<br />
}<br />
else if(nr == 2)<br />
{<br />
digitalWrite(2, HIGH); // midden<br />
digitalWrite(3, LOW); // lt<br />
digitalWrite(4, HIGH); // t<br />
digitalWrite(5, HIGH); // rt<br />
digitalWrite(6, HIGH); // lb<br />
digitalWrite(7, HIGH); // b<br />
digitalWrite(8, LOW); // rb<br />
digitalWrite(9, LOW); // dot<br />
}<br />
else if(nr == 3)<br />
{<br />
digitalWrite(2, HIGH); // midden<br />
digitalWrite(3, LOW); // lt<br />
digitalWrite(4, HIGH); // t<br />
digitalWrite(5, HIGH); // rt<br />
digitalWrite(6, LOW); // lb<br />
digitalWrite(7, HIGH); // b<br />
digitalWrite(8, HIGH); // rb<br />
digitalWrite(9, LOW); // dot<br />
}<br />
else if(nr == 4)<br />
{<br />
digitalWrite(2, HIGH); // midden<br />
digitalWrite(3, HIGH); // lt<br />
digitalWrite(4, LOW); // t<br />
digitalWrite(5, HIGH); // rt<br />
digitalWrite(6, LOW); // lb<br />
digitalWrite(7, LOW); // b<br />
digitalWrite(8, HIGH); // rb<br />
digitalWrite(9, LOW); // dot<br />
}<br />
else if(nr == 5)<br />
{<br />
digitalWrite(2, HIGH); // midden<br />
digitalWrite(3, HIGH); // lt<br />
digitalWrite(4, HIGH); // t<br />
digitalWrite(5, LOW); // rt<br />
digitalWrite(6, LOW); // lb<br />
digitalWrite(7, HIGH); // b<br />
digitalWrite(8, HIGH); // rb<br />
digitalWrite(9, LOW); // dot<br />
}<br />
else if(nr == 6)<br />
{<br />
digitalWrite(2, HIGH); // midden<br />
digitalWrite(3, HIGH); // lt<br />
digitalWrite(4, HIGH); // t<br />
digitalWrite(5, LOW); // rt<br />
digitalWrite(6, HIGH); // lb<br />
digitalWrite(7, HIGH); // b<br />
digitalWrite(8, HIGH); // rb<br />
digitalWrite(9, LOW); // dot<br />
}<br />
else if(nr == 7)<br />
{<br />
digitalWrite(2, LOW); // midden<br />
digitalWrite(3, LOW); // lt<br />
digitalWrite(4, HIGH); // t<br />
digitalWrite(5, HIGH); // rt<br />
digitalWrite(6, LOW); // lb<br />
digitalWrite(7, LOW); // b<br />
digitalWrite(8, HIGH); // rb<br />
digitalWrite(9, LOW); // dot<br />
}<br />
else if(nr == 8)<br />
{<br />
digitalWrite(2, HIGH); // midden<br />
digitalWrite(3, HIGH); // lt<br />
digitalWrite(4, HIGH); // t<br />
digitalWrite(5, HIGH); // rt<br />
digitalWrite(6, HIGH); // lb<br />
digitalWrite(7, HIGH); // b<br />
digitalWrite(8, HIGH); // rb<br />
digitalWrite(9, LOW); // dot<br />
}<br />
else if(nr == 9)<br />
{<br />
digitalWrite(2, HIGH); // midden<br />
digitalWrite(3, HIGH); // lt<br />
digitalWrite(4, HIGH); // t<br />
digitalWrite(5, HIGH); // rt<br />
digitalWrite(6, LOW); // lb<br />
digitalWrite(7, HIGH); // b<br />
digitalWrite(8, HIGH); // rb<br />
digitalWrite(9, LOW); // dot<br />
}<br />
else<br />
{<br />
digitalWrite(2, LOW); // midden<br />
digitalWrite(3, LOW); // lt<br />
digitalWrite(4, LOW); // t<br />
digitalWrite(5, LOW); // rt<br />
digitalWrite(6, LOW); // lb<br />
digitalWrite(7, LOW); // b<br />
digitalWrite(8, LOW); // rb<br />
digitalWrite(9, LOW); // dot<br />
}<br />
}<br />
<br />
// the loop routine runs over and over again forever<br />
long number = 0;<br />
int decimals[5] = {0, 0, 0, 0, 0};<br />
<br />
void loop() {<br />
for(int i = 49; i < 54; i++)<br />
{<br />
// Disable the incorrect segment displays<br />
if(i == 49)<br />
{<br />
digitalWrite(53, HIGH);<br />
}<br />
else<br />
{<br />
digitalWrite(i - 1, HIGH);<br />
}<br />
digitalWrite(i, LOW);<br />
<br />
// Enable the segments<br />
writeNumber(decimals[4 - (i - 49)]);<br />
delay(1);<br />
}<br />
if(Serial.available() > 14) // Wait until there are two bytes available. Then read them out.<br />
{<br />
String command;<br />
String var;<br />
char lastchar;<br />
<br />
while(lastchar != '=')<br />
{<br />
lastchar = Serial.read();<br />
if(lastchar != '=')<br />
{<br />
command += lastchar;<br />
}<br />
}<br />
while(lastchar != '\n')<br />
{<br />
lastchar = Serial.read();<br />
if(lastchar != '\n')<br />
{<br />
var += lastchar;<br />
}<br />
}<br />
<br />
if(command == "altitude" )<br />
{<br />
char buf[50];<br />
var.toCharArray(buf, 50);<br />
number = atol(buf);<br />
}<br />
<br />
/*if(number == 10000)<br />
{<br />
number = 0;<br />
}*/<br />
<br />
long currentnumber = number;<br />
<br />
int remainder = currentnumber % 10;<br />
currentnumber = (currentnumber - remainder) / 10;<br />
decimals[4] = remainder;<br />
<br />
remainder = currentnumber % 10;<br />
currentnumber = (currentnumber - remainder) / 10;<br />
decimals[3] = remainder;<br />
<br />
remainder = currentnumber % 10;<br />
currentnumber = (currentnumber - remainder) / 10;<br />
decimals[2] = remainder;<br />
<br />
remainder = currentnumber % 10;<br />
currentnumber = (currentnumber - remainder) / 10;<br />
decimals[1] = remainder;<br />
<br />
remainder = currentnumber % 10;<br />
currentnumber = (currentnumber - remainder) / 10;<br />
decimals[0] = remainder;<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
The hardware used was five seven-segment displays, multiplexed straight on the Arduino device. Ideally, you'd rather use some 74HC595 or other shift register chips to drive them, to unload the Arduino and have more current.<br />
<br />
Below is a demo uploaded to YouTube, with voiceover in which the display shows the RPM of [[Robin DR400]]'s single engine.<br />
{{#ev:youtube|lVtV9-CgqBo}}<br />
<br />
== Related content ==<br />
* [[Input device]]<br />
<br />
== External links ==<br />
* [http://arduino.cc/ Official Arduino website]<br />
* [http://playground.arduino.cc/Main/FlightGear FlightGear Serial Communications with Arduino] (tutorial)<br />
* [http://forum.flightgear.org/viewtopic.php?f=18&t=11126 Arduino LCD and FlightGear] (FlightGear forum)<br />
* [https://sites.google.com/site/flightgeararduinoandlinux/ Flightgear, Arduino and Linux] (potentiometer and switch interfacing tutorial)<br />
<br />
[[Category:Cockpit building]]<br />
[[Category:Hardware]]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=User:Vaipe&diff=103161User:Vaipe2016-08-19T10:42:20Z<p>Vaipe: </p>
<hr />
<div>Interested in homecockpit building.<br />
<br />
[http://wiki.flightgear.org/Howto:Use_Arduino_with_FlightGear Howto: Use Arduino with Flightgear]<br />
<br />
[http://wiki.flightgear.org/Howto:Create_WebPanel_instrument HowTo: Create WebPanel instrument]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=User:Vaipe&diff=103160User:Vaipe2016-08-19T10:41:18Z<p>Vaipe: </p>
<hr />
<div>[http://wiki.flightgear.org/Howto:Use_Arduino_with_FlightGear Arduino with Flightgear]<br />
<br />
[http://wiki.flightgear.org/Howto:Create_WebPanel_instrument Create WebPanel instrument]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=Howto:Create_WebPanel_instrument&diff=103158Howto:Create WebPanel instrument2016-08-19T10:25:24Z<p>Vaipe: </p>
<hr />
<div>This guide will show you how to create a one simple web based instrument for a WebPanel. In a picture below, a Cessna 172P WebPanel is shown in another monitor in front of a lcd tv used as a scenery visual.<br />
<br />
[[File:C172p WebPanel with TV as visual.jpg|thumb|Cessna 172P WebPanel shown in a monitor front of a TV used as visual]]<br />
<br />
First you should check that you can see a Cessna 172P WebPanel on a browser window. Start Flightgear with a Cessna 172P plane selected and with "--httpd=8080" additional option to start internal webserver. Then from Flightgear's C172P aircraft menu, click "Panel in a Browser" and browser window should open with a working instrument panel. When you start engine and lift off, instruments should be moving.<br />
<br />
This HowTo uses following software:<br />
* Ubuntu 16.04<br />
* Flightgear 2016.2.1<br />
* PC-9m aircraft<br />
* Inkscape<br />
<br />
=== WebPanel folder and instrument files for aircraft ===<br />
<br />
Create a folder named "WebPanel" into Flightgear's aircraft folder. In Ubuntu, installed aircraft folders can be found from: /home/YOUR_USER_NAME/.fgfs/Aircraft/org.flightgear.official/Aircraft<br />
<br />
For WebPanel to work, following files are needed:<br />
* webpanel-properties.json (maps Flightgears internal properties for instruments)<br />
* webpanel.html (html page what is shown in browser)<br />
<br />
And for a single instrument, following files are needed:<br />
* INSTRUMENT_NAME.svg (vector image shown in www-page as flight instrument)<br />
* INSTRUMENT_NAME.json (for instrument animations)<br />
* INSTRUMENT_NAMEInterpolation.xml (not necessary file, but used if instrument animation needs to be non-linear)<br />
<br />
=== webpanel-properties.json ===<br />
<br />
webpanel-properties.json file maps Flightgears internal properties to instruments. Create a file named webpanel-properties.json, save it to aircrafts WebPanel folder and insert following code into it:<br />
<syntaxhighlight land="xml"><br />
{<br />
"instrumentSelector": ".instrument",<br />
"instrumentDataKey": "fgpanel-instrument",<br />
"updateInterval": 32,<br />
<br />
"propertyMirror": [<br />
["ias", "/instrumentation/airspeed-indicator/indicated-speed-kt"]<br />
<br />
]<br />
}<br />
</syntaxhighlight><br />
<br />
This example file will take only planes indicated speed in knots and sends it to "ias". If you need multiple internal properties for one instrument or for creating other instruments, see example from /usr/share/games/flightgear/Aircraft/c172p/WebPanel/c172p-webpanel-properties.json file, for how more rows for multiple properties are added.<br />
<br />
=== WebPanel www-page file ===<br />
<br />
Create webpanel.html file and save it in WebPanel folder with following code:<br />
<br />
<syntaxhighlight land="html"><br />
<!DOCTYPE html><br />
<html><br />
<head><br />
<meta charset=utf-8 /><br />
<!-- Tweaks for panel on an ipad - from https://gist.github.com/tfausak/2222823 --><br />
<meta name="apple-mobile-web-app-capable" content="yes"><br />
<!-- meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" --><br />
<meta name="apple-touch-fullscreen" content="yes"><br />
<meta name="apple-mobile-web-app-status-bar-style" content="black"><br />
<br />
<title>FlightGear - PC-9m Instrument Panel</title><br />
<style type="text/css" media="screen"><br />
body,html {<br />
width: 100%;<br />
height: 100%;<br />
overflow: hidden;<br />
background-color: #000000;<br />
border: 0;<br />
margin: 0;<br />
padding: 0;<br />
}<br />
<br />
.instrument {<br />
border: 1px solid #131313;<br />
padding: 8px;<br />
background-color: #111111;<br />
}<br />
</style><br />
<br />
<br />
<script type="text/javascript" charset="utf-8"<br />
src="/3rdparty/jquery/jquery-1.11.1.min.js"></script><br />
<br />
<!-- Latest compiled and minified CSS --><br />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css"><br />
<!-- Latest compiled and minified JavaScript --><br />
<script src="bootstrap/bootstrap.min.js"></script><br />
<br />
<script type="text/javascript" charset="utf-8" src="/lib/jquery.fganimate.js"></script><br />
<script type="text/javascript" charset="utf-8" src="/lib/fgfs.js"></script><br />
<br />
</head><br />
<body data-fgpanel="true" data-fgpanel-props="webpanel-properties.json"><br />
<div class="row"><br />
<div id="pc9m_ASI" class="instrument col-xs-2" data-fgpanel-instrument="pc9m_ASI.json"></div><br />
</div><br />
</body><br />
</html><br />
</syntaxhighlight><br />
<br />
This creates a file for browser to show instruments. Important is data-fgpanel-props="webpanel-properties.json"> which specifies planes properties .json file. In &#60;div&#62; tag id="pc9m_ASI" and data-fgpanel-instrument="pc9m_ASI.json" specifies what instrument is drawn into browser. To create a new instrument, add another &#60;div&#62; with new id tag and .json file. To create a new row for instruments start a new &#60;div class="row"&#62;. See example from Cessna 172P planes folder /usr/share/games/flightgear/Aircraft/c172p/WebPanel/c172p-webpanel.html.<br />
<br />
=== INSTRUMENT_NAME.json ===<br />
<br />
INSTRUMENT_NAME.json file specifies how instrument behaves when Flightgears properties change. Create file named pc9m_ASI.json, save it to WebPanel folder and add following code into it:<br />
<syntaxhighlight land="json"><br />
{ <br />
"src": "pc9m_ASI.svg",<br />
<br />
"animations": [<br />
{<br />
"element": "#Needle",<br />
"type": "transform",<br />
"transforms": [{<br />
"type": "rotate",<br />
"a": {<br />
"property": "ias",<br />
"interpolation": "AirspeedInterpolation.xml"<br />
},<br />
"x": 256,<br />
"y": 256<br />
}]<br />
}<br />
<br />
]<br />
}<br />
</syntaxhighlight><br />
<br />
Explanation for rows:<br />
* "src": "pc9m_ASI.svg": filename of instruments .svg vector graphic file<br />
* "element": "#Needle": instruments .svg images id what is meant to be animated<br />
* "type": "rotate": we are rotating Needle layer of instrument image<br />
* property "ias": Flightgears internal property that causes the movement<br />
* "interpolation": file where interpolation is specified<br />
* "x": 256, "y": 256: specifies origo for rotation. In our image size 512x512px, 256px is in middle of the image.<br />
<br />
=== INSTRUMENT_NAMEInterpolation.xml ===<br />
<br />
Create file AirspeedInterpolation.xml and save it to WebPanel folder with following code:<br />
<syntaxhighlight land="xml"><br />
<?xml version="1.0"?><br />
<!--<br />
This file is part of FlightGear, the free flight simulator<br />
http://www.flightgear.org/<br />
<br />
Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de<br />
<br />
This program is free software; you can redistribute it and/or<br />
modify it under the terms of the GNU General Public License as<br />
published by the Free Software Foundation; either version 2 of the<br />
License, or (at your option) any later version.<br />
<br />
This program is distributed in the hope that it will be useful, but<br />
WITHOUT ANY WARRANTY; without even the implied warranty of<br />
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br />
General Public License for more details.<br />
--><br />
<PropertyList><br />
<entry><ind> 0</ind><dep> 0</dep></entry><br />
<entry><ind> 35</ind><dep> 36</dep></entry><br />
<entry><ind> 40</ind><dep> 50</dep></entry><br />
<entry><ind> 60</ind><dep> 100</dep></entry><br />
<entry><ind> 80</ind><dep> 152</dep></entry><br />
<entry><ind> 100</ind><dep> 206</dep></entry><br />
<entry><ind> 120</ind><dep> 249</dep></entry><br />
<entry><ind> 140</ind><dep> 291</dep></entry><br />
<entry><ind> 160</ind><dep> 333</dep></entry><br />
<entry><ind> 190</ind><dep> 340</dep></entry><br />
</PropertyList><br />
</syntaxhighlight><br />
<br />
Interpolation lists first number input property (air speed in this example) and second number is angle for needle.<br />
<br />
=== Creating instrument graphics with Inkscape ===<br />
<br />
If you are not familiar with Inkscape, see [https://inkscape.org/en/learn/tutorials/ Inkscape tutorials].<br />
<br />
To create a instrument image, start creating a new 512x512 px size file with Inkscape. When drawing .svg file, following issues need to be kept in mind:<br />
* moving objects needs to be on a different layers<br />
* layers id needs to be renamed from Inkscapes XML editor. Layer animation will fail if id is not correct.<br />
<br />
Draw a round face and a simple needle on top of it<br />
*Create new layer and call it "Face". Draw a circle in it.<br />
*create new layers called "Needle" and draw a needle in it. Needles rotating point should be in middle of the drawing area. Rename its ID from XML editor to "Needle".<br />
*Save it with a pc9m_ASI.svg name in to PC-9m aircrafts WebPanel folder. <br />
<br />
=== Test WebPanel ===<br />
<br />
To test instrument in WebPanel, start Flightgear with "--httpd=8080" additional option to start Flightgears web server.<br />
<br />
When Flightgear has started, go to http://localhost:8080/aircraft-dir/WebPanel/webpanel.html address and simple instrument with one needle and without numbers should be visible.<br />
<br />
Start PC-9m and when speed is rising you should see needle to start moving.<br />
<br />
[[File:PC-9m WebPanel tutorial air speed instrument.jpg|thumb|Example of WebPanel instrument showing PC-9m airspeed in browser]]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=User:Vaipe&diff=103155User:Vaipe2016-08-19T06:21:50Z<p>Vaipe: Blanked the page</p>
<hr />
<div></div>Vaipehttps://wiki.flightgear.org/w/index.php?title=Howto:Create_WebPanel_instrument&diff=103154Howto:Create WebPanel instrument2016-08-19T06:20:03Z<p>Vaipe: </p>
<hr />
<div>This guide will show you how to create a one simple web based instrument for a WebPanel. In a picture below, a C172s WebPanel is shown in another monitor in front of a lcd tv used as a scenery visual.<br />
<br />
[[File:C172p WebPanel with TV as visual.jpg|thumb|Flightgear flightsimulators Cessna C172p WebPanel in monitor front of a TV used as visual]]<br />
<br />
First you should check that you can see a Cessna C172s WebPanel on a browser window. Start Flightgear with a C172s and from Flightgear's aircrafts menu, click "Panel in a Browser" and browser window should open with a working instrument panel. And when you start engine and lift off, instruments should be moving.<br />
<br />
This HowTo uses following software:<br />
* Ubuntu 16.04<br />
* Flightgear 2016.2.1<br />
* PC-9m aircraft<br />
* Inkscape<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== WebPanel folder and instrument files for aircraft ===<br />
<br />
Create a folder named "WebPanel" into Flightgear's aircraft folder. In Ubuntu, installed aircraft folders can be found from: /home/YOUR_USER_NAME/.fgfs/Aircraft/org.flightgear.official/Aircraft<br />
<br />
For WebPanel to work, following files are needed:<br />
* webpanel-properties.json (maps Flightgears internal properties for instruments)<br />
* webpanel.html (html page what is shown in browser)<br />
<br />
And for a single instrument, following files are needed:<br />
* INSTRUMENT_NAME.svg (vector image shown in www-page as flight instrument)<br />
* INSTRUMENT_NAME.json (for instrument animations)<br />
* INSTRUMENT_NAMEInterpolation.xml (not necessary file, but used if instrument animation needs to be non-linear)<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== webpanel-properties.json ===<br />
<br />
webpanel-properties.json file maps Flightgears internal properties to instruments. Create a file named webpanel-properties.json, save it to aircrafts WebPanel folder and insert following code into it:<br />
<syntaxhighlight land="xml"><br />
{<br />
"instrumentSelector": ".instrument",<br />
"instrumentDataKey": "fgpanel-instrument",<br />
"updateInterval": 32,<br />
<br />
"propertyMirror": [<br />
["ias", "/instrumentation/airspeed-indicator/indicated-speed-kt"]<br />
<br />
]<br />
}<br />
</syntaxhighlight><br />
<br />
This example file will take only planes indicated speed in knots and sends it to "ias". If you need multiple internal properties for one instrument or for creating other instruments, see example from /usr/share/games/flightgear/Aircraft/c172p/WebPanel/c172p-webpanel-properties.json file, for how more rows for multiple properties are added.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== WebPanel www-page file ===<br />
<br />
Create webpanel.html file and save it in WebPanel folder with following code:<br />
<br />
<syntaxhighlight land="html"><br />
<!DOCTYPE html><br />
<html><br />
<head><br />
<meta charset=utf-8 /><br />
<!-- Tweaks for panel on an ipad - from https://gist.github.com/tfausak/2222823 --><br />
<meta name="apple-mobile-web-app-capable" content="yes"><br />
<!-- meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" --><br />
<meta name="apple-touch-fullscreen" content="yes"><br />
<meta name="apple-mobile-web-app-status-bar-style" content="black"><br />
<br />
<title>FlightGear - PC-9m Instrument Panel</title><br />
<style type="text/css" media="screen"><br />
body,html {<br />
width: 100%;<br />
height: 100%;<br />
overflow: hidden;<br />
background-color: #000000;<br />
border: 0;<br />
margin: 0;<br />
padding: 0;<br />
}<br />
<br />
.instrument {<br />
border: 1px solid #131313;<br />
padding: 8px;<br />
background-color: #111111;<br />
}<br />
</style><br />
<br />
<br />
<script type="text/javascript" charset="utf-8"<br />
src="/3rdparty/jquery/jquery-1.11.1.min.js"></script><br />
<br />
<!-- Latest compiled and minified CSS --><br />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css"><br />
<!-- Latest compiled and minified JavaScript --><br />
<script src="bootstrap/bootstrap.min.js"></script><br />
<br />
<script type="text/javascript" charset="utf-8" src="/lib/jquery.fganimate.js"></script><br />
<script type="text/javascript" charset="utf-8" src="/lib/fgfs.js"></script><br />
<br />
</head><br />
<body data-fgpanel="true" data-fgpanel-props="webpanel-properties.json"><br />
<div class="row"><br />
<div id="pc9m_ASI" class="instrument col-xs-2" data-fgpanel-instrument="pc9m_ASI.json"></div><br />
</div><br />
</body><br />
</html><br />
</syntaxhighlight><br />
<br />
<br />
This creates a file for browser to show instruments. Important is data-fgpanel-props="webpanel-properties.json"> which specifies planes properties .json file. In <div> tag id="pc9m_ASI" and data-fgpanel-instrument="pc9m_ASI.json" specifies what instrument is drawn into browser. To create a new instrument, add another <div> with new id tag and .json file. To create a new row for instruments start a new <div class="row">. See example from C172p planes folder /usr/share/games/flightgear/Aircraft/c172p/WebPanel/c172p-webpanel.html.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== INSTRUMENT_NAME.json ===<br />
<br />
INSTRUMENT_NAME.json file specifies how instrument behaves when Flightgears properties change. Create file named pc9m_ASI.json, save it to WebPanel folder and add following code into it:<br />
<syntaxhighlight land="xml"><br />
{ <br />
"src": "pc9m_ASI.svg",<br />
<br />
"animations": [<br />
{<br />
"element": "#Needle",<br />
"type": "transform",<br />
"transforms": [{<br />
"type": "rotate",<br />
"a": {<br />
"property": "ias",<br />
"interpolation": "AirspeedInterpolation.xml"<br />
},<br />
"x": 256,<br />
"y": 256<br />
}]<br />
}<br />
<br />
]<br />
}<br />
</syntaxhighlight><br />
<br />
"src": "pc9m_ASI.svg": filename of instruments .svg vector graphic file<br />
"element": "#Needle": instruments .svg images id what is meant to be animated<br />
"type": "rotate": we are rotating Needle layer of instrument image<br />
property "ias": Flightgears internal property that causes the movement<br />
"interpolation": file where interpolation is specified<br />
"x": 256, "y": 256: specifies origo for rotation. In our image size 512x512px, 256px is in middle of the image.<br />
<br />
<br />
=== INSTRUMENT_NAMEInterpolation.xml ===<br />
<br />
Create file AirspeedInterpolation.xml and save it to WebPanel folder with following code:<br />
<syntaxhighlight land="xml"><br />
<?xml version="1.0"?><br />
<!--<br />
This file is part of FlightGear, the free flight simulator<br />
http://www.flightgear.org/<br />
<br />
Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de<br />
<br />
This program is free software; you can redistribute it and/or<br />
modify it under the terms of the GNU General Public License as<br />
published by the Free Software Foundation; either version 2 of the<br />
License, or (at your option) any later version.<br />
<br />
This program is distributed in the hope that it will be useful, but<br />
WITHOUT ANY WARRANTY; without even the implied warranty of<br />
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br />
General Public License for more details.<br />
--><br />
<PropertyList><br />
<entry><ind> 0</ind><dep> 0</dep></entry><br />
<entry><ind> 35</ind><dep> 36</dep></entry><br />
<entry><ind> 40</ind><dep> 50</dep></entry><br />
<entry><ind> 60</ind><dep> 100</dep></entry><br />
<entry><ind> 80</ind><dep> 152</dep></entry><br />
<entry><ind> 100</ind><dep> 206</dep></entry><br />
<entry><ind> 120</ind><dep> 249</dep></entry><br />
<entry><ind> 140</ind><dep> 291</dep></entry><br />
<entry><ind> 160</ind><dep> 333</dep></entry><br />
<entry><ind> 190</ind><dep> 340</dep></entry><br />
</PropertyList><br />
</syntaxhighlight><br />
<br />
Interpolation lists first number input property (air speed in this example) and second number is angle for needle.<br />
<br />
<br />
<br />
<br />
<br />
=== Creating instrument graphics with Inkscape ===<br />
<br />
If you are not familiar with Inkscape, see [https://inkscape.org/en/learn/tutorials/ Inkscape tutorials].<br />
<br />
To create a instrument image, start creating a new 512x512 px size file with Inkscape. When drawing .svg file, following issues need to be kept in mind:<br />
* moving objects needs to be on a different layers<br />
* layers id needs to be renamed from Inkscapes XML editor. Layer animation will fail if id is not correct.<br />
<br />
Draw a round face and a simple needle on top of it<br />
*Create new layer and call it "Face". Draw a circle in it.<br />
*create new layers called "Needle" and draw a needle in it. Needles rotating point should be in middle of the drawing area. Rename its ID from XML editor to "Needle".<br />
*Save it with a pc9m_ASI.svg name in to PC-9m aircrafts WebPanel folder. <br />
<br />
<br />
<br />
=== Test WebPanel ===<br />
<br />
To test instrument in WebPanel, start Flightgear with "--httpd=8080" additional option to start Flightgears web server.<br />
<br />
When Flightgear has started, go to http://localhost:8080/aircraft-dir/WebPanel/webpanel.html address and simple instrument with one needle and without numbers should be visible.<br />
<br />
Start PC-9m and when speed is rising you should see needle to start moving.<br />
<br />
[[File:PC-9m WebPanel tutorial air speed instrument.jpg|thumb|Example of WebPanel instrument showing PC-9m airspeed in browser]]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=Howto:Create_WebPanel_instrument&diff=103153Howto:Create WebPanel instrument2016-08-19T06:17:20Z<p>Vaipe: Created page with "== How to: Create instrument for Flightgear WebPanel == This guide will show you how to create a one simple web based instrument for a WebPanel. In a picture below, a C172s W..."</p>
<hr />
<div>== How to: Create instrument for Flightgear WebPanel ==<br />
<br />
This guide will show you how to create a one simple web based instrument for a WebPanel. In a picture below, a C172s WebPanel is shown in another monitor in front of a lcd tv used as a scenery visual.<br />
<br />
[[File:C172p WebPanel with TV as visual.jpg|thumb|Flightgear flightsimulators Cessna C172p WebPanel in monitor front of a TV used as visual]]<br />
<br />
First you should check that you can see a Cessna C172s WebPanel on a browser window. Start Flightgear with a C172s and from Flightgear's aircrafts menu, click "Panel in a Browser" and browser window should open with a working instrument panel. And when you start engine and lift off, instruments should be moving.<br />
<br />
This HowTo uses following software:<br />
* Ubuntu 16.04<br />
* Flightgear 2016.2.1<br />
* PC-9m aircraft<br />
* Inkscape<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== WebPanel folder and instrument files for aircraft ===<br />
<br />
Create a folder named "WebPanel" into Flightgear's aircraft folder. In Ubuntu, installed aircraft folders can be found from: /home/YOUR_USER_NAME/.fgfs/Aircraft/org.flightgear.official/Aircraft<br />
<br />
For WebPanel to work, following files are needed:<br />
* webpanel-properties.json (maps Flightgears internal properties for instruments)<br />
* webpanel.html (html page what is shown in browser)<br />
<br />
And for a single instrument, following files are needed:<br />
* INSTRUMENT_NAME.svg (vector image shown in www-page as flight instrument)<br />
* INSTRUMENT_NAME.json (for instrument animations)<br />
* INSTRUMENT_NAMEInterpolation.xml (not necessary file, but used if instrument animation needs to be non-linear)<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== webpanel-properties.json ===<br />
<br />
webpanel-properties.json file maps Flightgears internal properties to instruments. Create a file named webpanel-properties.json, save it to aircrafts WebPanel folder and insert following code into it:<br />
<syntaxhighlight land="xml"><br />
{<br />
"instrumentSelector": ".instrument",<br />
"instrumentDataKey": "fgpanel-instrument",<br />
"updateInterval": 32,<br />
<br />
"propertyMirror": [<br />
["ias", "/instrumentation/airspeed-indicator/indicated-speed-kt"]<br />
<br />
]<br />
}<br />
</syntaxhighlight><br />
<br />
This example file will take only planes indicated speed in knots and sends it to "ias". If you need multiple internal properties for one instrument or for creating other instruments, see example from /usr/share/games/flightgear/Aircraft/c172p/WebPanel/c172p-webpanel-properties.json file, for how more rows for multiple properties are added.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== WebPanel www-page file ===<br />
<br />
Create webpanel.html file and save it in WebPanel folder with following code:<br />
<br />
<syntaxhighlight land="html"><br />
<!DOCTYPE html><br />
<html><br />
<head><br />
<meta charset=utf-8 /><br />
<!-- Tweaks for panel on an ipad - from https://gist.github.com/tfausak/2222823 --><br />
<meta name="apple-mobile-web-app-capable" content="yes"><br />
<!-- meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" --><br />
<meta name="apple-touch-fullscreen" content="yes"><br />
<meta name="apple-mobile-web-app-status-bar-style" content="black"><br />
<br />
<title>FlightGear - PC-9m Instrument Panel</title><br />
<style type="text/css" media="screen"><br />
body,html {<br />
width: 100%;<br />
height: 100%;<br />
overflow: hidden;<br />
background-color: #000000;<br />
border: 0;<br />
margin: 0;<br />
padding: 0;<br />
}<br />
<br />
.instrument {<br />
border: 1px solid #131313;<br />
padding: 8px;<br />
background-color: #111111;<br />
}<br />
</style><br />
<br />
<br />
<script type="text/javascript" charset="utf-8"<br />
src="/3rdparty/jquery/jquery-1.11.1.min.js"></script><br />
<br />
<!-- Latest compiled and minified CSS --><br />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css"><br />
<!-- Latest compiled and minified JavaScript --><br />
<script src="bootstrap/bootstrap.min.js"></script><br />
<br />
<script type="text/javascript" charset="utf-8" src="/lib/jquery.fganimate.js"></script><br />
<script type="text/javascript" charset="utf-8" src="/lib/fgfs.js"></script><br />
<br />
</head><br />
<body data-fgpanel="true" data-fgpanel-props="webpanel-properties.json"><br />
<div class="row"><br />
<div id="pc9m_ASI" class="instrument col-xs-2" data-fgpanel-instrument="pc9m_ASI.json"></div><br />
</div><br />
</body><br />
</html><br />
</syntaxhighlight><br />
<br />
<br />
This creates a file for browser to show instruments. Important is data-fgpanel-props="webpanel-properties.json"> which specifies planes properties .json file. In <div> tag id="pc9m_ASI" and data-fgpanel-instrument="pc9m_ASI.json" specifies what instrument is drawn into browser. To create a new instrument, add another <div> with new id tag and .json file. To create a new row for instruments start a new <div class="row">. See example from C172p planes folder /usr/share/games/flightgear/Aircraft/c172p/WebPanel/c172p-webpanel.html.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== INSTRUMENT_NAME.json ===<br />
<br />
INSTRUMENT_NAME.json file specifies how instrument behaves when Flightgears properties change. Create file named pc9m_ASI.json, save it to WebPanel folder and add following code into it:<br />
<syntaxhighlight land="xml"><br />
{ <br />
"src": "pc9m_ASI.svg",<br />
<br />
"animations": [<br />
{<br />
"element": "#Needle",<br />
"type": "transform",<br />
"transforms": [{<br />
"type": "rotate",<br />
"a": {<br />
"property": "ias",<br />
"interpolation": "AirspeedInterpolation.xml"<br />
},<br />
"x": 256,<br />
"y": 256<br />
}]<br />
}<br />
<br />
]<br />
}<br />
</syntaxhighlight><br />
<br />
"src": "pc9m_ASI.svg": filename of instruments .svg vector graphic file<br />
"element": "#Needle": instruments .svg images id what is meant to be animated<br />
"type": "rotate": we are rotating Needle layer of instrument image<br />
property "ias": Flightgears internal property that causes the movement<br />
"interpolation": file where interpolation is specified<br />
"x": 256, "y": 256: specifies origo for rotation. In our image size 512x512px, 256px is in middle of the image.<br />
<br />
<br />
=== INSTRUMENT_NAMEInterpolation.xml ===<br />
<br />
Create file AirspeedInterpolation.xml and save it to WebPanel folder with following code:<br />
<syntaxhighlight land="xml"><br />
<?xml version="1.0"?><br />
<!--<br />
This file is part of FlightGear, the free flight simulator<br />
http://www.flightgear.org/<br />
<br />
Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de<br />
<br />
This program is free software; you can redistribute it and/or<br />
modify it under the terms of the GNU General Public License as<br />
published by the Free Software Foundation; either version 2 of the<br />
License, or (at your option) any later version.<br />
<br />
This program is distributed in the hope that it will be useful, but<br />
WITHOUT ANY WARRANTY; without even the implied warranty of<br />
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br />
General Public License for more details.<br />
--><br />
<PropertyList><br />
<entry><ind> 0</ind><dep> 0</dep></entry><br />
<entry><ind> 35</ind><dep> 36</dep></entry><br />
<entry><ind> 40</ind><dep> 50</dep></entry><br />
<entry><ind> 60</ind><dep> 100</dep></entry><br />
<entry><ind> 80</ind><dep> 152</dep></entry><br />
<entry><ind> 100</ind><dep> 206</dep></entry><br />
<entry><ind> 120</ind><dep> 249</dep></entry><br />
<entry><ind> 140</ind><dep> 291</dep></entry><br />
<entry><ind> 160</ind><dep> 333</dep></entry><br />
<entry><ind> 190</ind><dep> 340</dep></entry><br />
</PropertyList><br />
</syntaxhighlight><br />
<br />
Interpolation lists first number input property (air speed in this example) and second number is angle for needle.<br />
<br />
<br />
<br />
<br />
<br />
=== Creating instrument graphics with Inkscape ===<br />
<br />
If you are not familiar with Inkscape, see [https://inkscape.org/en/learn/tutorials/ Inkscape tutorials].<br />
<br />
To create a instrument image, start creating a new 512x512 px size file with Inkscape. When drawing .svg file, following issues need to be kept in mind:<br />
* moving objects needs to be on a different layers<br />
* layers id needs to be renamed from Inkscapes XML editor. Layer animation will fail if id is not correct.<br />
<br />
Draw a round face and a simple needle on top of it<br />
*Create new layer and call it "Face". Draw a circle in it.<br />
*create new layers called "Needle" and draw a needle in it. Needles rotating point should be in middle of the drawing area. Rename its ID from XML editor to "Needle".<br />
*Save it with a pc9m_ASI.svg name in to PC-9m aircrafts WebPanel folder. <br />
<br />
<br />
<br />
=== Test WebPanel ===<br />
<br />
To test instrument in WebPanel, start Flightgear with "--httpd=8080" additional option to start Flightgears web server.<br />
<br />
When Flightgear has started, go to http://localhost:8080/aircraft-dir/WebPanel/webpanel.html address and simple instrument with one needle and without numbers should be visible.<br />
<br />
Start PC-9m and when speed is rising you should see needle to start moving.<br />
<br />
[[File:PC-9m WebPanel tutorial air speed instrument.jpg|thumb|Example of WebPanel instrument showing PC-9m airspeed in browser]]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=User:Vaipe&diff=103152User:Vaipe2016-08-19T06:14:22Z<p>Vaipe: </p>
<hr />
<div>== How to: Create instrument for Flightgear WebPanel ==<br />
<br />
This guide will show you how to create a one simple web based instrument for a WebPanel. In a picture below, a C172s WebPanel is shown in another monitor in front of a lcd tv used as a scenery visual.<br />
<br />
[[File:C172p WebPanel with TV as visual.jpg|thumb|Flightgear flightsimulators Cessna C172p WebPanel in monitor front of a TV used as visual]]<br />
<br />
First you should check that you can see a Cessna C172s WebPanel on a browser window. Start Flightgear with a C172s and from Flightgear's aircrafts menu, click "Panel in a Browser" and browser window should open with a working instrument panel. And when you start engine and lift off, instruments should be moving.<br />
<br />
This HowTo uses following software:<br />
* Ubuntu 16.04<br />
* Flightgear 2016.2.1<br />
* PC-9m aircraft<br />
* Inkscape<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== WebPanel folder and instrument files for aircraft ===<br />
<br />
Create a folder named "WebPanel" into Flightgear's aircraft folder. In Ubuntu, installed aircraft folders can be found from: /home/YOUR_USER_NAME/.fgfs/Aircraft/org.flightgear.official/Aircraft<br />
<br />
For WebPanel to work, following files are needed:<br />
* webpanel-properties.json (maps Flightgears internal properties for instruments)<br />
* webpanel.html (html page what is shown in browser)<br />
<br />
And for a single instrument, following files are needed:<br />
* INSTRUMENT_NAME.svg (vector image shown in www-page as flight instrument)<br />
* INSTRUMENT_NAME.json (for instrument animations)<br />
* INSTRUMENT_NAMEInterpolation.xml (not necessary file, but used if instrument animation needs to be non-linear)<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== webpanel-properties.json ===<br />
<br />
webpanel-properties.json file maps Flightgears internal properties to instruments. Create a file named webpanel-properties.json, save it to aircrafts WebPanel folder and insert following code into it:<br />
<syntaxhighlight land="xml"><br />
{<br />
"instrumentSelector": ".instrument",<br />
"instrumentDataKey": "fgpanel-instrument",<br />
"updateInterval": 32,<br />
<br />
"propertyMirror": [<br />
["ias", "/instrumentation/airspeed-indicator/indicated-speed-kt"]<br />
<br />
]<br />
}<br />
</syntaxhighlight><br />
<br />
This example file will take only planes indicated speed in knots and sends it to "ias". If you need multiple internal properties for one instrument or for creating other instruments, see example from /usr/share/games/flightgear/Aircraft/c172p/WebPanel/c172p-webpanel-properties.json file, for how more rows for multiple properties are added.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== WebPanel www-page file ===<br />
<br />
Create webpanel.html file and save it in WebPanel folder with following code:<br />
<br />
<syntaxhighlight land="html"><br />
<!DOCTYPE html><br />
<html><br />
<head><br />
<meta charset=utf-8 /><br />
<!-- Tweaks for panel on an ipad - from https://gist.github.com/tfausak/2222823 --><br />
<meta name="apple-mobile-web-app-capable" content="yes"><br />
<!-- meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" --><br />
<meta name="apple-touch-fullscreen" content="yes"><br />
<meta name="apple-mobile-web-app-status-bar-style" content="black"><br />
<br />
<title>FlightGear - PC-9m Instrument Panel</title><br />
<style type="text/css" media="screen"><br />
body,html {<br />
width: 100%;<br />
height: 100%;<br />
overflow: hidden;<br />
background-color: #000000;<br />
border: 0;<br />
margin: 0;<br />
padding: 0;<br />
}<br />
<br />
.instrument {<br />
border: 1px solid #131313;<br />
padding: 8px;<br />
background-color: #111111;<br />
}<br />
</style><br />
<br />
<br />
<script type="text/javascript" charset="utf-8"<br />
src="/3rdparty/jquery/jquery-1.11.1.min.js"></script><br />
<br />
<!-- Latest compiled and minified CSS --><br />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css"><br />
<!-- Latest compiled and minified JavaScript --><br />
<script src="bootstrap/bootstrap.min.js"></script><br />
<br />
<script type="text/javascript" charset="utf-8" src="/lib/jquery.fganimate.js"></script><br />
<script type="text/javascript" charset="utf-8" src="/lib/fgfs.js"></script><br />
<br />
</head><br />
<body data-fgpanel="true" data-fgpanel-props="webpanel-properties.json"><br />
<div class="row"><br />
<div id="pc9m_ASI" class="instrument col-xs-2" data-fgpanel-instrument="pc9m_ASI.json"></div><br />
</div><br />
</body><br />
</html><br />
</syntaxhighlight><br />
<br />
<br />
This creates a file for browser to show instruments. Important is data-fgpanel-props="webpanel-properties.json"> which specifies planes properties .json file. In <div> tag id="pc9m_ASI" and data-fgpanel-instrument="pc9m_ASI.json" specifies what instrument is drawn into browser. To create a new instrument, add another <div> with new id tag and .json file. To create a new row for instruments start a new <div class="row">. See example from C172p planes folder /usr/share/games/flightgear/Aircraft/c172p/WebPanel/c172p-webpanel.html.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== INSTRUMENT_NAME.json ===<br />
<br />
INSTRUMENT_NAME.json file specifies how instrument behaves when Flightgears properties change. Create file named pc9m_ASI.json, save it to WebPanel folder and add following code into it:<br />
<syntaxhighlight land="xml"><br />
{ <br />
"src": "pc9m_ASI.svg",<br />
<br />
"animations": [<br />
{<br />
"element": "#Needle",<br />
"type": "transform",<br />
"transforms": [{<br />
"type": "rotate",<br />
"a": {<br />
"property": "ias",<br />
"interpolation": "AirspeedInterpolation.xml"<br />
},<br />
"x": 256,<br />
"y": 256<br />
}]<br />
}<br />
<br />
]<br />
}<br />
</syntaxhighlight><br />
<br />
"src": "pc9m_ASI.svg": filename of instruments .svg vector graphic file<br />
"element": "#Needle": instruments .svg images id what is meant to be animated<br />
"type": "rotate": we are rotating Needle layer of instrument image<br />
property "ias": Flightgears internal property that causes the movement<br />
"interpolation": file where interpolation is specified<br />
"x": 256, "y": 256: specifies origo for rotation. In our image size 512x512px, 256px is in middle of the image.<br />
<br />
<br />
=== INSTRUMENT_NAMEInterpolation.xml ===<br />
<br />
Create file AirspeedInterpolation.xml and save it to WebPanel folder with following code:<br />
<syntaxhighlight land="xml"><br />
<?xml version="1.0"?><br />
<!--<br />
This file is part of FlightGear, the free flight simulator<br />
http://www.flightgear.org/<br />
<br />
Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de<br />
<br />
This program is free software; you can redistribute it and/or<br />
modify it under the terms of the GNU General Public License as<br />
published by the Free Software Foundation; either version 2 of the<br />
License, or (at your option) any later version.<br />
<br />
This program is distributed in the hope that it will be useful, but<br />
WITHOUT ANY WARRANTY; without even the implied warranty of<br />
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br />
General Public License for more details.<br />
--><br />
<PropertyList><br />
<entry><ind> 0</ind><dep> 0</dep></entry><br />
<entry><ind> 35</ind><dep> 36</dep></entry><br />
<entry><ind> 40</ind><dep> 50</dep></entry><br />
<entry><ind> 60</ind><dep> 100</dep></entry><br />
<entry><ind> 80</ind><dep> 152</dep></entry><br />
<entry><ind> 100</ind><dep> 206</dep></entry><br />
<entry><ind> 120</ind><dep> 249</dep></entry><br />
<entry><ind> 140</ind><dep> 291</dep></entry><br />
<entry><ind> 160</ind><dep> 333</dep></entry><br />
<entry><ind> 190</ind><dep> 340</dep></entry><br />
</PropertyList><br />
</syntaxhighlight><br />
<br />
Interpolation lists first number input property (air speed in this example) and second number is angle for needle.<br />
<br />
<br />
<br />
<br />
<br />
=== Creating instrument graphics with Inkscape ===<br />
<br />
If you are not familiar with Inkscape, see [https://inkscape.org/en/learn/tutorials/ Inkscape tutorials].<br />
<br />
To create a instrument image, start creating a new 512x512 px size file with Inkscape. When drawing .svg file, following issues need to be kept in mind:<br />
* moving objects needs to be on a different layers<br />
* layers id needs to be renamed from Inkscapes XML editor. Layer animation will fail if id is not correct.<br />
<br />
Draw a round face and a simple needle on top of it<br />
*Create new layer and call it "Face". Draw a circle in it.<br />
*create new layers called "Needle" and draw a needle in it. Needles rotating point should be in middle of the drawing area. Rename its ID from XML editor to "Needle".<br />
*Save it with a pc9m_ASI.svg name in to PC-9m aircrafts WebPanel folder. <br />
<br />
<br />
<br />
=== Test WebPanel ===<br />
<br />
To test instrument in WebPanel, start Flightgear with "--httpd=8080" additional option to start Flightgears web server.<br />
<br />
When Flightgear has started, go to http://localhost:8080/aircraft-dir/WebPanel/webpanel.html address and simple instrument with one needle and without numbers should be visible.<br />
<br />
Start PC-9m and when speed is rising you should see needle to start moving.<br />
<br />
[[File:PC-9m WebPanel tutorial air speed instrument.jpg|thumb|Example of WebPanel instrument showing PC-9m airspeed in browser]]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=User:Vaipe&diff=103151User:Vaipe2016-08-19T06:09:14Z<p>Vaipe: </p>
<hr />
<div>== How to: Create instrument for Flightgear WebPanel ==<br />
<br />
This guide will show you how to create a one simple web based instrument for a WebPanel. In a picture below, a C172s WebPanel is shown in another monitor in front of a lcd tv used as a scenery visual.<br />
<br />
[[File:C172p WebPanel with TV as visual.jpg|thumb|Flightgear flightsimulators Cessna C172p WebPanel in monitor front of a TV used as visual]]<br />
<br />
First you should check that you can see a Cessna C172s WebPanel on a browser window. Start Flightgear with a C172s and from Flightgear's aircrafts menu, click "Panel in a Browser" and browser window should open with a working instrument panel. And when you start engine and lift off, instruments should be moving.<br />
<br />
This HowTo uses following software:<br />
* Ubuntu 16.04<br />
* Flightgear 2016.2.1<br />
* PC-9m aircraft<br />
* Inkscape<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== WebPanel folder and instrument files for aircraft ===<br />
<br />
Create a folder named "WebPanel" into Flightgear's aircraft folder. In Ubuntu, installed aircraft folders can be found from: /home/YOUR_USER_NAME/.fgfs/Aircraft/org.flightgear.official/Aircraft<br />
<br />
For WebPanel to work, following files are needed:<br />
* webpanel-properties.json (maps Flightgears internal properties for instruments)<br />
* webpanel.html (html page what is shown in browser)<br />
<br />
and for a single instrument:<br />
* INSTRUMENT_NAME.svg (vector image shown in www-page as flight instrument)<br />
* INSTRUMENT_NAME.json (for instrument animations)<br />
* INSTRUMENT_NAMEInterpolation.xml (not necessary file, but used if instrument animation needs to be non-linear)<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== webpanel-properties.json ===<br />
<br />
webpanel-properties.json file maps Flightgears internal properties to instruments. Create a file named webpanel-properties.json and insert following code into aircrafts WebPanel-folder:<br />
<syntaxhighlight land="xml"><br />
{<br />
"instrumentSelector": ".instrument",<br />
"instrumentDataKey": "fgpanel-instrument",<br />
"updateInterval": 32,<br />
<br />
"propertyMirror": [<br />
["ias", "/instrumentation/airspeed-indicator/indicated-speed-kt"]<br />
<br />
]<br />
}<br />
</syntaxhighlight><br />
<br />
This example file will take only planes indicated speed in knots and sends it to "ias". If you need multiple internal properties for one instrument or for creating other instruments, see example from /usr/share/games/flightgear/Aircraft/c172p/WebPanel/c172p-webpanel-properties.json file, for how more rows for multiple properties are added.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== WebPanel www-page file ===<br />
<br />
Create webpanel.html file and save it with following:<br />
<br />
<syntaxhighlight land="html"><br />
<!DOCTYPE html><br />
<html><br />
<head><br />
<meta charset=utf-8 /><br />
<!-- Tweaks for panel on an ipad - from https://gist.github.com/tfausak/2222823 --><br />
<meta name="apple-mobile-web-app-capable" content="yes"><br />
<!-- meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" --><br />
<meta name="apple-touch-fullscreen" content="yes"><br />
<meta name="apple-mobile-web-app-status-bar-style" content="black"><br />
<br />
<title>FlightGear - PC-9m Instrument Panel</title><br />
<style type="text/css" media="screen"><br />
body,html {<br />
width: 100%;<br />
height: 100%;<br />
overflow: hidden;<br />
background-color: #000000;<br />
border: 0;<br />
margin: 0;<br />
padding: 0;<br />
}<br />
<br />
.instrument {<br />
border: 1px solid #131313;<br />
padding: 8px;<br />
background-color: #111111;<br />
}<br />
</style><br />
<br />
<br />
<script type="text/javascript" charset="utf-8"<br />
src="/3rdparty/jquery/jquery-1.11.1.min.js"></script><br />
<br />
<!-- Latest compiled and minified CSS --><br />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css"><br />
<!-- Latest compiled and minified JavaScript --><br />
<script src="bootstrap/bootstrap.min.js"></script><br />
<br />
<script type="text/javascript" charset="utf-8" src="/lib/jquery.fganimate.js"></script><br />
<script type="text/javascript" charset="utf-8" src="/lib/fgfs.js"></script><br />
<br />
</head><br />
<body data-fgpanel="true" data-fgpanel-props="webpanel-properties.json"><br />
<div class="row"><br />
<div id="pc9m_ASI" class="instrument col-xs-2" data-fgpanel-instrument="pc9m_ASI.json"></div><br />
</div><br />
</body><br />
</html><br />
</syntaxhighlight><br />
<br />
<br />
This creates a file for browser to show instruments. Important is data-fgpanel-props="webpanel-properties.json"> which specifies planes properties .json file. In <div> tag id="pc9m_ASI" and data-fgpanel-instrument="pc9m_ASI.json" specifies what instrument is drawn into browser. To create a new instrument, add another <div> with new id tag and .json file. To create a new row for instruments start a new <div class="row">. See example from C172p planes folder /usr/share/games/flightgear/Aircraft/c172p/WebPanel/c172p-webpanel.html.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== INSTRUMENT_NAME.json ===<br />
<br />
INSTRUMENT_NAME.json file (in this HowTo: pc9m_ASI.json) specifies how instrument behaves when Flightgears properties change. Create file named pc9m_ASI.json and add following into it:<br />
<syntaxhighlight land="xml"><br />
{ <br />
"src": "pc9m_ASI.svg",<br />
<br />
"animations": [<br />
{<br />
"element": "#Needle",<br />
"type": "transform",<br />
"transforms": [{<br />
"type": "rotate",<br />
"a": {<br />
"property": "ias",<br />
"interpolation": "AirspeedInterpolation.xml"<br />
},<br />
"x": 256,<br />
"y": 256<br />
}]<br />
}<br />
<br />
]<br />
}<br />
</syntaxhighlight><br />
<br />
"src": "pc9m_ASI.svg": filename of instruments .svg vector graphic file<br />
"element": "#Needle": instruments .svg images id what is meant to be animated<br />
"type": "rotate": we are rotating Needle layer of instrument image<br />
property "ias": Flightgears internal property that causes the movement<br />
"interpolation": file where interpolation is specified<br />
"x": 256, "y": 256: specifies origo for rotation. In our image size 512x512px, 256px is in middle of the image.<br />
<br />
<br />
=== INSTRUMENT_NAMEInterpolation.xml ===<br />
<br />
Create file AirspeedInterpolation.xml and save it with following code:<br />
<syntaxhighlight land="xml"><br />
<?xml version="1.0"?><br />
<!--<br />
This file is part of FlightGear, the free flight simulator<br />
http://www.flightgear.org/<br />
<br />
Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de<br />
<br />
This program is free software; you can redistribute it and/or<br />
modify it under the terms of the GNU General Public License as<br />
published by the Free Software Foundation; either version 2 of the<br />
License, or (at your option) any later version.<br />
<br />
This program is distributed in the hope that it will be useful, but<br />
WITHOUT ANY WARRANTY; without even the implied warranty of<br />
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br />
General Public License for more details.<br />
--><br />
<PropertyList><br />
<entry><ind> 0</ind><dep> 0</dep></entry><br />
<entry><ind> 35</ind><dep> 36</dep></entry><br />
<entry><ind> 40</ind><dep> 50</dep></entry><br />
<entry><ind> 60</ind><dep> 100</dep></entry><br />
<entry><ind> 80</ind><dep> 152</dep></entry><br />
<entry><ind> 100</ind><dep> 206</dep></entry><br />
<entry><ind> 120</ind><dep> 249</dep></entry><br />
<entry><ind> 140</ind><dep> 291</dep></entry><br />
<entry><ind> 160</ind><dep> 333</dep></entry><br />
<entry><ind> 190</ind><dep> 340</dep></entry><br />
</PropertyList><br />
</syntaxhighlight><br />
<br />
Interpolation lists first number input property (air speed in this example) and second number is angle for needle.<br />
<br />
<br />
<br />
<br />
<br />
=== Creating instrument graphics with Inkscape ===<br />
<br />
If you are not familiar with Inkscape, see https://inkscape.org/en/learn/tutorials/<br />
<br />
To create a instrument image, start creating a new 512x512 px size file with Inkscape. When drawing .svg file, following issues need to be kept in mind:<br />
* moving objects need to be on different layers<br />
* layers id needs to be renamed from Inkscapes XML editor. Animation will fail if id is not correct.<br />
<br />
Draw a round face and a simple needle on top of it<br />
*Create new layer and call it "Face". Draw a circle in it.<br />
*create new layers called "Needle" and draw a needle in it. Needles rotating point should be in middle of the drawing area. Rename its ID from XML editor to "Needle".<br />
*Save it with a pc9m_ASI.svg name in to PC-9m aircrafts WebPanel folder. <br />
<br />
<br />
=== Test WebPanel ===<br />
<br />
To test instrument in WebPanel, start Flightgear with "--httpd=8080" additional option to start Flightgears web server.<br />
<br />
When Flightgear has started, go to http://localhost:8080/aircraft-dir/WebPanel/webpanel.html address and simple instrument with one needle and without numbers should be visible.<br />
<br />
Start PC-9m and when speed is rising you should see needle to start moving.<br />
<br />
[[File:PC-9m WebPanel tutorial air speed instrument.jpg|thumb|Example of WebPanel instrument showing PC-9m airspeed in browser]]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=File:PC-9m_WebPanel_tutorial_air_speed_instrument.jpg&diff=103150File:PC-9m WebPanel tutorial air speed instrument.jpg2016-08-19T06:03:01Z<p>Vaipe: User created page with UploadWizard</p>
<hr />
<div>=={{int:filedesc}}==<br />
{{Information<br />
|description={{en|1=Example of WebPanel instrument showing PC-9m airspeed in browser}}<br />
|date=2016-08-19<br />
|source={{own}}<br />
|author=[[User:Vaipe|Vaipe]]<br />
|permission=<br />
|other versions=<br />
}}<br />
<br />
=={{int:license-header}}==<br />
{{self|cc-by-sa-4.0}}<br />
<br />
<br />
<br />
[[Category:WebPanel]]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=File:C172p_WebPanel_with_TV_as_visual.jpg&diff=103149File:C172p WebPanel with TV as visual.jpg2016-08-19T05:58:59Z<p>Vaipe: User created page with UploadWizard</p>
<hr />
<div>=={{int:filedesc}}==<br />
{{Information<br />
|description={{en|1=Flightgear flightsimulators Cessna C172p WebPanel in monitor front of a TV used as visual}}<br />
|date=2016-08-17 08:39:29<br />
|source={{own}}<br />
|author=[[User:Vaipe|Vaipe]]<br />
|permission=<br />
|other versions=<br />
}}<br />
{{Location dec|60.4631214|22.169137599722}}<br />
<br />
=={{int:license-header}}==<br />
{{self|cc-by-sa-4.0}}</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=User:Vaipe&diff=103148User:Vaipe2016-08-19T05:53:13Z<p>Vaipe: How to: Create instrument for Flightgear WebPanel</p>
<hr />
<div>== How to: Create instrument for Flightgear WebPanel ==<br />
<br />
This guide will show you how to create a one simple web based instrument for a WebPanel. In a picture below, a C172s WebPanel is shown in another monitor in front of a lcd tv used as a scenery visual.<br />
<br />
INSERT IMAGE HERE<br />
<br />
First you should check that you can see a Cessna C172s WebPanel on a browser window. Start Flightgear with a C172s and from Flightgear's aircrafts menu, click "Panel in a Browser" and browser window should open with a working instrument panel. And when you start engine and lift off, instruments should be moving.<br />
<br />
This HowTo uses following software:<br />
* Ubuntu 16.04<br />
* Flightgear 2016.2.1<br />
* PC-9m aircraft<br />
* Inkscape<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== WebPanel folder and instrument files for aircraft ===<br />
<br />
Create a folder named "WebPanel" into Flightgear's aircraft folder. In Ubuntu, installed aircraft folders can be found from: /home/YOUR_USER_NAME/.fgfs/Aircraft/org.flightgear.official/Aircraft<br />
<br />
For WebPanel to work, following files are needed:<br />
* webpanel-properties.json (maps Flightgears internal properties for instruments)<br />
* webpanel.html (html page what is shown in browser)<br />
<br />
and for a single instrument:<br />
* INSTRUMENT_NAME.svg (vector image shown in www-page as flight instrument)<br />
* INSTRUMENT_NAME.json (for instrument animations)<br />
* INSTRUMENT_NAMEInterpolation.xml (not necessary file, but used if instrument animation needs to be non-linear)<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== webpanel-properties.json ===<br />
<br />
webpanel-properties.json file maps Flightgears internal properties to instruments. Create a file named webpanel-properties.json and insert following code into aircrafts WebPanel-folder:<br />
<syntaxhighlight land="xml"><br />
{<br />
"instrumentSelector": ".instrument",<br />
"instrumentDataKey": "fgpanel-instrument",<br />
"updateInterval": 32,<br />
<br />
"propertyMirror": [<br />
["ias", "/instrumentation/airspeed-indicator/indicated-speed-kt"]<br />
<br />
]<br />
}<br />
</syntaxhighlight><br />
<br />
This example file will take only planes indicated speed in knots and sends it to "ias". If you need multiple internal properties for one instrument or for creating other instruments, see example from /usr/share/games/flightgear/Aircraft/c172p/WebPanel/c172p-webpanel-properties.json file, for how more rows for multiple properties are added.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== WebPanel www-page file ===<br />
<br />
Create webpanel.html file and save it with following:<br />
<br />
<syntaxhighlight land="html"><br />
<!DOCTYPE html><br />
<html><br />
<head><br />
<meta charset=utf-8 /><br />
<!-- Tweaks for panel on an ipad - from https://gist.github.com/tfausak/2222823 --><br />
<meta name="apple-mobile-web-app-capable" content="yes"><br />
<!-- meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" --><br />
<meta name="apple-touch-fullscreen" content="yes"><br />
<meta name="apple-mobile-web-app-status-bar-style" content="black"><br />
<br />
<title>FlightGear - PC-9m Instrument Panel</title><br />
<style type="text/css" media="screen"><br />
body,html {<br />
width: 100%;<br />
height: 100%;<br />
overflow: hidden;<br />
background-color: #000000;<br />
border: 0;<br />
margin: 0;<br />
padding: 0;<br />
}<br />
<br />
.instrument {<br />
border: 1px solid #131313;<br />
padding: 8px;<br />
background-color: #111111;<br />
}<br />
</style><br />
<br />
<br />
<script type="text/javascript" charset="utf-8"<br />
src="/3rdparty/jquery/jquery-1.11.1.min.js"></script><br />
<br />
<!-- Latest compiled and minified CSS --><br />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css"><br />
<!-- Latest compiled and minified JavaScript --><br />
<script src="bootstrap/bootstrap.min.js"></script><br />
<br />
<script type="text/javascript" charset="utf-8" src="/lib/jquery.fganimate.js"></script><br />
<script type="text/javascript" charset="utf-8" src="/lib/fgfs.js"></script><br />
<br />
</head><br />
<body data-fgpanel="true" data-fgpanel-props="webpanel-properties.json"><br />
<div class="row"><br />
<div id="pc9m_ASI" class="instrument col-xs-2" data-fgpanel-instrument="pc9m_ASI.json"></div><br />
</div><br />
</body><br />
</html><br />
</syntaxhighlight><br />
<br />
<br />
This creates a file for browser to show instruments. Important is data-fgpanel-props="webpanel-properties.json"> which specifies planes properties .json file. In <div> tag id="pc9m_ASI" and data-fgpanel-instrument="pc9m_ASI.json" specifies what instrument is drawn into browser. To create a new instrument, add another <div> with new id tag and .json file. To create a new row for instruments start a new <div class="row">. See example from C172p planes folder /usr/share/games/flightgear/Aircraft/c172p/WebPanel/c172p-webpanel.html.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
=== INSTRUMENT_NAME.json ===<br />
<br />
INSTRUMENT_NAME.json file (in this HowTo: pc9m_ASI.json) specifies how instrument behaves when Flightgears properties change. Create file named pc9m_ASI.json and add following into it:<br />
<syntaxhighlight land="xml"><br />
{ <br />
"src": "pc9m_ASI.svg",<br />
<br />
"animations": [<br />
{<br />
"element": "#Needle",<br />
"type": "transform",<br />
"transforms": [{<br />
"type": "rotate",<br />
"a": {<br />
"property": "ias",<br />
"interpolation": "AirspeedInterpolation.xml"<br />
},<br />
"x": 256,<br />
"y": 256<br />
}]<br />
}<br />
<br />
]<br />
}<br />
</syntaxhighlight><br />
<br />
"src": "pc9m_ASI.svg": filename of instruments .svg vector graphic file<br />
"element": "#Needle": instruments .svg images id what is meant to be animated<br />
"type": "rotate": we are rotating Needle layer of instrument image<br />
property "ias": Flightgears internal property that causes the movement<br />
"interpolation": file where interpolation is specified<br />
"x": 256, "y": 256: specifies origo for rotation. In our image size 512x512px, 256px is in middle of the image.<br />
<br />
<br />
=== INSTRUMENT_NAMEInterpolation.xml ===<br />
<br />
Create file AirspeedInterpolation.xml and save it with following code:<br />
<syntaxhighlight land="xml"><br />
<?xml version="1.0"?><br />
<!--<br />
This file is part of FlightGear, the free flight simulator<br />
http://www.flightgear.org/<br />
<br />
Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de<br />
<br />
This program is free software; you can redistribute it and/or<br />
modify it under the terms of the GNU General Public License as<br />
published by the Free Software Foundation; either version 2 of the<br />
License, or (at your option) any later version.<br />
<br />
This program is distributed in the hope that it will be useful, but<br />
WITHOUT ANY WARRANTY; without even the implied warranty of<br />
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br />
General Public License for more details.<br />
--><br />
<PropertyList><br />
<entry><ind> 0</ind><dep> 0</dep></entry><br />
<entry><ind> 35</ind><dep> 36</dep></entry><br />
<entry><ind> 40</ind><dep> 50</dep></entry><br />
<entry><ind> 60</ind><dep> 100</dep></entry><br />
<entry><ind> 80</ind><dep> 152</dep></entry><br />
<entry><ind> 100</ind><dep> 206</dep></entry><br />
<entry><ind> 120</ind><dep> 249</dep></entry><br />
<entry><ind> 140</ind><dep> 291</dep></entry><br />
<entry><ind> 160</ind><dep> 333</dep></entry><br />
<entry><ind> 190</ind><dep> 340</dep></entry><br />
</PropertyList><br />
</syntaxhighlight><br />
<br />
Interpolation lists first number input property (air speed in this example) and second number is angle for needle.<br />
<br />
<br />
<br />
<br />
<br />
=== Creating instrument graphics with Inkscape ===<br />
<br />
If you are not familiar with Inkscape, see https://inkscape.org/en/learn/tutorials/<br />
<br />
To create a instrument image, start creating a new 512x512 px size file with Inkscape. When drawing .svg file, following issues need to be kept in mind:<br />
* moving objects need to be on different layers<br />
* layers id needs to be renamed from Inkscapes XML editor. Animation will fail if id is not correct.<br />
<br />
Draw a round face and a simple needle on top of it<br />
*Create new layer and call it "Face". Draw a circle in it.<br />
*create new layers called "Needle" and draw a needle in it. Needles rotating point should be in middle of the drawing area. Rename its ID from XML editor to "Needle".<br />
*Save it with a pc9m_ASI.svg name in to PC-9m aircrafts WebPanel folder. <br />
<br />
You may download and use this sample svg image: FILE DOWNLOAD ADDRESS<br />
<br />
<br />
=== Test WebPanel ===<br />
<br />
To test instrument in WebPanel, start Flightgear with "--httpd=8080" additional option to start Flightgears web server.<br />
<br />
When Flightgear has started, go to http://localhost:8080/aircraft-dir/WebPanel/webpanel.html address and simple instrument with one needle and without numbers should be visible.<br />
<br />
Start PC-9m and when speed is rising you should see needle to start moving.</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=Howto:Use_Arduino_with_FlightGear&diff=80790Howto:Use Arduino with FlightGear2015-02-09T19:03:38Z<p>Vaipe: </p>
<hr />
<div>'''[http://www.arduino.cc/ Arduino]''' is an open-source electronics prototyping platform based on flexible, easy-to-use [[:Category:Hardware|hardware]] (consisting of a board designed around an 8-bit or a 32-bit microcontroller) and software [http://arduino.cc/en/main/software Arduino IDE]).<br />
[[FlightGear]]'s IO interface allows easy development of hardware that can improve the immersion and realism of the simulation. The output [[Generic protocol|protocol]] allow hardware to respond to simulation data, while the input protocol allows FlightGear to reply to hardware events (e.g., on the press of a button).<br />
<br />
== How to: Control Flightgear with Arduino ==<br />
<br />
With this "how to", you are able to do a switch and a potentiometer interface to control Flightgear's properties such as aileron, elevator, gears, lights, fuel valve, etc..<br />
<br />
=== Equipment and software ===<br />
<br />
This example uses following components and software:<br />
* [[Changelog_3.2|FlightGear 3.2]]<br />
* [[Flightgear Launch Control]] (program to make FlightGear start without terminal command and options)<br />
* Arduino UNO<br />
* Linux (Ubuntu 14.04)<br />
* On/off switch<br />
* Potentiometer<br />
* Flightgear's Cessna 172P Skyhawk<br />
<br />
===Input protocol file===<br />
<br />
Input protocol file is used to specify how serial information is read by Flightgear. In Ubuntu protocol files are found in:<br />
"/usr/share/games/flightgear/protocol" directory.<br />
<br />
====Protocol file structure====<br />
<br />
Create controltest.xml file to your protocol folder and paste code from below to it.<br />
<syntaxhighlight land="xml"><br />
<?xml version="1.0"?><br />
<PropertyList><br />
<generic><br />
<input><br />
<br />
<line_separator>\n</line_separator><br />
<var_separator>,</var_separator><br />
<br />
<chunk><br />
<name>Strobe</name><br />
<node>/controls/lighting/strobe</node><br />
<type>bool</type><br />
</chunk><br />
<br />
<chunk><br />
<name>Throttle</name><br />
<node>/controls/engines/engine/throttle</node><br />
<type>float</type><br />
</chunk><br />
<br />
</input><br />
</generic><br />
</PropertyList><br />
</code><br />
</syntaxhighlight><br />
Explanation of lines:<br />
<br />
*Line separator: "line_separator" is used to tell Flightgear that a line of commands is at end and new one is starting. In this example file its "/n" and it means new line.<br />
*Variable separator: "variable_separator" is used to tell Flightgear that another variable is after this mark. In this protocol file it's ",".<br />
*Chunk: "chunk" is to specify area for one variable and it's information.<br />
*Name: "name" is used only for identifying variable so it can be anything.<br />
*Node: "node" is an address to tell what property in Flightgear is changed. In this example it is "/controls/lighting/strobe" and "controls/engines/engine/throttle".<br />
*Type: "type" line tells what kind of command is send. In this example it is a "bool" and that means a boolean type of property of a "float" for float.<br />
<br />
For a better explanation of configuration file, read [[Generic_protocol|Generic Protocol]] wiki page. You can find a list of properties that can be controlled from a Flightgears docs-folder a file called "README.properties". Or you can use [[Property_browser|Flightgears Property Browser]] from main menu: Debug > Browse Internal Properties. Properties in protocol file needs to be in same order as they are send from Arduino.<br />
<br />
===Wiring and coding Arduino===<br />
<br />
====Wiring====<br />
Potentiometer is connected to Arduinos ground and +5 volts. Potentiometers middle connector is connected to A0 analoq input. Switch is connected to ground with 10 kOhms pull-down resistor and +5 and digital pin 7.<br />
[[File:Arduino switch and potentiometer wiring.png|frame|none|Wiring schematic for connecting potentiometer and switch to Arduino]]<br />
<br />
====Code====<br />
Copy this code to Arduino IDE and send it to Arduino Uno:<br />
<syntaxhighlight lang="c"><br />
/*<br />
FGFS Input Test<br />
Reads a digital input on pin 7, prints the result to the serial port.<br />
Reads a potentiometer input on A0 and print result to serial port.<br />
This example code is in the public domain.<br />
*/<br />
<br />
int potPin = 0; // potentiometer on A0<br />
int switchPin = 7; // switch on pin 7<br />
float potValue = 0; // float variable to store potentiometer value<br />
<br />
void setup() {<br />
Serial.begin(9600); // open serial connection<br />
pinMode(switchPin, INPUT); // pin 7 declared as input<br />
}<br />
<br />
<br />
void loop() {<br />
<br />
Serial.print(digitalRead(switchPin)); // read and print switch state<br />
Serial.print(","); // print ,<br />
potValue = analogRead(potPin); // read potentiometer and store it to potValue<br />
potValue = potValue / 1024; // divide potValue with 1024 to make it between 0 and 1<br />
PrintDouble(potValue, 2); // pass potValue to PrintDouble-function, read from below what magic happens<br />
Serial.print("\n"); // print new line<br />
delay(500); // delay only for making this guide easier to follow on serial monitor<br />
<br />
}<br />
<br />
<br />
void PrintDouble(double val, byte precision){<br />
// prints val with number of decimal places determine by precision<br />
// precision is a number from 0 to 6 indicating the desired decimial places<br />
// example: lcdPrintDouble( 3.1415, 2); // prints 3.14 (two decimal places)<br />
// From http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207226548<br />
<br />
if(val < 0.0){<br />
Serial.print('-');<br />
val = -val;<br />
}<br />
<br />
Serial.print (int(val)); //prints the int part<br />
if( precision > 0) {<br />
Serial.print("."); // print the decimal point<br />
unsigned long frac;<br />
unsigned long mult = 1;<br />
byte padding = precision -1;<br />
while(precision--)<br />
mult *=10;<br />
<br />
if(val >= 0)<br />
frac = (val - int(val)) * mult;<br />
else<br />
frac = (int(val)- val ) * mult;<br />
unsigned long frac1 = frac;<br />
while( frac1 /= 10 )<br />
padding--;<br />
while( padding--)<br />
Serial.print("0");<br />
Serial.print(frac,DEC) ;<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
====Test serial output====<br />
<br />
Use Arduino IDEs serial monitor and you should see something like this:<br />
[[File:Flightgear arduino serial monitor.png|frame|none|Arduino IDEs serial monitor output]]<br />
<br />
First number is switch data, so it's either 0 (switch off) or 1 (switch on). After "," mark is our throttle data. First it's 0.00 meaning idle throttle and then potentiometer is gradually turned until it reaches 0.99.<br />
<br />
{{Warning|Remember to '''unplug Arduino's USB cable and plug it back''' in because Flightgear won't be able to read serial without doing this! You have to do this every time after you use Arduino IDE.}}<br />
<br />
====Start Flightgear====<br />
<br />
Flightgear needs to be started with a correct command line option for it to be able to read serial connection. This example uses following option:<br />
<br />
--generic=serial,in,30,/dev/ttyACM0,controltest<br />
<br />
If you like, you can use graphical user interface, Flightgear Launch Control (aka FGRun), to launch Flightgear. Select correct settings from Advanced Option tab. [[File:Starting Flightgear with input options enabled.jpg|thumb|none|Starting Flightgear with FGLaunch Control, selecting input/output options]]<br />
<br />
If you don't now your correct port, you can check it with a following command in terminal: dmesg | tail. It should give you a message something like: "ttyACM0: USB ACM device" or "ttyACM1: USB ACM device". That's your port. Finally save setting by clicking 'OK' and click 'Run' to start flightgear. For more detailed guide, see [https://sites.google.com/site/flightgeararduinoandlinux/home Flightgear, Arduino and Linux]<br />
<br />
[[File:Arduinofgfs.jpg|thumb|270px|Arduino LCD panel displaying speed, heading and altitude.]]<br />
== Display/Generic protocol Example by rubdos ==<br />
<br />
Rubdos (Ruben De Smet) has built an example using the [[Generic Protocol]] and an Arduino Mega 2560.<br />
The code used to control the Arduino with generic protocol was:<br />
<syntaxhighlight lang="xml"><br />
<?xml version="1.0"?><br />
<PropertyList><br />
<generic><br />
<output><br />
<binary_mode>false</binary_mode><br />
<line_separator>newline</line_separator><br />
<var_separator>newline</var_separator><br />
<preamble></preamble><br />
<postamble></postamble><br />
<chunk><br />
<name>Altitude</name><br />
<node>/position/altitude-ft</node><br />
<type>integer</type><br />
<format>altitude=%i</format><br />
</chunk><br />
<chunk><br />
<name>RPM</name><br />
<node>/engines/engine/rpm</node><br />
<type>integer</type><br />
<format>rpm=%i</format><br />
</chunk><br />
</output><br />
<!-- <input><br />
<line_separator>newline</line_separator><br />
<var_separator>tab</var_separator><br />
<chunk><br />
</chunk><br />
</input><br />
--><br />
</generic><br />
</PropertyList><br />
</syntaxhighlight><br />
It is a simple plaintext protocol, which can easily be parsed by an Arduino. The code used on the Arduino is available on github as a gist: [https://gist.github.com/rubdos/5422870]<br />
<br />
As hardware, five seven segment displays were used, multiplexed straight on the Arduino device. In production, you'd rather use some 74HC595 or other shift register chips to drive them, to unload the Arduino and have more current.<br />
A demo is uploaded to youtube, with voiceover in which the display shows the RPM of the first engine of (the single engine) [[DR400]]: [https://www.youtube.com/watch?v=lVtV9-CgqBo]<br />
<br />
== Related content ==<br />
* [[Input device]]<br />
<br />
== External links ==<br />
* [http://arduino.cc/ Official website]<br />
* [http://playground.arduino.cc/Main/FlightGear FlightGear Serial Communications with Arduino] (tutorial)<br />
* [http://forum.flightgear.org/viewtopic.php?f=18&t=11126 Arduino LCD and FlightGear] (FlightGear forum)<br />
* [https://sites.google.com/site/flightgeararduinoandlinux/ Flightgear, Arduino and Linux] (potentiometer and switch interfacing tutorial)<br />
<br />
[[Category:Cockpit building]]<br />
[[Category:Hardware]]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=Howto:Use_Arduino_with_FlightGear&diff=80789Howto:Use Arduino with FlightGear2015-02-09T18:37:57Z<p>Vaipe: </p>
<hr />
<div>'''[http://www.arduino.cc/ Arduino]''' is an open-source electronics prototyping platform based on flexible, easy-to-use [[:Category:Hardware|hardware]] (consisting of a board designed around an 8-bit or a 32-bit microcontroller) and software [http://arduino.cc/en/main/software Arduino IDE]).<br />
[[FlightGear]]'s IO interface allows easy development of hardware that can improve the immersion and realism of the simulation. The output [[Generic protocol|protocol]] allow hardware to respond to simulation data, while the input protocol allows FlightGear to reply to hardware events (e.g., on the press of a button).<br />
<br />
== How to: Control Flightgear with Arduino ==<br />
<br />
With this "how to", you are able to do a switch and a potentiometer interface to control Flightgear's properties such as aileron, elevator, gears, lights, fuel valve, etc..<br />
<br />
=== Equipment and software ===<br />
<br />
This example uses following components and software:<br />
* [[Changelog_3.2|FlightGear 3.2]]<br />
* [[Flightgear Launch Control]] (program to make FlightGear start without terminal command and options)<br />
* Arduino UNO<br />
* Linux (Ubuntu 14.04)<br />
* On/off switch<br />
* Potentiometer<br />
* Flightgear's Cessna 172P Skyhawk<br />
<br />
===Input protocol file===<br />
<br />
Input protocol file is used to specify how serial information is read by Flightgear. In Ubuntu protocol files are found in:<br />
"/usr/share/games/flightgear/protocol" directory.<br />
<br />
====Protocol file structure====<br />
<br />
Create controltest.xml file to your protocol folder and paste code from below to it.<br />
<syntaxhighlight land="xml"><br />
<?xml version="1.0"?><br />
<PropertyList><br />
<generic><br />
<input><br />
<br />
<line_separator>\n</line_separator><br />
<var_separator>,</var_separator><br />
<br />
<chunk><br />
<name>Strobe</name><br />
<node>/controls/lighting/strobe</node><br />
<type>bool</type><br />
</chunk><br />
<br />
<chunk><br />
<name>Throttle</name><br />
<node>/controls/engines/engine/throttle</node><br />
<type>float</type><br />
</chunk><br />
<br />
</input><br />
</generic><br />
</PropertyList><br />
</code><br />
</syntaxhighlight><br />
Explanation of lines:<br />
<br />
*Line separator: "line_separator" is used to tell Flightgear that a line of commands is at end and new one is starting. In this example file its "/n" and it means new line.<br />
*Variable separator: "variable_separator" is used to tell Flightgear that another variable is after this mark. In this protocol file it's ",".<br />
*Chunk: "chunk" is to specify area for one variable and it's information.<br />
*Name: "name" is used only for identifying variable so it can be anything.<br />
*Node: "node" is an address to tell what property in Flightgear is changed. In this example it is "/controls/lighting/strobe" and "controls/engines/engine/throttle".<br />
*Type: "type" line tells what kind of command is send. In this example it is a "bool" and that means a boolean type of property of a "float" for float.<br />
<br />
For a better explanation of configuration file, read [[Generic_protocol|Generic Protocol]] wiki page. You can find a list of properties that can be controlled from a Flightgears docs-folder a file called "README.properties". Or you can use [[Property_browser|Flightgears Property Browser]] from main menu: Debug > Browse Internal Properties. Properties in protocol file needs to be in same order as they are send from Arduino.<br />
<br />
===Wiring and coding Arduino===<br />
<br />
====Wiring====<br />
Potentiometer is connected to Arduinos ground and +5 volts. Potentiometers middle connector is connected to A0 analoq input. Switch is connected to ground with 10 kOhms pull-down resistor and +5 and digital pin 7.<br />
[[File:Arduino switch and potentiometer wiring.png|frame|none|Wiring schematic for connecting potentiometer and switch to Arduino]]<br />
<br />
====Code====<br />
Copy this code to Arduino IDE and send it to Arduino Uno:<br />
<syntaxhighlight lang=""><br />
/*<br />
FGFS Input Test<br />
Reads a digital input on pin 7, prints the result to the serial port.<br />
Reads a potentiometer input on A0 and print result to serial port.<br />
This example code is in the public domain.<br />
*/<br />
<br />
int potPin = 0; // potentiometer on A0<br />
int switchPin = 7; // switch on pin 7<br />
float potValue = 0; // float variable to store potentiometer value<br />
<br />
void setup() {<br />
Serial.begin(9600); // open serial connection<br />
pinMode(switchPin, INPUT); // pin 7 declared as input<br />
}<br />
<br />
<br />
void loop() {<br />
<br />
Serial.print(digitalRead(switchPin)); // read and print switch state<br />
Serial.print(","); // print ,<br />
potValue = analogRead(potPin); // read potentiometer and store it to potValue<br />
potValue = potValue / 1024; // divide potValue with 1024 to make it between 0 and 1<br />
PrintDouble(potValue, 2); // pass potValue to PrintDouble-function, read from below what magic happens<br />
Serial.print("\n"); // print new line<br />
delay(500); // delay only for making this guide easier to follow on serial monitor<br />
<br />
}<br />
<br />
<br />
void PrintDouble(double val, byte precision){<br />
// prints val with number of decimal places determine by precision<br />
// precision is a number from 0 to 6 indicating the desired decimial places<br />
// example: lcdPrintDouble( 3.1415, 2); // prints 3.14 (two decimal places)<br />
// From http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207226548<br />
<br />
if(val < 0.0){<br />
Serial.print('-');<br />
val = -val;<br />
}<br />
<br />
Serial.print (int(val)); //prints the int part<br />
if( precision > 0) {<br />
Serial.print("."); // print the decimal point<br />
unsigned long frac;<br />
unsigned long mult = 1;<br />
byte padding = precision -1;<br />
while(precision--)<br />
mult *=10;<br />
<br />
if(val >= 0)<br />
frac = (val - int(val)) * mult;<br />
else<br />
frac = (int(val)- val ) * mult;<br />
unsigned long frac1 = frac;<br />
while( frac1 /= 10 )<br />
padding--;<br />
while( padding--)<br />
Serial.print("0");<br />
Serial.print(frac,DEC) ;<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
====Test serial output====<br />
<br />
Use Arduino IDEs serial monitor and you should see something like this:<br />
[[File:Flightgear arduino serial monitor.png|frame|none|Arduino IDEs serial monitor output]]<br />
<br />
First number is switch data, so it's either 0 (switch off) or 1 (switch on). After "," mark is our throttle data. First it's 0.00 meaning idle throttle and then potentiometer is gradually turned until it reaches 0.99.<br />
<br />
{{Warning|Remember to '''unplug Arduino's USB cable and plug it back''' in because Flightgear won't be able to read serial without doing this! You have to do this every time after you use Arduino IDE.}}<br />
<br />
====Start Flightgear====<br />
<br />
Flightgear needs to be started with a correct command line option for it to be able to read serial connection. This example uses following option:<br />
<br />
--generic=serial,in,30,/dev/ttyACM0,controltest<br />
<br />
If you like, you can use graphical user interface, Flightgear Launch Control (aka FGRun), to launch Flightgear. Select correct settings from Advanced Option tab. [[File:Starting Flightgear with input options enabled.jpg|thumb|none|Starting Flightgear with FGLaunch Control, selecting input/output options]]<br />
<br />
If you don't now your correct port, you can check it with a following command in terminal: dmesg | tail. It should give you a message something like: "ttyACM0: USB ACM device" or "ttyACM1: USB ACM device". That's your port. Finally save setting by clicking 'OK' and click 'Run' to start flightgear. For more detailed guide, see [https://sites.google.com/site/flightgeararduinoandlinux/home Flightgear, Arduino and Linux]<br />
<br />
[[File:Arduinofgfs.jpg|thumb|270px|Arduino LCD panel displaying speed, heading and altitude.]]<br />
== Display/Generic protocol Example by rubdos ==<br />
<br />
Rubdos (Ruben De Smet) has built an example using the [[Generic Protocol]] and an Arduino Mega 2560.<br />
The code used to control the Arduino with generic protocol was:<br />
<syntaxhighlight lang="xml"><br />
<?xml version="1.0"?><br />
<PropertyList><br />
<generic><br />
<output><br />
<binary_mode>false</binary_mode><br />
<line_separator>newline</line_separator><br />
<var_separator>newline</var_separator><br />
<preamble></preamble><br />
<postamble></postamble><br />
<chunk><br />
<name>Altitude</name><br />
<node>/position/altitude-ft</node><br />
<type>integer</type><br />
<format>altitude=%i</format><br />
</chunk><br />
<chunk><br />
<name>RPM</name><br />
<node>/engines/engine/rpm</node><br />
<type>integer</type><br />
<format>rpm=%i</format><br />
</chunk><br />
</output><br />
<!-- <input><br />
<line_separator>newline</line_separator><br />
<var_separator>tab</var_separator><br />
<chunk><br />
</chunk><br />
</input><br />
--><br />
</generic><br />
</PropertyList><br />
</syntaxhighlight><br />
It is a simple plaintext protocol, which can easily be parsed by an Arduino. The code used on the Arduino is available on github as a gist: [https://gist.github.com/rubdos/5422870]<br />
<br />
As hardware, five seven segment displays were used, multiplexed straight on the Arduino device. In production, you'd rather use some 74HC595 or other shift register chips to drive them, to unload the Arduino and have more current.<br />
A demo is uploaded to youtube, with voiceover in which the display shows the RPM of the first engine of (the single engine) [[DR400]]: [https://www.youtube.com/watch?v=lVtV9-CgqBo]<br />
<br />
== Related content ==<br />
* [[Input device]]<br />
<br />
== External links ==<br />
* [http://arduino.cc/ Official website]<br />
* [http://playground.arduino.cc/Main/FlightGear FlightGear Serial Communications with Arduino] (tutorial)<br />
* [http://forum.flightgear.org/viewtopic.php?f=18&t=11126 Arduino LCD and FlightGear] (FlightGear forum)<br />
* [https://sites.google.com/site/flightgeararduinoandlinux/ Flightgear, Arduino and Linux] (potentiometer and switch interfacing tutorial)<br />
<br />
[[Category:Cockpit building]]<br />
[[Category:Hardware]]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=Howto:Use_Arduino_with_FlightGear&diff=80779Howto:Use Arduino with FlightGear2015-02-09T14:54:06Z<p>Vaipe: </p>
<hr />
<div><br />
'''[http://www.arduino.cc/ Arduino]''' is an open-source electronics prototyping platform based on flexible, easy-to-use [[:Category:Hardware|hardware]] (consisting of a board designed around an 8-bit or a 32-bit microcontroller) and software [http://arduino.cc/en/main/software Arduino IDE]).<br />
[[FlightGear]]'s IO interface allows easy development of hardware that can improve the immersion and realism of the simulation. The output [[Generic protocol|protocols]] allow hardware to response to simulation data, while the input protocol allows FlightGear to reply to hardware events (eg. on the press of a button).<br />
<br />
==How to: Control Flightgear with Arduino==<br />
<br />
With this "how to", you are able to do a switch and a potentiometer interface to control Flightgears properties such as aileron, elevator, gears, lights, fuel valve, etc.<br />
<br />
===Equipment and software===<br />
<br />
This example uses following components and software:<br />
*FlightGear 3.2<br />
*[[FlightGear_Launch_Control|Flightgear Launch Control]] (program to make FlightGear start without terminal command and options)<br />
*Arduino UNO<br />
*Linux (Ubuntu 14.04)<br />
*on/off switch<br />
*potentiometer<br />
*Flightgears Cessna 172P Skyhawk<br />
<br />
===Input protocol file===<br />
<br />
Input protocol file is used to specify how serial information is read by Flightgear. In Ubuntu protocol files are found in:<br />
"/usr/share/games/flightgear/protocol" directory.<br />
<br />
====Protocol file structure====<br />
<br />
Create controltest.xml file to your protocol folder and paste code from below to it.<br />
<br />
<?xml version="1.0"?><br />
<PropertyList><br />
<generic><br />
<input><br />
<br />
<line_separator>\n</line_separator><br />
<var_separator>,</var_separator><br />
<br />
<chunk><br />
<name>Strobe</name><br />
<node>/controls/lighting/strobe</node><br />
<type>bool</type><br />
</chunk><br />
<br />
<chunk><br />
<name>Throttle</name><br />
<node>/controls/engines/engine/throttle</node><br />
<type>float</type><br />
</chunk><br />
<br />
</input><br />
</generic><br />
</PropertyList><br />
</code><br />
<br />
Explanation of lines:<br />
<br />
*Line separator: "line_separator" is used to tell Flightgear that a line of commands is at end and new one is starting. In this example file its "/n" and it means new line.<br />
*Variable separator: "variable_separator" is used to tell Flightgear that another variable is after this mark. In this protocol file it's ",".<br />
*Chunk: "chunk" is to specify area for one variable and it's information.<br />
*Name: "name" is used only for identifying variable so it can be anything.<br />
*Node: "node" is an address to tell what property in Flightgear is changed. In this example it is "/controls/lighting/strobe" and "controls/engines/engine/throttle".<br />
*Type: "type" line tells what kind of command is send. In this example it is a "bool" and that means a boolean type of property of a "float" for float.<br />
<br />
For a better explanation of configuration file, read [[Generic_protocol|Generic Protocol]] wiki page. You can find a list of properties that can be controlled from a Flightgears docs-folder a file called "README.properties". Or you can use [[Property_browser|Flightgears Property Browser]] from main menu: Debug > Browse Internal Properties. Properties in protocol file needs to be in same order as they are send from Arduino.<br />
<br />
===Wiring and coding Arduino===<br />
<br />
====Wiring====<br />
Potentiometer is connected to Arduinos ground and +5 volts. Potentiometers middle connector is connected to A0 analoq input. Switch is connected to ground with 10 kOhms pull-down resistor and +5 and digital pin 7.<br />
[[File:Arduino switch and potentiometer wiring.png|frame|none|Wiring schematic for connecting potentiometer and switch to Arduino]]<br />
<br />
====Code====<br />
Copy this code to Arduino IDE and send it to Arduino Uno:<br />
<br />
/*<br />
FGFS Input Test<br />
Reads a digital input on pin 7, prints the result to the serial port.<br />
Reads a potentiometer input on A0 and print result to serial port.<br />
This example code is in the public domain.<br />
*/<br />
<br />
int potPin = 0; // potentiometer on A0<br />
int switchPin = 7; // switch on pin 7<br />
float potValue = 0; // float variable to store potentiometer value<br />
<br />
void setup() {<br />
Serial.begin(9600); // open serial connection<br />
pinMode(switchPin, INPUT); // pin 7 declared as input<br />
}<br />
<br />
<br />
void loop() {<br />
<br />
Serial.print(digitalRead(switchPin)); // read and print switch state<br />
Serial.print(","); // print ,<br />
potValue = analogRead(potPin); // read potentiometer and store it to potValue<br />
potValue = potValue / 1024; // divide potValue with 1024 to make it between 0 and 1<br />
PrintDouble(potValue, 2); // pass potValue to PrintDouble-function, read from below what magic happens<br />
Serial.print("\n"); // print new line<br />
delay(500); // delay only for making this guide easier to follow on serial monitor<br />
<br />
}<br />
<br />
<br />
void PrintDouble(double val, byte precision){<br />
// prints val with number of decimal places determine by precision<br />
// precision is a number from 0 to 6 indicating the desired decimial places<br />
// example: lcdPrintDouble( 3.1415, 2); // prints 3.14 (two decimal places)<br />
// From http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207226548<br />
<br />
if(val < 0.0){<br />
Serial.print('-');<br />
val = -val;<br />
}<br />
<br />
Serial.print (int(val)); //prints the int part<br />
if( precision > 0) {<br />
Serial.print("."); // print the decimal point<br />
unsigned long frac;<br />
unsigned long mult = 1;<br />
byte padding = precision -1;<br />
while(precision--)<br />
mult *=10;<br />
<br />
if(val >= 0)<br />
frac = (val - int(val)) * mult;<br />
else<br />
frac = (int(val)- val ) * mult;<br />
unsigned long frac1 = frac;<br />
while( frac1 /= 10 )<br />
padding--;<br />
while( padding--)<br />
Serial.print("0");<br />
Serial.print(frac,DEC) ;<br />
}<br />
}<br />
<br />
====Test serial output====<br />
<br />
Use Arduino IDEs serial monitor and you should see something like this:<br />
[[File:Flightgear arduino serial monitor.png|frame|none|Arduino IDEs serial monitor output]]<br />
<br />
First number is switch data, so it's either 0 (switch off) or 1 (switch on). After "," mark is our throttle data. First it's 0.00 meaning idle throttle and then potentiometer is gradually turned until it reaches 0.99.<br />
<br />
'''NOTE!''' Remember to '''unplug Arduino's USB cable and plug it back''' in because Flightgear won't be able to read serial without doing this! You have to do this every time after you use Arduino IDE.<br />
<br />
====Start Flightgear====<br />
<br />
Flightgear needs to be started with a correct command line option for it to be able to read serial connection. This example uses following option:<br />
--generic=serial,in,30,/dev/ttyACM0,controltest<br />
<br />
If you like, you can use graphical user interface, Flightgear Launch Control (aka FGRun), to launch Flightgear. Select correct settings from Advanced Option tab. [[File:Starting Flightgear with input options enabled.jpg|thumb|none|Starting Flightgear with FGLaunch Control, selecting input/output options]]<br />
<br />
If you don't now your correct port, you can check it with a following command in terminal: dmesg | tail. It should give you a message something like: "ttyACM0: USB ACM device" or "ttyACM1: USB ACM device". That's your port. Finally save setting by clicking 'OK' and click 'Run' to start flightgear. For more detailed guide, see [https://sites.google.com/site/flightgeararduinoandlinux/home Flightgear, Arduino and Linux]<br />
<br />
<br />
[[File:Arduinofgfs.jpg|thumb|270px|Arduino LCD panel displaying speed, heading and altitude.]]<br />
== Display/Generic protocol Example by rubdos ==<br />
<br />
Rubdos (Ruben De Smet) has built an example using the [[Generic Protocol]] and an Arduino Mega 2560.<br />
The code used to control the Arduino with generic protocol was:<br />
<?xml version="1.0"?><br />
<PropertyList><br />
<generic><br />
<output><br />
<binary_mode>false</binary_mode><br />
<line_separator>newline</line_separator><br />
<var_separator>newline</var_separator><br />
<preamble></preamble><br />
<postamble></postamble><br />
<chunk><br />
<name>Altitude</name><br />
<node>/position/altitude-ft</node><br />
<type>integer</type><br />
<format>altitude=%i</format><br />
</chunk><br />
<chunk><br />
<name>RPM</name><br />
<node>/engines/engine/rpm</node><br />
<type>integer</type><br />
<format>rpm=%i</format><br />
</chunk><br />
</output><br />
<!-- <input><br />
<line_separator>newline</line_separator><br />
<var_separator>tab</var_separator><br />
<chunk><br />
</chunk><br />
</input><br />
--><br />
</generic><br />
</PropertyList><br />
It is a simple plaintext protocol, which can easily be parsed by an Arduino. The code used on the Arduino is available on github as a gist: [https://gist.github.com/rubdos/5422870]<br />
<br />
As hardware, five seven segment displays were used, multiplexed straight on the Arduino device. In production, you'd rather use some 74HC595 or other shift register chips to drive them, to unload the Arduino and have more current.<br />
A demo is uploaded to youtube, with voiceover in which the display shows the RPM of the first engine of (the single engine) [[DR400]]: [https://www.youtube.com/watch?v=lVtV9-CgqBo]<br />
<br />
== Related content ==<br />
* [[Input device]]<br />
<br />
== External links ==<br />
* [http://arduino.cc/ Official website]<br />
* [http://playground.arduino.cc/Main/FlightGear FlightGear Serial Communications with Arduino] (tutorial)<br />
* [http://forum.flightgear.org/viewtopic.php?f=18&t=11126 Arduino LCD and FlightGear] (FlightGear forum)<br />
* [https://sites.google.com/site/flightgeararduinoandlinux/ Flightgear, Arduino and Linux] (potentiometer and switch interfacing tutorial)<br />
<br />
[[Category:Cockpit building]]<br />
[[Category:Hardware]]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=File:Starting_Flightgear_with_input_options_enabled.jpg&diff=79888File:Starting Flightgear with input options enabled.jpg2015-02-09T08:58:12Z<p>Vaipe: User created page with UploadWizard</p>
<hr />
<div>=={{int:filedesc}}==<br />
{{Information<br />
|description={{en|1=Starting Flightgear with FGLaunch Control, selecting input/output options}}<br />
|date=2015-02-09 10:56:49<br />
|source={{own}}<br />
|author=[[User:Vaipe|Vaipe]]<br />
|permission=<br />
|other versions=<br />
}}<br />
<br />
=={{int:license-header}}==<br />
{{self|cc-by-sa-4.0}}</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=File:Flightgear_arduino_serial_monitor.png&diff=79887File:Flightgear arduino serial monitor.png2015-02-09T08:45:50Z<p>Vaipe: User created page with UploadWizard</p>
<hr />
<div>=={{int:filedesc}}==<br />
{{Information<br />
|description={{en|1=Arduino IDEs serial monitor output}}<br />
|date=2015-02-09 10:44:06<br />
|source={{own}}<br />
|author=[[User:Vaipe|Vaipe]]<br />
|permission=<br />
|other versions=<br />
}}<br />
<br />
=={{int:license-header}}==<br />
{{self|cc-by-sa-4.0}}</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=File:Arduino_switch_and_potentiometer_wiring.png&diff=79810File:Arduino switch and potentiometer wiring.png2015-02-07T19:13:34Z<p>Vaipe: User created page with UploadWizard</p>
<hr />
<div>=={{int:filedesc}}==<br />
{{Information<br />
|description={{en|1=Wiring schematic for connecting potentiometer and switch to Arduino}}<br />
|date=2015-02-07 21:06:03<br />
|source={{own}}<br />
|author=[[User:Vaipe|Vaipe]]<br />
|permission=<br />
|other versions=<br />
}}<br />
<br />
=={{int:license-header}}==<br />
{{self|cc-by-sa-4.0}}</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=Howto:Use_Arduino_with_FlightGear&diff=78522Howto:Use Arduino with FlightGear2014-12-24T05:50:56Z<p>Vaipe: /* External links */</p>
<hr />
<div>[[File:Arduinofgfs.jpg|thumb|270px|Arduino LCD panel displaying speed, heading and altitude.]]<br />
'''Arduino''' is an open-source electronics prototyping platform based on flexible, easy-to-use [[:Category:Hardware|hardware]] (consisting of a board designed around an 8-bit or a 32-bit microcontroller) and software (based on an integrated development environment (IDE)).<br />
[[FlightGear]]'s IO interface allows easy development of hardware that can improve the immersion and realism of the simulation. The output [[Generic protocol|protocols]] allow hardware to response to simulation data (like shown in the image on the right), while the input protocol allows FlightGear to reply to hardware events (eg. on the press of a button).<br />
<br />
== Display/Generic protocol Example by rubdos ==<br />
<br />
Rubdos (Ruben De Smet) has built an example using the [[Generic Protocol]] and an Arduino Mega 2560.<br />
The code used to control the Arduino with generic protocol was:<br />
<?xml version="1.0"?><br />
<PropertyList><br />
<generic><br />
<output><br />
<binary_mode>false</binary_mode><br />
<line_separator>newline</line_separator><br />
<var_separator>newline</var_separator><br />
<preamble></preamble><br />
<postamble></postamble><br />
<chunk><br />
<name>Altitude</name><br />
<node>/position/altitude-ft</node><br />
<type>integer</type><br />
<format>altitude=%i</format><br />
</chunk><br />
<chunk><br />
<name>RPM</name><br />
<node>/engines/engine/rpm</node><br />
<type>integer</type><br />
<format>rpm=%i</format><br />
</chunk><br />
</output><br />
<!-- <input><br />
<line_separator>newline</line_separator><br />
<var_separator>tab</var_separator><br />
<chunk><br />
</chunk><br />
</input><br />
--><br />
</generic><br />
</PropertyList><br />
It is a simple plaintext protocol, which can easily be parsed by an Arduino. The code used on the Arduino is available on github as a gist: [https://gist.github.com/rubdos/5422870]<br />
<br />
As hardware, five seven segment displays were used, multiplexed straight on the Arduino device. In production, you'd rather use some 74HC595 or other shift register chips to drive them, to unload the Arduino and have more current.<br />
A demo is uploaded to youtube, with voiceover in which the display shows the RPM of the first engine of (the single engine) [[DR400]]: [https://www.youtube.com/watch?v=lVtV9-CgqBo]<br />
<br />
== Related content ==<br />
* [[Input device]]<br />
<br />
== External links ==<br />
* [http://arduino.cc/ Official website]<br />
* [http://playground.arduino.cc/Main/FlightGear FlightGear Serial Communications with Arduino] (tutorial)<br />
* [http://forum.flightgear.org/viewtopic.php?f=18&t=11126 Arduino LCD and FlightGear] (FlightGear forum)<br />
* [https://sites.google.com/site/flightgeararduinoandlinux/ Flightgear, Arduino and Linux] (potentiometer and switch interfacing tutorial)<br />
<br />
[[Category:Cockpit building]]<br />
[[Category:Hardware]]</div>Vaipehttps://wiki.flightgear.org/w/index.php?title=Howto:Use_Arduino_with_FlightGear&diff=78521Howto:Use Arduino with FlightGear2014-12-24T05:44:16Z<p>Vaipe: /* External links */</p>
<hr />
<div>[[File:Arduinofgfs.jpg|thumb|270px|Arduino LCD panel displaying speed, heading and altitude.]]<br />
'''Arduino''' is an open-source electronics prototyping platform based on flexible, easy-to-use [[:Category:Hardware|hardware]] (consisting of a board designed around an 8-bit or a 32-bit microcontroller) and software (based on an integrated development environment (IDE)).<br />
[[FlightGear]]'s IO interface allows easy development of hardware that can improve the immersion and realism of the simulation. The output [[Generic protocol|protocols]] allow hardware to response to simulation data (like shown in the image on the right), while the input protocol allows FlightGear to reply to hardware events (eg. on the press of a button).<br />
<br />
== Display/Generic protocol Example by rubdos ==<br />
<br />
Rubdos (Ruben De Smet) has built an example using the [[Generic Protocol]] and an Arduino Mega 2560.<br />
The code used to control the Arduino with generic protocol was:<br />
<?xml version="1.0"?><br />
<PropertyList><br />
<generic><br />
<output><br />
<binary_mode>false</binary_mode><br />
<line_separator>newline</line_separator><br />
<var_separator>newline</var_separator><br />
<preamble></preamble><br />
<postamble></postamble><br />
<chunk><br />
<name>Altitude</name><br />
<node>/position/altitude-ft</node><br />
<type>integer</type><br />
<format>altitude=%i</format><br />
</chunk><br />
<chunk><br />
<name>RPM</name><br />
<node>/engines/engine/rpm</node><br />
<type>integer</type><br />
<format>rpm=%i</format><br />
</chunk><br />
</output><br />
<!-- <input><br />
<line_separator>newline</line_separator><br />
<var_separator>tab</var_separator><br />
<chunk><br />
</chunk><br />
</input><br />
--><br />
</generic><br />
</PropertyList><br />
It is a simple plaintext protocol, which can easily be parsed by an Arduino. The code used on the Arduino is available on github as a gist: [https://gist.github.com/rubdos/5422870]<br />
<br />
As hardware, five seven segment displays were used, multiplexed straight on the Arduino device. In production, you'd rather use some 74HC595 or other shift register chips to drive them, to unload the Arduino and have more current.<br />
A demo is uploaded to youtube, with voiceover in which the display shows the RPM of the first engine of (the single engine) [[DR400]]: [https://www.youtube.com/watch?v=lVtV9-CgqBo]<br />
<br />
== Related content ==<br />
* [[Input device]]<br />
<br />
== External links ==<br />
* [http://arduino.cc/ Official website]<br />
* [http://playground.arduino.cc/Main/FlightGear FlightGear Serial Communications with Arduino] (tutorial)<br />
* [http://forum.flightgear.org/viewtopic.php?f=18&t=11126 Arduino LCD and FlightGear] (FlightGear forum)<br />
* [https://sites.google.com/site/flightgeararduinoandlinux/ Flightgear, Arduino and Linux] (potentiometer and switch interfacing tutorial<br />
<br />
[[Category:Cockpit building]]<br />
[[Category:Hardware]]</div>Vaipe