User:Tuxklok

From FlightGear wiki
Jump to: navigation, search

Configuring FGCOM and FlightGear To Have Use Of An Optional Second Comm Radio

The Goal

  1. Be able to monitor both the comm1 frequency and comm2 frequency at the same time.
  2. Be able to select between comm1 and comm2 to transmit on easily.
  3. Keep the second radio optional, but easily added at runtime when needed.
  4. To do so with existing fgcom and flightgear functionality.

What Is Involved

  • Two instances of fgcom, one for each comm radio.
  • A second, slightly modified fgcom protocol file for comm2.
  • A second generic protocol definition for the above.
  • A bit of nasal script to glue it all together
  • A little bit of patience.

Files

  • The secondary fgcom protocol file - fgcom_com2.xml
  • The nasal script file - fgcom.nas * (Script updated on Nov. 29, 2010. Please see the Nasal Script section below for updated functionality and installation/update instructions.)
Protocol File

This is a slightly modified version of the normal fgcom protocol file. It is used to get the second instance of fgcom to use comm2 frequency and ptt.

Place this file in FG_ROOT/Protocol.

Nasal Script

The script file defines and creates an instance of an FGComRadio object. This object is used to select radio(s) and transmit on the right one, it is available to other nasal script as fgcom.radio

The script also exposes some properties which will be found in the flightgear property tree under /local/fgcom. These properties are purely informational and should be considered read only, changing them will not affect anything. By default the script will display these properties at the upper right of your screen.

Api
  • fgcom.radio.ptt(BOOL) - Enable/disable push to talk on the currently selected radio(s). BOOL should be 1 to start transmitting, 0 to stop.
  • fgcom.radio.next_radio() - Switch to the next radio for transmitting. This cycles through comm1, comm2, both(if enabled), and back to comm1.
  • fgcom.radio.select_radio(INT) - Select a specific radio for transmitting. INT should be 0 for comm1, 1 for comm2, or 2 for both(must be enabled first).
  • fgcom.radio.selected_radio() - Returns the currently selected radio for transmitting. 0 for comm1, 1 for comm2, or 2 for both(if enabled).
  • fgcom.enable_transmit_both(BOOL) - Enables or disables ability to select both radios for transmitting. BOOL should be 1 to enable, 0 to disable. [1]
  • fgcom.toggle_property_display() - By default fgcom related properties will be displayed on the screen. This toggles visibility on/off. [2]

* (Any other methods or attributes of the FGComRadio object should be considered private and not be used or modified.)

[1] Transmitting on both radios simultaneously is disabled by default and should only be used for testing purposes.

[2] You may change the position and/or color of the property display by changing the PROPERTY_DISPLAY_* variables at top of script.


Place this file in FG_HOME/Nasal, creating the directory if needed.

  • On Linux the path is /home/<username>/.fgfs/Nasal
  • On Windows XP the path is C:\Documents And Settings\<username>\Application Data\flightgear.org\Nasal
  • On Windows Vista the path is C:\Users\<username>\appdata\roaming\flightgear.org\Nasal
  • On Mac I do not know, possibly the same as Linux? (feel free to contact if you know)

* The windows paths are what I was told by Windows users, I cannot confirm them personally

It is important that you do not put this file in FG_ROOT/Nasal!


* If you had followed earlier versions of this guide and placed fgcom.nas into FG_HOME/Nasal as per the old instructions above, you should delete this file now and then follow new instructions below.

To install the script simply download and place directly into your FG_ROOT/Nasal directory.


Setup

Setup is fairly simple and consists of the following:

  1. Configuring a second generic protocol for comm2.
  2. Adding bindings to the joystick or keyboard to call the methods in the fgcom.radio object.
Protocol

Start by configuring the second generic protocol for flightgear. This is in addition to the fgcom protocol you have setup previously, and should be the same except change port to 16662 and change the protocol name to fgcom_com2. If you need help in setting up the protocol again(in fgrun), refer to this section of the main fgcom article(scroll down to part 6) Input/Output). If your using fgcomgui, you can go to Help->HTML Docs and refer to the flightgear section there.

Bindings

The default push to talk binding in flightgear is the spacebar, but only affects properties for comm1. You can try to modify the default bindings if you wish, but I recommend just leaving them and adding your own bindings elsewhere. I personally use two buttons on my joystick for this, one for push to talk, and one for switching between comm radios. So I will just show those parts of my joystick config as an example for how to setup bindings using the fgcom.radio object for control.

binds button 1 on my joystick to push to talk. Transmits (on selected radio) while pressed, stops when released.

   <button>
       <number>
           <unix>1</unix>
           <windows>1</windows>
       </number>
       <desc>Push To Talk</desc>
       <binding>
           <command>nasal</command>
           <script>fgcom.radio.ptt(1);</script>
       </binding>
       <mod-up>
           <binding>
               <command>nasal</command>
               <script>fgcom.radio.ptt(0);</script>
           </binding>
       </mod-up>
   </button>

