Status of AI in FlightGear: Difference between revisions
Line 62: | Line 62: | ||
|author=<nowiki>Hooray</nowiki> | |author=<nowiki>Hooray</nowiki> | ||
|date=<nowiki>Wed Aug 28</nowiki> | |date=<nowiki>Wed Aug 28</nowiki> | ||
}} | |||
}} | |||
{{FGCquote | |||
|For starters, I'd suggest to read through these:<br/> | |||
[[What_is_Nasal]]<br/> | |||
[[Nasal_for_C%2B%2B_programmers]]<br/> | |||
<br/> | |||
You'll find a few analogies in those articles - but basically, Nasal scripting works exactly like JavaScript in your browser: it's an embedded extension language, that is integrated into FlightGear as a conventional FlightGear subsystem - during each frame, the Nasal interpreter gets its time slice to process scripts - which is why badly written scripts may slow down the sim and affect frame rate/frame spacing - in addition, Nasal supports dozens of FG-specific extension functions to do various FG-related things - which allows callbacks to be registered in the form of property listeners (which get invoked whenever a property is written to) or via timers (that may expire and trigger a callback). In addition, there's a standard library of Nasal library functions and a plethora of FlightGear-specific modules in $FG_ROOT/Nasal that greatly simplify coding stuff from scratch.<br/> | |||
<br/> | |||
To learn more about timers, see: [[List_of_Nasal_extension_functions#settimer.28.29]]<br/> | |||
[[List_of_Nasal_extension_functions#maketimer.28.29_.28v._2.11.2B.29]]<br/> | |||
<br/> | |||
To learn more about listeners, see: [[Using_listeners_and_signals_with_Nasal]]<br/> | |||
<br/> | |||
You can start playing around with Nasal by using the so called "Nasal Console": [[Nasal_Console]]<br/> | |||
[[File:Nasal_console.png|250px]] | |||
|{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=190385#p190385 | |||
|title=<nowiki>Re: How would I go about controlling an airplane with nasal?</nowiki> | |||
|author=<nowiki>Hooray</nowiki> | |||
|date=<nowiki>Fri Sep 20</nowiki> | |||
}} | }} | ||
}} | }} |
Revision as of 09:41, 26 June 2014
AI Scenarios vs. Scripting
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.
— Hooray (Thu Aug 29). Re: Suitability of this software to run a swarm simulation.
(powered by Instant-Cquotes) |
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. |
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.
— Hooray (Wed Aug 28). Re: Suitability of this software to run a swarm simulation.
(powered by Instant-Cquotes) |
For starters, I'd suggest to read through these: What_is_Nasal — Hooray (Fri Sep 20). Re: How would I go about controlling an airplane with nasal?.
(powered by Instant-Cquotes) |
Scripted AI in FlightGear
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 <iframe width="420" height="315" src="http://www.youtube.com/embed/LL7bdHrR8uI" frameborder="0" allowfullscreen=""></iframe>
— Hooray (Mon Feb 04). Re: Possibility to run a fully automatized mission ?.
(powered by Instant-Cquotes) |
he 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.
|
Scripted AI Missiles
xiii is the developer of the F14b's fox2 implementation, the original thread was: Subject: Missiles with seeking capabilities.
<iframe width="420" height="315" src="http://www.youtube.com/embed/UL7jQkl1qe4" frameborder="0" allowfullscreen=""></iframe>
|
Learning AI
It is certainly possible (like xiii said already), however it will require a solid background in AI and coding. It could definitely be implemented without touching any C++ though (i.e. using scripted Nasal code). I am disagreeing a little with xiii regarding the feasibility of using the bombability package for this, it's actually pretty well-written and well-commented source code. However, it is obviously a huge and complex piece of software. Just understanding how everything works, will take weeks or even months. — Hooray (Sun Jul 08). Re: Possibility of incorporating "learning" AI?.
(powered by Instant-Cquotes) |
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.
— Hooray (Thu Aug 02). Re: Possibility of incorporating "learning" AI?.
(powered by Instant-Cquotes) |
Custom "pilot" implementations could then be provided for different purposes, i.e. by reimplementing an abstract "pilot" base class and overriding functionality as required.
— Hooray (Thu Aug 02). Re: Possibility of incorporating "learning" AI?.
(powered by Instant-Cquotes) |
Controlling the main Airplane
I'd suggest to get started by looking at the tanker.nas script instead - fox2.nas, the f14b demo and the bombable script are much more sophisticated, while tanker.nas is really pretty simple and straightforward: https://gitorious.org/fg/fgdata/source/ ... tanker.nas
— Hooray (Thu Sep 19). Re: How would I go about controlling an airplane with nasal?.
(powered by Instant-Cquotes) |
hat would be great - but you'll probably want to look at tanker.nas for now, and look up the various APIs used there (see the wiki). The other examples are a little more involved. — Hooray (Thu Sep 19). Re: How would I go about controlling an airplane with nasal?.
(powered by Instant-Cquotes) |
you can simply look at the autopilot dialog of your aircraft (e.g. c172p, b1900d or 777) - sometimes, looking at the cockpit panel may also make sense (MCP) - otherwise, you can then simply use the autopilot system to control the aircraft, which also includes support for flying complete routes via the built-in route manager, for details, see:
— Hooray (Fri Sep 20). Re: How would I go about controlling an airplane with nasal?.
(powered by Instant-Cquotes) |
Fully Automatized Missions
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: <iframe width="420" height="315" src="http://www.youtube.com/embed/cvbtSG9cy20" frameborder="0" allowfullscreen=""></iframe>
— Hooray (Mon Feb 04). Re: Possibility to run a fully automatized mission ?.
(powered by Instant-Cquotes) |