Board index FlightGear Support Interfacing

Arduino - Python - FG in/out - status LED's Win7/10

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

Arduino - Python - FG in/out - status LED's Win7/10

Postby Volador » Tue Sep 29, 2020 5:25 pm

#Ludomotico has some very interesting python 'middleware' code that sits inbetween FG and Arduino and might be able to elaborate or #Bill516 on this but in the hope of developing functions other than COM's like gear down with a feedback LED that lights once it's down, or APProch that only lights when you hit the glide-slope how would this work with variables being passed to and from the properties tree through python to the Arduino? I have a little programming knowledge but I'm nowhere near what Ludomotico or Bill516 have done with their code.

Example: Hitting the APProach button (747 for example) on an Arduino interface, the arduino via python sets the property tree Approach to on (couldn't find this in the property tree wiki by the way). But, the APProach light in FG only comes on once you hit the glideslope correctly and are at a safe speed etc, so if you wanted to output the status or the Approach back to an LED on the Arduino interface to reflect being locked in or not, how would you do it? Is there a second variable or property that can be read? Same sort of thing for gear down, there is a delay while the gear comes down during which time the gear down LEDs should be off, only and if the gear gets down should the status of the gear change to all green LED.
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby Volador » Wed Sep 30, 2020 4:55 pm

I founds some variables after dome digging, perhaps there is a logic that can be read by the Arduino to illuminate an LED for feedback on the status of instruments that are not simply on or off.

Watching the property tree on final approach 747-8 intercontinental the LOC (localiser) button triggers:
Instrumentation/afds/inputs/loc-armed (bool) flashes quickly true back to false on press
Instrumentation/afds/inputs/lateral-index = '4' int (normally = '2') - this seems to be the only way to distinguish localiser on from localiser off rather than a boolean expression.

The APP (approach) button changes:
Instrumentation/afds/inputs/gs-armed (bool) false to true

Similarly on the 777 aircraft
Instrumentation/afds/inputs/Lateral index = '2' when LOC off '4' when LOC on - not quite sure how they relate but if it's a consistent value of 2 or 4 then in theory this could be used to illuminate the Approch led on the APP switch on the Arduino.

getting there...
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby ludomotico » Wed Sep 30, 2020 7:50 pm

The idea es quite similar, and it is implemented in other external interfaces such as the web interface. For example, for the C172P: https://github.com/c172p-team/c172p/issues/1308 (The web interface uses "the Phi protocol" [i.e., http] instead of telnet, but it is the same idea)

You must identify the property you are interested in, as you did.

Option A: you can check the value of the property from time to time. For the NAV modes of the AP, it is probably enough checking once a second. This is probably the easiest way if you check only a few properties.

Option B: you don't have to check the value of the property constantly: "the middleware" can subscribe to a property in telnet and wait for its changes: http://wiki.flightgear.org/Telnet_usage ... nsubscribe I suspect there is a race condition somewhere and sometimes, randomly, you won't get changes to some subscribed properties.

When your middleware detects the change of the relevant property, send the appropriate command to the Arduino.
User avatar
ludomotico
 
Posts: 1269
Joined: Tue Apr 24, 2012 2:01 pm
Version: nightly
OS: Windows 10

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby Volador » Fri Oct 02, 2020 7:05 pm

Unfortunately I don't have time for any deep development with ludomotico's Python middleware but thank you for the pointers and ideas :) (if it was a 'black box' that just passed everything in and out that would be great) so I've come up with a different plan. For Windows my (perhaps clunky) idea now is to use 2 usb ports (using 2 com ports) and 2 mega's, one will handle the 'input' (button presses and rotary encoder values) and the other 'output' (leds/numeric displays). My theory is that FG will then handle most of the computations and the arduino's each have a single mode, one writing button data to FG and the other listening for and displaying the resulting status of FG variables on the displays. I'm hoping the arduino coding will be simpler this way. However I suspect I'll be reworking this project in time as I do like the look of MSFS 2020 and there is a very useful set of arduino utilities/routines written especially for flight simulators called Mobiflight which allows easy interface expansion... time will tell
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby Volador » Sun Oct 04, 2020 5:41 pm

Any .xml experts out there, I've read readme.protocol but it went above my head towards the end and other xml references seem to point me to spreadsheet code.... Is it possible to format a value before it's output , say to a serial port? For example;

/controls/autoflight/heading-select can be set from 1 to 360 but can the chunk containing the format <format>%d</format> be set to specify the output with leading zeros? eg 001 or 022 -to always use three figures?
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby Johan G » Sun Oct 04, 2020 7:38 pm

This FlightGear wiki article might be a better starting point: Interfacing FlightGear (permalink)
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6629
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby daweed » Sun Oct 04, 2020 10:11 pm

Volador wrote in Sun Oct 04, 2020 5:41 pm:Any .xml experts out there, I've read readme.protocol but it went above my head towards the end and other xml references seem to point me to spreadsheet code.... Is it possible to format a value before it's output , say to a serial port? For example;

/controls/autoflight/heading-select can be set from 1 to 360 but can the chunk containing the format <format>%d</format> be set to specify the output with leading zeros? eg 001 or 022 -to always use three figures?


Hello,

The format option work as well as the C / C++ printf function

In this ways the following code will lead to format the heading on 3 digit

