Board index FlightGear Development

Suitability of this software to run a swarm simulation

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Suitability of this software to run a swarm simulation

Postby darksanity » Wed Aug 28, 2013 10:59 am

Hi guys,

Just looking to see if this was possible and if anyone could point me in the right direction.

Looking to start a project to simulate a few aircraft flying in a swarm.

Is this possible with flightgear?

Has there been any projects in this area? Anyone point me in the right direction in terms of readingup?

Thanks muchly =]
darksanity
 
Posts: 2
Joined: Wed Aug 28, 2013 10:56 am

Re: Suitability of this software to run a swarm simulation

Postby Hooray » Wed Aug 28, 2013 2:11 pm

Hi & welcome,

yeah, it's possible using a handful of different approaches - such as the AI traffic system, which is configurable via XML files: http://wiki.flightgear.org/AI_Schedule_manager
However, the most flexible approach would be using scripting - FligthGear has a built-in scripting language (called "Nasal"), that can be used to control aircraft, and even to instantiate multiple AI aircraft, one of the most straightforward examples is the "tanker.nas" script, which creates a fully scripted AI tanker - that could be easily extended to create dozens of tankers, and obviously you could also change the 3D model if you wanted to. In fact, we have a separate addon, named "bombable" that adds "AI bots" to the simulator, for dogfighting purposes - none of that required C++ changes, it's all done in scripting space. Another users implemented a fully scripted missile (fox2.nas) that tracks aircraft - and we also have a feature for "wingman" support, too.

Actually, you could even create scripted AI pilots and scripted AI ATC that interact with eachother - it's all doable, and doesn't require rebuilding FlightGear from source.

Here are some pointers to get you started, these were all "recent" discussions that can be easily found by searching the forum:

Subject: AI development (bots) / AI engine

Hooray wrote:
AI development (bots)


I only saw this thread due to the new AI sub forum, I am not sure if I understood everything you wrote, but I think you are making this more complicated than it needs to be.
If this is all about "bots" controlling aircraft, then you can do this already.
Take for example a look at another discussion a couple of days ago: viewtopic.php?f=5&t=6807&p=66463#66463 (should probably also be moved to the new AI sub forum), where I roughly sketched out how to use Nasal to control an aircraft.

So this could then be used to create such "bots" (scripted pilots) for aircraft by using Nasal.

Thorsten has recently shown in very impressive ways that this method works really well and that Nasal can be used for many things already, including dynamic placement of AI objects:

viewtopic.php?f=5&t=6968
viewtopic.php?f=5&t=7107
viewtopic.php?f=5&t=7358


but I think you might already be able to do most of this, without too much work.



I once modified the tanker.nas script when somebody asked about the possibility to simulate birds and birdstrikes:
Subject: Bird strikes script

Hooray wrote:Just to prove my point: It really doesn't take any longer than say 2-3 minutes to open the tanker.nas script, change the model file name to point to the 3D model of a bird, what you end up with is a "funny bird" flying at 330+ kts ground speed at 17000 ft AMSL (I took the first freely available bird model that I could find...):

Image

