Board index FlightGear Support Interfacing

FGFS screenshot and the property tree?

Connecting two computers, using generic protocol, connecting with Matlab?

FGFS screenshot and the property tree?

Postby ScottBouch » Thu Nov 30, 2017 11:34 am

Hi all,

Is there a node in the FGFS property tree to trigger the in-built function of taking a screenshot? (Like pressing F3)

Reason I ask is that I'd like to use the trigger on my stick (Serial Generic Protocol - Arduino) to take screen shots, and this seems like a simple way to do it if it's available in the property tree..
See: http://www.scottbouch.com/flightgear-sim-arduino-serial-hardware-2-axis-potentiometer-joystick.html

Cheers, Scott
User avatar
ScottBouch
 
Posts: 183
Joined: Wed Jun 22, 2016 4:14 pm
Location: Midlands, UK
OS: Linux Mint

Re: FGFS screenshot and the property tree?

Postby Thorsten » Thu Nov 30, 2017 11:38 am

Tie the binding

Code: Select all
  <binding>
   <command>screen-capture</command>
  </binding>


to whatever button you like and you're done.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: FGFS screenshot and the property tree?

Postby ScottBouch » Thu Nov 30, 2017 12:19 pm

Hi Thorsten, Thank you.. A question as I'm still learning this....

Can I add a binding to my protocol file? My stick is not HID compliant like an off-the shelf one, so I'm using the generic protocol via serial using an Arduino as the interface..

Below is my current protocol file that handles x and y stick positions (from potentiometers) and also trim as analogue positions too. Would I be able to insert the binding here?

Code: Select all
<?xml version="1.0"?>
<PropertyList>
   <generic>
   <input>
      <line_separator>\n</line_separator>
      <var_separator>,</var_separator>

      <chunk>
      <name>aileron</name>
      <type>float</type>
      <node>/controls/flight/aileron</node>
      </chunk>

      <chunk>
      <name>elevator</name>
      <type>float</type>
      <node>/controls/flight/elevator</node>
      </chunk>

      <chunk>
      <name>aileron-trim</name>
      <type>float</type>
      <node>/controls/flight/aileron-trim</node>
      </chunk>

      <chunk>
      <name>elevator-trim</name>
      <type>float</type>
      <node>/controls/flight/elevator-trim</node>
      </chunk>

   </input>
   </generic>
</PropertyList>


Thanks, Scott
User avatar
ScottBouch
 
Posts: 183
Joined: Wed Jun 22, 2016 4:14 pm
Location: Midlands, UK
OS: Linux Mint

Re: FGFS screenshot and the property tree?

Postby ScottBouch » Fri Dec 01, 2017 1:52 pm

Hi,

I've had a crack at it... I'm sending good data from my Arduino (verified by the IDE serial monitor). I send four analogue values followed by a boolean (1 or 0) that changes when the trigger is pressed. These values are all separated by commas, example below from Arduino IDE serial monitor:

(x position, y position, trim x value, trim y value, trigger bool state)

0.32,0.38,0.06,-0.05,0,
0.32,0.38,0.06,-0.05,0,
0.32,0.38,0.06,-0.05,1, - last "1" shows trigger pressed, returns to "0" when released
0.32,0.38,0.06,-0.05,1,

All analogues are controlling the flight surfaces as per normal, so my generic protocol file is working nicely for them.

I had a go at adding a chunk to the generic protocol to use the trigger to take a screenshot. I found very little information on using bindings with the generic protocol, so have just been playing around with it, based on no knowledge... so far it's not worked.

Below is an extract form my hardware protocol file, the first chunk is one that works to set the elevator trim, the second is my attempt to bind the input to the screen-capture command designed by guess work, and not working:

Code: Select all
      <chunk>
      <name>elevator-trim</name>
      <type>float</type>
      <node>/controls/flight/elevator-trim</node>
      </chunk>

      <chunk>
      <name>trigger</name>
      <binding>
      <command>screen-capture</command>
      </binding>
      </chunk>


Any guidance on this would really be appreciated...

Thanks, Scott.
User avatar
ScottBouch
 
Posts: 183
Joined: Wed Jun 22, 2016 4:14 pm
Location: Midlands, UK
OS: Linux Mint

Re: FGFS screenshot and the property tree?

Postby wlbragg » Fri Dec 01, 2017 8:01 pm

Hi Scott,

Until someone with more experience using the protocol system comes along it appears that you want

Code: Select all
<chunk>
  <name>trigger</name>     
  <type>bool</type>
  <node>/controls/screencapture</node>
</chunk>


