Board index FlightGear Support Interfacing

Headless mode with access to property tree

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

Headless mode with access to property tree

Postby alexklibisz » Mon Jul 18, 2016 9:12 pm

Short question: How would I run flightgear so that it renders no graphics but still allows access to the property tree over sockets?

Longer question:

I'm planning to use flightgear to train a neural net to keep a helicopter stable. The training is evolutionary optimization, so it's critical that we can spawn thousands of "runs" quickly and ideally in an environment without a display. Is it possible right now to run Flightgear so that no graphics render while exposing the property tree over sockets? For example, a separate process would spawn an fgfs process, send controls to the property tree over a socket until the helicopter crashes, detect that it's crashed by reading from the property tree, kill the process, and repeat.

If it would require modifying the source code, is it practical for a programmer without any flightgear programming experience to attempt to modify this?
alexklibisz
 
Posts: 14
Joined: Sat Jul 16, 2016 3:47 am

Re: Headless mode with access to property tree

Postby Hooray » Mon Jul 18, 2016 9:34 pm

You could use the FDM in standalone mode (think JSBSim/YASim), the wiki contains a few pointers on doing this sort of thing, including master/slave setups where an external FDM can be used to visualize such flights via fgfs

Regarding your last question, you don't necessarily need to know much about programming to do these things - in general, a solid background in a few related fields is likely more important than familiarity with the SG/FG code base - Nasal is very close to JavaScript, and C++ is obviously close to Java - and most APIs are likely to be very similar anyway.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Headless mode with access to property tree

Postby alexklibisz » Wed Jul 20, 2016 1:25 am

Could you maybe point me to a tutorial for running JSBSim with a helicopter? There's a lot of material out there but I've found it difficult to narrow down what's useful and what isn't.
Last edited by Johan G on Tue Aug 02, 2016 7:54 pm, edited 1 time in total.
Reason: Please do not quote the entire preceding post.
alexklibisz
 
Posts: 14
Joined: Sat Jul 16, 2016 3:47 am

Re: Headless mode with access to property tree

Postby alexklibisz » Wed Jul 20, 2016 1:37 am

Actually I came across this post after some more googling: viewtopic.php?t=14869

I think I will move to trying YASim unless there are more undocumented helicopters supported via JSBSim.

It seems that there is no documented way to talk to YASim outside of FlightGear (2008: viewtopic.php?p=3696, 2015: viewtopic.php?f=49&t=25624). If this is the case, would it be possible to modify the FlightGear source code to exclude the graphics entirely?
alexklibisz
 
Posts: 14
Joined: Sat Jul 16, 2016 3:47 am

Re: Headless mode with access to property tree

Postby Hooray » Wed Jul 20, 2016 8:38 pm

both, JSBSim and YASim can be used in standalone mode, thus, that really is all you need to use these FDMs "outside" fgs - there would be no graphics running at all, in fact, it's the leanest mode possible
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Headless mode with access to property tree

Postby alexklibisz » Fri Jul 22, 2016 2:55 pm

Could you give an example for how to run YASim in standalone mode? I haven't been able to find any concrete examples. I'd like to be sending it property tree values just like you can send them to fgfs using the Generic Protocol.

Thanks!
Last edited by Johan G on Tue Aug 02, 2016 7:55 pm, edited 1 time in total.
Reason: Please do not quote the entire preceding post.
alexklibisz
 
Posts: 14
Joined: Sat Jul 16, 2016 3:47 am

Re: Headless mode with access to property tree

Postby Hooray » Fri Jul 22, 2016 7:55 pm

yasim standalone does not have socket support AFAIR, it's a console application, so you need to use a wrapper to run/control it or do it interactively.
I suggest you actually tinker with the corresponding binaries - I don't have the bandwidth (or patience) to walk you through the whole thing, especially given that these resources are fairly accessible actually.
In other words, if you find yourself being unable to invoke a console program to run it in a terminal/shell environment, that may also raise the question if the whole approach/project may be way over your head for the time being - I mean, it's not that JSBSim or YASim are undocumented, and there are tons of existing FDMs that you could test like this in a console environment and then take it from there, which kinda sums up what I would be doing in your situation.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Headless mode with access to property tree

Postby PINTO » Fri Jul 22, 2016 8:28 pm

Contrary to what Hooray is suggesting, YASim standalone doesn't run the FDM in the console, where you can give it inputs like set elevators to 10%, throttles to 60%, or whatever, and watch what the plane does. It's just a solver for YASim. You give it the aircraft, an optional altitude and speed, and it'll pump out how it's solving the FDM (things like drag, AoA at cruise, CG, lift ratio, etc) for that. I don't really think it'll do what you want it to do.

And, at this time, there's no way to run FG without the graphics, AFAIK. I wish there was. JSBSim, or something completely outside of FG altogether, would probably be best for you.

If you really wanna use the yasim executable, open up a command prompt/terminal, and it's format is
Code: Select all
"/path/to/exe/yasim.exe" "/path/to/fdm/my-fdm-yasim.xml" [-g] [-s <speed>] [-a <altitude>]

You can redirect it to an output file by adding this to the end:
Code: Select all
> path/to/output/output.txt
Actively developing the MiG-21bis (github repo) (forum thread) (dev discord) (fg wiki)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 944
Joined: Wed Oct 21, 2015 6:28 pm
Callsign: pinto
Version: 2016.3.0
OS: Win10

Re: Headless mode with access to property tree

Postby Hooray » Fri Jul 22, 2016 8:57 pm