As a next step, one could change the heuristics that move the bird (assuming that you don't want it to keep flying refueling patterns...), making it search actual thermals (local weather) would also not seem too complicated - it would just involve calls into the local weather code.

Probably, you'll want to add some collision detection code then.
Once this is working, you may want to animate the whole thing and probably change its size, too.

Like I said, it's all perfectly possible with the tanker.nas script.

Also, please do let me know if you need help creating "effect contrails" out of feathers and blood, okay :lol:




Subject: Possibility to run a fully automatized mission ?

Hooray wrote:
Is it possible to make a complete automatized mission, from engine start to engine shutdown ?


Yes, it is possible "to make" such a mission - but you will literally have to MAKE it by writing a script to outline all required steps for your aircraft.
Curt did that a while back for the f14b, which did a fully automated carrier approach using just Nasal scripting:

http://diydrones.com/profiles/blogs/uas ... simulation
http://www.mail-archive.com/flightgear- ... 33987.html
http://www.flightgear.org/forums/viewto ... =4&t=13615


http://www.flightgear.org/tours/carrier-ops/

Another example is the "tanker.nas" script in $FG_ROOT which implements a simple scripted AI tanker for AAR purposes: search.php?st=0&sk=t&sd=d&sr=posts&keywords=tanker.nas
http://www.mail-archive.com/search?q=ta ... eforge.net

And then we have the fox2.nas script which implements a fox2 AI missile using Nasal: search.php?st=0&sk=t&sd=d&sr=posts&keywords=fox2.nas

The "bombable" addon is completely implemented in Nasal and created multiple virtual pilots for dogfighting purposes: http://wiki.flightgear.org/Bombable




Subject: F-14B's Weapon System
Hooray wrote:
I am not an expert, but I would think one would just have to use the the model of the missile and code it so that the AIM-7 and AIM-54 can fire when the target is many miles away.


xiii is the developer of the F14b's fox2 implementation, the original thread was: Subject: Missiles with seeking capabilities.

To find related threads, see:
search.php?st=0&sk=t&sd=d&sr=posts&keywords=fox2.nas

Subject: Custom dialog, nasal console etc. to fire a missile?



Subject: Multiple intelligent flyers

Hooray wrote:
What I would like to know is if FlightGear could support multiple aircraft in a single instance (not a multiplayer server...I'd like to just spawn a bunch of these things), and also each having their own independent brain which I would provide functionality for, based on the output of the algorithms that I run.


For something like this, the simplest solution is probably using scripted AI traffic nodes. Note however that AI traffic cannot currently make use of any FDMs (JSBSim/YaSim), instead you need to come up with your own "pseudo FDM" in scripting space.

You might be able to circumvent this restriction by coming up with a separate FDM and communicating with FG using sockets.

We have a number of more or less complex examples for this. $FG_ROOT/Nasal/tanker.nas is the simplest test case you'll find, which basically spawns an "AI tanker" that can be used for refueling purposes. It would be possible to generalize the script some more in order to spawn an arbitrary number of aircraft. Also, you could equip them with a scripted control loop, so that each node can be controlled individually, i.e. by either setting a bunch of properties, or even by issuing ATC instructions.

Curt has recently provided a more complex example.
The most complex example for this technique is certainly the "bombable addon" which implements "AI bots" entirely in scripting space to provide "dog fighting" support.

I would suggest to search the archives (wiki, forum, mailing list) and look into the aforementioned examples.

Also, you'll inevitably need to look into the Nasal documentation, too: http://wiki.flightgear.org/Nasal_scripting_language

You may also be interested in this:
viewtopic.php?f=23&t=7791#p75820
viewtopic.php?f=23&t=5900
http://www.flightgear.org/forums/viewto ... 0&p=142081
viewtopic.php?f=30&t=10223
viewtopic.php?f=30&t=9033&p=90071&#p89374

Also, is it possible that any sort of sensing equipment is implemented here as well? I'd kind of like to give them a target and tell them to simply "go to that" as well.

viewtopic.php?f=36&t=212
viewtopic.php?f=36&t=7640



For coding examples, see this thread:
Subject: Working with AI/Multiplayer properties

Hooray wrote:Actually, the code to do this is already readily available in FlightGear.
$FG_ROOT/tanker.nas is a good demonstration for code that iterates over the AI properties.
Another good example is the multiplayer pilot list, which also iterates over the property tree.
You only need to combine snippets from these two files to come up with what you need.

Iteration is just a matter of using a loop to examine the property tree.

For example, to get a list of all aircraft entries in /ai/models and dump it to the console, use something like this:
Code: Select all
foreach(var a; props.globals.getNode("/ai/models").getChildren("aircraft"))
  props.dump ( a );


Obviously, you can repeat this using settimer() - and instead of dumping all nodes to the console, you could just as well process them in a different way.

Just post the code that you got so far, and we can tell you what you need to do differently.



At the moment, you'll want to look at files like tanker.nas, fox2.nas and/or the bombable addon to learn more about controlling AI aircraft via scripting, but we've been meaning to come up with a dedicated wrapper for that purpose for years:


Subject: Possibility of incorporating "learning" AI?

Hooray wrote:Like you say, we should probably consider this a long-term goal, and then it would make sense to extract the AI control code from bombable into some separate "ai.nas" module, i.e. splitting up bombable into separate files.

So that some of these could eventually be moved to the Nasal standard library directory in $FG_ROOT/Nasal, this is where we could then have a separate "ai.nas" module that allows controlling AI objects via the property tree. And another "pilot.nas" module which uses the ai.nas module.

It should definitely be simpler to do this with some standalone aircraft, or maybe just the tanker.nas module. So that we could tackle this task separately, reuse as much of the bombable code as possible, and re-integrate the results later on via some sort of API, like you say.

Custom "pilot" implementations could then be provided for different purposes, i.e. by reimplementing an abstract "pilot" base class and overriding functionality as required.

Currently, the major showstopper is probably the complexity of the whole system, and having to understand it in its entirety, if bombable could be split up into separate modules, that should be made easier - also, adding the bombable package as a Nasal subsystem (sub module) to the base package should be easier then.

Also it's worth mentioning that there have been discussions on exposing the autopilot/route manager system and the FDM system to Nasal space via the property tree and/or new Nasal extension functions, that could also help to make some old code obsolete, i.e. because a real autopilot or FDM could be used for scripted AI traffic eventually.
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Suitability of this software to run a swarm simulation

Postby darksanity » Thu Aug 29, 2013 2:54 pm

Wow thanks for the very detailed reply.

Mucked around with the software today.

The tanker file seems easy enough to modify.

If the end goal is to get a few aircraft to fly to a set of coordinates together would that be better implemented in your opinion with a modification of the tanker file or with the ai director and multiplayer functionality?

Is it at all possible to also move around freely (akin to flying about in google earth) and just view the environment and/or any ai driven planes you have running? I've looked at the ufo but its not "free" in terms of maneuverability if you get what I'm saying haha
darksanity
 
Posts: 2
Joined: Wed Aug 28, 2013 10:56 am

Re: Suitability of this software to run a swarm simulation

Postby Hooray » Thu Aug 29, 2013 3:14 pm

In general, anything based on multiplayer will require several instances of FlightGear - unless you are creating a standalone MP client that "injects" some form of traffic feed, which would then allow any connected FGFS instance to experience a conventional multiplayer environment. The interfacing sub forum has tons of pointers: search.php?st=0&sk=t&sd=d&sr=posts&keywords=feed&fid[]=36

The AI system itself is not all that flexible, but the various scripted approaches (tanker.nas, bombable etc) do use it as the backend for placing traffic, even though all the control logic is then handled in scripting space.

Is it at all possible to also move around freely (akin to flying about in google earth) and just view the environment and/or any ai driven planes you have running? I've looked at the ufo but its not "free" in terms of maneuverability if you get what I'm saying haha


The maneuverability of the ufo can be easily changed, and any multiplayer clients can be easily viewed/followed using a bunch of MP specific views (tracking traffic). The view manager itself is configurable through properties - in other words, regardless of the approach you are taking, you could simply copy the position/orientation properties of each simulated aircraft (think tanker) and copy those over to the main property tree, and you should be getting a view that's correct.

Before you do anything, I suggest to spend at least an hour reading through all the pointers I have provided earlier, which should provide all the answers that you need, because the advantages/disadvantages of the various approaches should become obvious then.
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Development

Who is online

Users browsing this forum: No registered users and 10 guests