where (trigger) /controls/screencapture is the node your creating (could be anything you want) from the last parsed data (5) your trigger. That gets the data into the property tree. Then you would bind that node you created to screen-capture in your joystick configuration file (see fgdata/Inputs/Joysticks/?.xml ). Looks like that might be how it's done, just a guess here on my part.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: FGFS screenshot and the property tree?

Postby ScottBouch » Fri Dec 01, 2017 9:19 pm

Ah! cool, I hadn't realised you could add custom nodes to the property tree as simply as that! That really is good to know!

Thanks, I can see what you are saying, and I will have a go..

Many thanks, Scott.
User avatar
ScottBouch
 
Posts: 183
Joined: Wed Jun 22, 2016 4:14 pm
Location: Midlands, UK
OS: Linux Mint

Re: FGFS screenshot and the property tree?

Postby ScottBouch » Fri Dec 01, 2017 10:39 pm

Brilliant!

I now have a trigger in the property tree!

I did it like this:
Code: Select all
      <chunk>
      <name>trigger</name>
      <type>bool</type>
      <node>/controls/switches/trigger</node>
      </chunk>

And I've just used the internal property browser to verify it works, and it indeed does!

Now to bind it to the screen-capture command, I'll have a go as you suggested.

Thanks, Scott
User avatar
ScottBouch
 
Posts: 183
Joined: Wed Jun 22, 2016 4:14 pm
Location: Midlands, UK
OS: Linux Mint

Re: FGFS screenshot and the property tree?

Postby ScottBouch » Fri Dec 01, 2017 11:18 pm

Tried adding the binding directly in my hardware generic protocol file. didn't work.

So, I hunted down where the key F3 is bound to screen-capture in the keyboard.xml file. I added my node to the existing binding there, but it still didn't work:

Code: Select all
 <key n="259">
  <name>F3</name>
  <desc>Capture screen</desc>
  <binding>
   <command>screen-capture</command>
   <node>/controls/switches/trigger</node>
  </binding>
 </key>

(mod-shift removed for clarity)

I also checked the property browser to see if it was binding in reverse: ie: pressing F3 making /controls/switches/trigger to true, but it did not, it just took screen shots.

I tried something else, placing a generic tags in the keyboard xml file, but still no joy:

Code: Select all
 <generic>
  <name>trigger</name>
  <desc>Capture screen</desc>
  <node>/controls/switches/trigger</node>
  <binding>
   <command>screen-capture</command>
  </binding>
 </generic>
User avatar
ScottBouch
 
Posts: 183
Joined: Wed Jun 22, 2016 4:14 pm
Location: Midlands, UK
OS: Linux Mint

Re: FGFS screenshot and the property tree?

Postby wlbragg » Sat Dec 02, 2017 6:47 am

And I've just used the internal property browser to verify it works, and it indeed does!
Now to bind it to the screen-capture command, I'll have a go as you suggested.


Now you have to bind the new screen-capture property you created using the Joystick config file your Joystick is using by adding a new entry in it. Look at the basic joystick.xml file located in fgdata/Input/Joysticks

It will be an entry something like below, I'm not sure of the exact syntax. Again, hopefully someone with experience can interject here.

Code: Select all
<button n="2">
  <desc>trigger</desc>
  <binding>
    <command>screen-capture</command>
    <property>/controls/screen-capture</property>
   <value>1</value>
  </binding>
</button>


So, I hunted down where the key F3 is bound to screen-capture in the keyboard.xml file

I think it will have to be added to the joystick configuration file your joystick uses.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: FGFS screenshot and the property tree?

Postby ScottBouch » Mon Dec 04, 2017 6:24 pm

Hi, thanks..

You mentioned about a joystick configuration file my joystick uses... it's a sort of home-made joystick (not HID compliant). see: http://www.scottbouch.com/flightgear-sim-arduino-serial-hardware-2-axis-potentiometer-joystick.html

I use an arduino to read potentiometers and switches, it passes serial data over USB TTY port to the Generic Protocol of fgfs. so the only configuration file is an xml file I created to read the serial data chunks in order and map them to points in the property tree.

My issue is now getting <command>screen-capture</command> to run when /controls/switches/trigger goes true ( = 1 )

I've tried placing this code in my generic protocol file, the "keyboard.xml" file, and in the default "joysticks.xml" file, but so far have not got it working.

Cheers, Scott.
User avatar
ScottBouch
 
Posts: 183
Joined: Wed Jun 22, 2016 4:14 pm
Location: Midlands, UK
OS: Linux Mint

Re: FGFS screenshot and the property tree?

Postby wlbragg » Mon Dec 04, 2017 7:40 pm

I've tried placing this code in my generic protocol file, the "keyboard.xml" file, and in the default "joysticks.xml" file, but so far have not got it working.