binds button 4 on my joystick to switching selected radio(s) for transmitting.

   <button>
       <desc>Change comm radio used for ptt</desc>
       <number>
           <unix>4</unix>
           <windows>4</windows>
       </number>
       <binding>
           <command>nasal</command>
           <script>fgcom.radio.next_radio();</script>
       </binding>
   </button>

binding button 6 to toggle visibility of the property display.

   <button>
       <desc>Toggle visibility of fgcom property display</desc>
       <number>  
           <unix>6</unix>
           <windows>6</windows>
       </number>
       <binding>
           <command>nasal</command>
           <script>fgcom.radio.toggle_property_display();</script>
       </binding>
   </button>

Bringing It All Together

Ok, so you have placed the files in the appropriate places, added the generic protocol definition to fgrun(if you use it), added keyboard/joystick bindings, and now your ready to try it all out.

Starting FlightGear

First we will go ahead and launch flightgear using your preferred method below. If all is well you should see no errors, and will see the fgcom.radio properties at the top left of your flightgear window. Pressing the button you've bound to switching radios, you should see the active_radio property changing between comm1 and comm2. Pressing the button you've bound to ptt, you should see the ptt property switching between 0 to 1. If it's all working, congrats, you can now move on to the Starting FGCom section. If you had any problems or errors, please refer to the Trouble Shooting section for possible solutions. Resolve any problems before moving on.

* Please remember that the ptt property on screen will only change when the fgcom.radio.ptt method is used.

FGRun

Just go ahead and start flightgear. Making sure you set up the second protocol definition first of course.

Command Line

Starting flightgear, using the ufo and specifying the fgcom protocols. Notice the different port and protocol name for the second.

jacob@dualbuntu:~ $ fgfs --aircraft=ufo --generic=socket,out,10,localhost,16661,udp,fgcom --generic=socket,out,10,localhost,16662,udp,fgcom_com2
Starting FGCom

To have two comm radios, we will need to run two instances of fgcom. For the first instance you can use fgcomgui or run fgcom from the command line. For the second instance I recommend using the command line, as fgcomgui is not really intended to be run multiple times.

First FGCom Instance

* If you wish to use fgcomgui as your first instance instead, go ahead and start it now, making sure port is set to 16661(the default). You can then skip to the Second FGCom Instance

Starting first instance of fgcom from the command line, using default settings.

jacob@dualbuntu:~ $ fgcom -Sfgcom.flightgear.org.uk

Set comm1 frequency to 910, then using your bindings created earlier make sure comm1 is selected and press your ptt key/button. You should hear everything echoed back to you. If you have any problems refer to the Trouble Shooting section for possible solutions and try again.

Second FGCom Instance

Ok, with first instance working, let's start the second one. Notice that we set port to 16662 this time.

jacob@dualbuntu:~ $ fgcom -Sfgcom.flightgear.org.uk -p16662

Set comm2 frequency to 910, then using your bindings created earlier make sure comm2 is selected and press your ptt key/button. You should hear everything echoed back to you. If you have any problems refer to the Trouble Shooting section for possible solutions and try again.

Trouble Shooting

Errors From The Script Or Script Not Working Properly
  • Make sure that you have put the script in FG_HOME/Nasal and not FG_ROOT/Nasal. (It matters!)
  • Make sure you are calling the fgcom.radio object correctly...check the Api section.
Nothing Echoed Back When Transmitting On Frequency 910
  • Check that your audio is turned up, mic plugged in, unmuted, etc.
  • Check that you have selected the correct comm radio.
  • Check that your binding is using fgcom.radio.ptt(BOOL), and not the default ptt.
  • Check that your appropriate fgcom instance is receiving frequency and ptt events.
  • Check that you have configured the flightgear protocol and fgcom properly.
FGCom Fails To Open Capture Device Or Device Busy Errors

* This section is Linux specific

If Using The Modern OpenAL Soft OpenAL Implementation.

Adjust your ~/.alsoftrc to use software mixing for playback and/or capture.

drivers = alsa
[alsa]
device = default
capture = plug:dsnoop
If Using The Old Loki OpenAL Implementation

Adjust your ~/.openalrc to use software mixing for playback and/or capture

(define devices '(alsa))
(define alsa-out-device "default")
(define alsa-in-device "plug:dsnoop")

Final Notes

Using multiple instances of fgcom, while useful in some situations, potentially doubles the amount of bandwidth used. To avoid excessive bandwidth usage and strain on the fgcom server, you should only start the second radio when you actually need it. Using this setup you can use just one instance of fgcom for normal use, and start/stop the other one (without restarting flightgear) dynamically when needed. Talking on both radios at the same time is not very realistic, wasteful of bandwidth, and generally a bad idea. For these reasons it is disabled by default, you should only enable and use this feature for testing purposes.

Please be kind to our one and only fgcom server and use multiple fgcom radios sparingly, and only when actually needed.