Howto:Use Arduino with FlightGear: Difference between revisions

Partial clean-up/copy-edit
m (Red Leader moved page Arduino to Howto:Use Arduino with FlightGear: Most of the page is about using Arduino with FlightGear, so make it more befitting.)
(Partial clean-up/copy-edit)
Line 1: Line 1:
Thanks to [[FlightGear]]'s [[generic protocol]], 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.
== About Arduino ==
'''[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]).
'''[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]).
[[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).


== How to: Control Flightgear with Arduino ==
== Controlling Flightgear with Arduino ==
 
This example demonstrates the use of a switch and a potentiometer to control the [[Property Tree]]
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..


=== Equipment and software ===
=== Equipment and software ===
 
This example uses the following components and software:
This example uses following components and software:
* [[Changelog_3.2|FlightGear 3.2]] or higher
* [[Changelog_3.2|FlightGear 3.2]]
* [[FlightGear Launch Control]] (or FGRun)  
* [[Flightgear Launch Control]] (program to make FlightGear start without terminal command and options)
* Arduino UNO
* Arduino UNO
* Linux (Ubuntu 14.04)
* Linux (Ubuntu 14.04)
* On/off switch
* On/off switch
* Potentiometer
* Potentiometer
* Flightgear's Cessna 172P Skyhawk
* [[Cessna 172P|Cessna 172P Skyhawk]] (default aircraft)


===Input protocol file===
=== Input protocol file ===
Input protocol file is used to specify how serial information is read by Flightgear. In Ubuntu protocol files are found in:
<tt>''/usr/share/games/flightgear/protocol''</tt> directory.


Input protocol file is used to specify how serial information is read by Flightgear. In Ubuntu protocol files are found in:
==== Protocol file structure ====
"/usr/share/games/flightgear/protocol" directory.
Create <tt>''controltest.xml''</tt> file in your protocol folder and paste code from below to it.
<syntaxhighlight land="xml">
<?xml version="1.0"?>


====Protocol file structure====
<PropertyList>


Create controltest.xml file to your protocol folder and paste code from below to it.
<generic>
<syntaxhighlight land="xml">
    <input>  
<?xml version="1.0"?>
        <line_separator>\n</line_separator>
<PropertyList>
        <var_separator>,</var_separator>
<generic>
  <input>
    
    
  <line_separator>\n</line_separator>
        <chunk>
  <var_separator>,</var_separator>
            <name>Strobe</name>
            <node>/controls/lighting/strobe</node>
            <type>bool</type>
        </chunk>
    
    
  <chunk>
        <chunk>
    <name>Strobe</name>
            <name>Throttle</name>
    <node>/controls/lighting/strobe</node>
            <node>/controls/engines/engine/throttle</node>
    <type>bool</type>
            <type>float</type>
  </chunk>
        </chunk>
 
  <chunk>
    <name>Throttle</name>
    <node>/controls/engines/engine/throttle</node>
    <type>float</type>
  </chunk>
   
   
  </input>
    </input>
  </generic>
</generic>
</PropertyList>
 
</code>
</PropertyList>
</syntaxhighlight>
</syntaxhighlight>
Explanation of lines:
See [[Generic protocol]] for a description of the various XML tags.
 
*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.
*Variable separator: "variable_separator" is used to tell Flightgear that another variable is after this mark. In this protocol file it's ",".
*Chunk: "chunk" is to specify area for one variable and it's information.
*Name: "name" is used only for identifying variable so it can be anything.
*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".
*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.
 
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.


===Wiring and coding Arduino===
===Wiring and coding Arduino===