Unless I am missing something it seem like it should go into whatever joystick.xml file you using. Unless you not using a "joysticks.xml" file because the Protocol file is directly manipulating the property that controls the flight surfaces. In which case I guess you would need to hook into a "joysticks.xml" file with a new mapping (binding) to the <command>screen-capture</command>. Read-up on how to use the default "joysticks.xml" file where you placed the screen-capture binding with a joystick. I've never used one so I can't comment on how it is done.

Otherwise, there is possible a nasal solution to trigger the screen capture command, I'd have to do some reading/investigating.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: FGFS screenshot and the property tree?

Postby ScottBouch » Tue Dec 05, 2017 11:38 am

wlbragg wrote in Mon Dec 04, 2017 7:40 pm:Unless you not using a "joysticks.xml" file because the Protocol file is directly manipulating the property that controls the flight surfaces.


This is exactly the case, my protocol .xml file is directly affecting the property tree, and no joystick xml file used.

One question: If I am to use joysticks.xml file that's in my FG home directory, do I need to specify this as an --option when starting fgfs? I ask as I had a go at putting the code there, to no avail, but I'd assumed fgfs would read the jpysticks.xml file by default as it's not been created by me, it was there form a fresh install. would I ned to add something like --config=joysticks.xml ?

Cheers, Scott.
User avatar
ScottBouch
 
Posts: 183
Joined: Wed Jun 22, 2016 4:14 pm
Location: Midlands, UK
OS: Linux Mint

Re: FGFS screenshot and the property tree?

Postby ScottBouch » Tue Dec 05, 2017 1:01 pm

I may have answered my own question about getting fgfs to read joysticks.xml, specifying the path as this seemed successful:
$ fgfs --generic=serial,in,30,/dev/ttyACM0,9600,hardware --config /usr/share/flightgear/data/joysticks.xml

Result was this during fgfs startup:

Code: Select all
Channel string = serial,in,30,/dev/ttyACM0,9600,hardware
   option:generic = serial,in,30,/dev/ttyACM0,9600,hardware
   option:config =
Reading command-line property file Path "/usr/share/flightgear/data/joysticks.xml"


The contents of joysticks.xml is:

Code: Select all
<?xml version="1.0"?>
<!--
   To override or add "named" joystick drivers list them in
   <js-named> entries with paths relative to the directory where
   the joysticks.xml file resides (first example). Such "named"
   drivers are only picked up if one of their <name>s matches
   the joystick hardware (see output of the js_demo application).
   These drivers have precedence over already existing drivers
   with the same <name>. (You can also add a <name>default</name>
   entry to the driver to make it the default choice.)

   The second example shows how to load a driver directly to
   position 0. This will then be used for the first joystick on
   your system and FlightGear will not overwrite it.
-->

<PropertyList>
<!--
   <js-named include="Input/Joysticks/Local/X45-modified.xml"/>

   <js n="0" include="Input/Joysticks/Local/joystick_0.xml"/>
-->

<button n="x">
  <desc>trigger</desc>
  <binding>
    <property>/controls/switches/trigger</property>
    <command>screen-capture</command>
   <value>1</value>
  </binding>
</button>

</PropertyList>


It didn't take a screenshot, can you see where I'm going wrong?

Many thanks again, Scott.
User avatar
ScottBouch
 
Posts: 183
Joined: Wed Jun 22, 2016 4:14 pm
Location: Midlands, UK
OS: Linux Mint

Re: FGFS screenshot and the property tree?

Postby AndersG » Tue Dec 05, 2017 1:07 pm

You most certainly do not want to use joysticks.xml - your button-element even if it were at the right level of the tree (which I think it is not) would not help since it tries to connect a button on a USB HID (or gameport) joystick device to the screen-capture command. If the property added into the binding is correct it'd be a property that is set by the aforementioned joystick button.

You need another type of construction that triggers the screen-capture command when a property written by your protocol changes.
Perhaps a Nasal property listener that calls fgcommand("screen-capture"); or similar?
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2524
Joined: Wed Nov 29, 2006 10:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: FGFS screenshot and the property tree?

Postby ScottBouch » Tue Dec 05, 2017 1:53 pm

Hi AndersG,

Thank you for that - I've never done any nasal coding, so will have to look it up, looks fairly straightforward at a glance though.

Is it best I create a new .nas file specifically for my nasal code in /usr/share/flightgear/data/Nasal? Or should I add to an existing file like controls.nas?

If I create a new nasal file, do I need a command to call this nasal file when starting fgfs, or will it just run automatically if it's in the data/Nasal directory?

Thanks again, Scott
User avatar
ScottBouch
 
Posts: 183
Joined: Wed Jun 22, 2016 4:14 pm
Location: Midlands, UK
OS: Linux Mint

Next

Return to Interfacing

Who is online

Users browsing this forum: No registered users and 2 guests