Code: Select all
<format>hdg=%03d</format>


BTW, as Johan said, reading the wiki is a good place to start even if although there are not many examples.
Reading the FG code itself sometime help too.

Best regards
Windows 10 / Linux Mint 20
AMD Ryzen 7 3700X |32 Go RAM GeForce RTX 3070 Ti 8 Go
FG Interface
Lyon Saint Exupery Scenery

ATC on LFLL on Friday 19:00 UTC => 22:00 UTC
daweed
 
Posts: 398
Joined: Thu Dec 11, 2014 11:45 am
Location: LFKP LFLL
Callsign: daweed
OS: Linux Mint 20

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby Volador » Sun Oct 11, 2020 10:38 am

Johan, Daweed, thank you both for your input and signposting.

I did code a workaround in the end, I'm now displaying autopilot target kts, alt, hdg, vs. The library HCMAX7219.h for driving the 7 seg displays on the arduino mega only allows integers or strings within quotes (as far as I can tell I can't display a string within a variable but I've probably missed something) so I was forced to code leading zeros depending on the value anyway. eg heading 001 is = 1 but to get the leading zeros I had to conditionally display "00" at the start. It's all working fine though but formatting the 7 seg display has taken a long time. Next step is status LED's and I'm digging through the property tree to watch values change in relation to button leds lighting up... that's the next step. I'll report back.
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby Volador » Sun Oct 11, 2020 7:58 pm

Johan G wrote in Sun Oct 04, 2020 7:38 pm:This FlightGear wiki article might be a better starting point: Interfacing FlightGear (permalink)


Hi Johan, I had read this and other material here on the site.

I'm still struggling with the basics after a few hours of research. I've read the documentation for outputting properties to a csv, I think I've missed something.

my output FG_log-config.xml is saved into (as explained in the $FGROOT) C:\Program Files\FlightGear 2020.2.1\data

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
 <logging>
  <log>
   <filename>autopilot controls.csv</filename>
   <enabled>true</enabled>
   <interval-ms>1000</interval-ms>
   <delimiter>,</delimiter>

   <entry>
     <enabled>true</enabled>
    <title>Target alt</title>
    <property>/autopilot/settings/alt-display-ft</property>
   </entry>

   <entry>
    <enabled>true</enabled><ref></ref>
    <title>Speedmode</title>
    <property>Instrumentation/afds/ap-modes/speed-mode</property>
   </entry>

  </log>
 </logging>
</PropertyList>


I start FG with the following options:

--generic=serial,out,10,/.//COM8,9600,FG_spd_hdg_out
--config=FG_log-config.xml

The serial output xml is working but the --config option to generate the log file does not generate the .csv file - I've searched all the drives after exiting flightgear - any clues would be most helpful
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby Johan G » Sun Oct 11, 2020 8:56 pm

Volador wrote in Sun Oct 11, 2020 7:58 pm:my output FG_log-config.xml is saved into (as explained in the $FGROOT) C:\Program Files\FlightGear 2020.2.1\data
[...]
[...] the --config option to generate the log file does not generate the .csv file - I've searched all the drives after exiting flightgear - any clues would be most helpful

The readme file states that:
The easiest way for an end-user to define logs is to put the log in a
separate XML file (usually under the user's home directory), then
refer to it using the --config option, like this:

fgfs --config=log-config.xml

The output log files are always relative to the current directory.

Which I read as that both the config file and the log file preferably should be in the home directory (see $FG HOME).

Could you test if instead placing the config file in C:\Users\Your user name here\AppData\Roaming\flightgear.org or C:\Users\Your user name here\Documents\FlightGear would make it work?
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6629
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby Volador » Tue Oct 13, 2020 4:47 pm

Hi Johan, thank you for your patience and suggestions.

I tried your suggestions and have re-read the documentation and I seem to be getting inconsistent results. I did get an error message (once only) in the fgfs.log saying it couldn't write the .csv file to the specified location but I've not even been able to replicate the error since. I'm using

fgfs --config=FG_log-config.xml
--generic=serial,out,10,/.//COM8,9600,FG_spd_hdg_out

and have put the FG_log-config.xml file in each and all of the locations suggested, still no luck I'm afraid.
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby wkitty42 » Tue Oct 13, 2020 5:01 pm

what directory are you starting FG from? check your shortcut and see if it has a starting path specified...

or you could take the better way out and directly specify the path for that file's location...

eg:
Code: Select all
~/myflightgear/runfgfsrelease --launcher --config=$HOME/myflightgear/fg-075km-horizon.rc

that's on my linux system but the concept is still the same...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby Volador » Tue Oct 13, 2020 5:43 pm

Hi wkitty42,

the shortcut is:
"C:\Program Files\FlightGear 2020.2.1\bin\fgfs.exe" --launcher
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby wkitty42 » Tue Oct 13, 2020 5:47 pm

right... and there's another field that is generally "starting location"... is that filled in or no?

i'd show you a screenshot of it but i don't do windows ;)
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Arduino - Python - FG in/out - status LED's Win7/10

Postby Volador » Tue Oct 13, 2020 5:49 pm

Thanks for your help wkitty42, the starting location is:
"C:\Program Files\FlightGear 2020.2.1\bin"
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Next

Return to Interfacing

Who is online

Users browsing this forum: No registered users and 5 guests