Please, just do a forum search, I have made several postings where I explained how to use the whole FDMShell thing in fgfs for these purposes - besides, disabling graphics also is not rocket science necessarily, but it's also not necessarily what the OP really wants, if he all he needs is the FDM, he should be using just the FDM, and not all the other fgfs stuff (sound, autopilot, route-manager etc)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Headless mode with access to property tree

Postby PINTO » Fri Jul 22, 2016 9:14 pm

Well, he asked about YASim standalone, you gave him some possibly misleading information, and I wanted to clarify. We weren't talking about FDMShell. I did that search, and didn't see anywhere where you explained how to use it, can you link please?

disabling graphics also is not rocket science necessarily


As long as your comfortable editing the source code, and rebuilding it. I was talking about turning it off without modifying FG source code.
Actively developing the MiG-21bis (github repo) (forum thread) (dev discord) (fg wiki)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 944
Joined: Wed Oct 21, 2015 6:28 pm
Callsign: pinto
Version: 2016.3.0
OS: Win10

Re: Headless mode with access to property tree

Postby alexklibisz » Mon Aug 01, 2016 4:42 pm

Hooray wrote in Fri Jul 22, 2016 8:57 pm:Please, just do a forum search, I have made several postings where I explained how to use the whole FDMShell thing in fgfs for these purposes - besides, disabling graphics also is not rocket science necessarily, but it's also not necessarily what the OP really wants, if he all he needs is the FDM, he should be using just the FDM, and not all the other fgfs stuff (sound, autopilot, route-manager etc)



I would just like whatever is simplest to implement so that I can communicate with the property tree to run a bunch of simulations without any graphics.

It seems you've said in the past that a "headless" mode is non-trivial to implement: viewtopic.php?f=24&t=29201&p=280722&hilit=headless#p280722

Has there been progress made since that point?

I've been probing through the codebase myself to figure out if/how it's possible to just not open any windows. I've figured out which functions invoke the GUI, but I still have little understanding of all the different pieces that comprise it and how they can be altered to disable it. A nudge in the right direction would certainly be helpful. Thanks in advance!
alexklibisz
 
Posts: 14
Joined: Sat Jul 16, 2016 3:47 am

Re: Headless mode with access to property tree

Postby chriscalef » Mon Aug 01, 2016 4:57 pm

Just wanted to interject a quick word here and say that I too am very much hoping to be able to run a headless instance of FG! If you don't mind, please keep us up to date on your progress. For my purposes I do want the rest of the program running, not just the FDM, but I would like to do it without any graphics, as I am using it as an FDM (and other data) server communicating with another 3D app over a socket. Good luck!
chriscalef
 
Posts: 236
Joined: Wed Feb 20, 2013 9:28 pm

Re: Headless mode with access to property tree

Postby Hooray » Mon Aug 01, 2016 6:26 pm

In that case, you still need the graphics, but just an invisible window - we kinda covered that a while ago, it involves handing an osg::Traits to the context creation routine that keeps the window hidden. Under the hood, all of FG would still be running - which also means that a server would need X11 installed to run such a "headless" (=window-less) setup.

Sorry, I haven't been following this (or other) discussions - but the headless article mentions Fred's original comment: http://wiki.flightgear.org/FlightGear_Headless

FredB wrote:the main camera is created in CameraGroup::buildCamera and a pbuffer is allocated when you set osg::GraphicContext::Traits.pbuffer to true. These traits are available in buildCamera because we set width and height there. For debugging purpose, you can add a line like

Code: Select all
window->gc->getTraits()->pbuffer=true;


at the end of this function.


This probably still is your best bet to do something like this, even if it's just a pointer/starting point.

For additional pointers, my suggestion would be to search the wiki/forum and devel list for CameraGroup specifically, and maybe help us extend the docs at: http://wiki.flightgear.org/The_FlightGe ... ameraGroup

Note that README.multiscreen and the CameraGroup code specifically support rendering to a buffer, so that the traits stuff may not even be needed necessarily.

Besides, anybody interested in this functionality would be well-advised to file a corresponding feature request, or at the very least add to the corresponding wiki article, so that fellow contributors are made aware of this
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Headless mode with access to property tree

Postby alexklibisz » Mon Aug 01, 2016 9:47 pm

Thanks for the pointers @Hooray. I do have some progress. Adding:

traits->pbuffer=true

at the end of the WindowBuilder::makeDefaultTraits function does make it "window-less". I can still tell graphics are being rendered *somewhere* because the memory usage in my VM jumps the same way it does with a window.

Now the question might be if this is a way to prevent the rendering entirely to avoid the increased memory usage? I'll keep probing but appreciate further tips!
alexklibisz
 
Posts: 14
Joined: Sat Jul 16, 2016 3:47 am

Re: Headless mode with access to property tree

Postby alexklibisz » Mon Aug 01, 2016 10:13 pm

For reference, here is what I've added to disable the window. It's the last thing before the return statement in WindowBuilder::makeDefaultTraits(bool stencil).

Code: Select all
char* fg_gui = getenv("FG_GUI");
if (fg_gui != NULL && strcmp(fg_gui, "disabled") == 0) {
  printf ("danna_fg_gui: %s\n", fg_gui);
  traits->pbuffer = true;
}


So I just set an environment variable in my shell called FG_GUI and then this little hack works.
alexklibisz
 
Posts: 14
Joined: Sat Jul 16, 2016 3:47 am

Next

Return to Interfacing

Who is online

Users browsing this forum: No registered users and 5 guests