Board index FlightGear Development AI Traffic

"Sophisticated AI aircraft" ... ?

Intelligent, computer controlled vehicles that drive/fly over the planet!

"Sophisticated AI aircraft" ... ?

Postby sharrif » Fri Feb 19, 2010 7:06 am

Hi everybody,

I'd like to follow an AI aicraft with realistic and "complex" behaviour. The simple way described on wiki just gives a heading, roll, ...

My idea (tested) was to record a previous flight done by me (thanks to a protocol dedicated to write directly in the good format), then reinject it in a flightplan of AI. But my tests don't work maybe because of limitations : flightplans are not dedicated to that ...

To help you to understand my problem, the goal is for example to follow an AI in acrobatic maneuvers in order to train, like a ghost in car games to improve your agility ... So i need the aircraft to behave like a classic aircraft : i don't want for example an AI which follows a 3D trajectory without rolling or yawing.
I can try to code if someone has a good guess how to start, because i don't want to go in a bad direction.

I need your help, thanks in advance.

PS : it could lead to formation flight training too ...
sharrif
 
Posts: 39
Joined: Thu Jan 28, 2010 9:50 am
Location: France

Re: "Sophisticated AI aircraft" ... ?

Postby grtux » Sun Feb 21, 2010 10:43 am

You seem getting no answer, however if we had such feature, it would be a great progress within the AI system.
We can replay a flight, we cannot include it in an AI process.

Cheers
g.robin
LFMO
User avatar
grtux
 
Posts: 432
Joined: Thu Dec 14, 2006 4:19 pm
Location: Provence France

Re: "Sophisticated AI aircraft" ... ?

Postby sharrif » Sun Feb 21, 2010 8:26 pm

Thx you, i'm not alone ...

Anyone has a good guess ?

(someone thinks i should mail this question to developpers ?)

Sorry to insist, but it could have many applications : formation flight,aerobatic, dogfight training, ...
We can even imagine tutorial such as : follow an aircraft (in turn) to train turn coordination (I know there are instruments for that, but this is maybe easier for a newbie !), or many others.

Are we only 2 people excited by such a possibility ?
sharrif
 
Posts: 39
Joined: Thu Jan 28, 2010 9:50 am
Location: France

Re: "Sophisticated AI aircraft" ... ?

Postby hovkid » Sun Feb 21, 2010 8:34 pm

sharrif wrote:Are we only 2 people excited by such a possibility ?


Nope, you have a third here, but I have no idea how to accomplish it :wink:
Fav Airliner - MD81 - Fav Fighter - F4J76 - Fav Light Aircraft - DHC2
User avatar
hovkid
 
Posts: 928
Joined: Tue Sep 01, 2009 10:20 am
Location: Gloucester, UK
Callsign: GB-TYER or AA-124

Re: "Sophisticated AI aircraft" ... ?

Postby sharrif » Sun Feb 21, 2010 8:38 pm

The problem is not solved, but if we are many to be interested ... !

So don't hesitate if you are like grtux or hovkid to say it too !

;)
sharrif
 
Posts: 39
Joined: Thu Jan 28, 2010 9:50 am
Location: France

Re: "Sophisticated AI aircraft" ... ?

Postby Thorsten » Mon Feb 22, 2010 8:55 am

To help you to understand my problem, the goal is for example to follow an AI in acrobatic maneuvers in order to train, like a ghost in car games to improve your agility ... So i need the aircraft to behave like a classic aircraft : i don't want for example an AI which follows a 3D trajectory without rolling or yawing.


The following could work if you have a table of all the flight data (position, airspeed, yaw, pitch, roll...):

* take the aircraft out of the AI system control, i.e. initialize it with zero airspeed
* make a Nasal control loop (I have achieved easily 20 fps with that for a single object, so it should work just fine without sudden jumps)
* move the aircraft around by setting continuously the position and orientation of the aircraft AI model in the property from the Nasal control loop, using an interpolation of your flight data table

=> since any property can be set from Nasal, you can in principle have the aircraft do about anything that can be adjusted in the property tree.
Thorsten
 
Posts: 11191
Joined: Mon Nov 02, 2009 8:33 am

Re: "Sophisticated AI aircraft" ... ?

Postby sharrif » Mon Feb 22, 2010 9:12 am

Thank you for your advices.

Just few questions :
- in your first point, you mean i need to create an AI with zero airspeed etc, am i ok ?
- ok for the nasal loop, i thought about it but i'm afraid of (real)"time" pb, but if you say you obtained 20 fps, i trust you.
- i can have the flight data without pb, but what is the best solution to save and/or read them : each variable in a vector ? Or make nasal read directly a xml (or text) file (but i don't know yet how) ?

Maybe if you have a similar piece of code, it helps me a lot, because i start from zero in nasal, so it could save me time.

Thank you again.
sharrif
 
Posts: 39
Joined: Thu Jan 28, 2010 9:50 am
Location: France

Re: "Sophisticated AI aircraft" ... ?

Postby Thorsten » Mon Feb 22, 2010 10:45 am

I'm not an expert in Nasal, and I still learning what one can do - so all I can do is give you ideas, you have to explore them yourself - and some of what I can think of may not work in practice. Sorry - best I can do.

in your first point, you mean i need to create an AI with zero airspeed etc, am i ok ?


Well, you need a visible model somewhere in the air, and that is an AI aircraft, which you then control via Nasal. Come to think of it, I don't know if it is easier to set the velocity to zero and let the Nasal update position (so the aircraft is moved from Nasal), or if one should better let the AI move the aircraft, and the Nasal just controls and modifies aircraft orientation continuously. Maybe the second is actually better in terms of performance.

- ok for the nasal loop, i thought about it but i'm afraid of (real)"time" pb, but if you say you obtained 20 fps, i trust you.


I've been using a Nasal script to rotate a thunderstorm model such that it always faces the viewer to get around a limitation of the animation xml-tag. I was able to run that with 20 fps without loss of performance and saw a smooth motion of the clouds. I would guess that the result generalizes to aircraft motion, but I haven't tried it.

- i can have the flight data without pb, but what is the best solution to save and/or read them : each variable in a vector ? Or make nasal read directly a xml (or text) file (but i don't know yet how) ?


No idea if Nasal eventually complains about array size. If not, I'd try to read everything in up front - harddisk usage is usually not a fast operation (and I don't know to what degree Nasal supports that). I have no clear idea what sampling rate is needed - maybe one state per second is enough to get what you want (especially if you interpolate the table), then the size is probably manageable.

Maybe if you have a similar piece of code, it helps me a lot, because i start from zero in nasal, so it could save me time.


I put the routines I used to rotate the cloud model into the Wiki - that has at least the loop structure and access to AI model properties, so you can see how that is done.
Thorsten
 
Posts: 11191
Joined: Mon Nov 02, 2009 8:33 am

Re: "Sophisticated AI aircraft" ... ?

Postby sharrif » Tue Feb 23, 2010 6:59 am

Don't worry, i don't want someone do this job for me :wink:

Thank you a lot for these clues, i saw the loop and i agree with the method of place firstly an AI in air.

If someone else has idea about the way to read (the lot of) pre-recorded flight datas ... Maybe we could mix the ideas : read automaticaly xml or text file and put it in arrays before running the pseudo realtime simulation. Someone knows how ? Maybe an example of parsexml() function could help me.
Precisely, my problem is : i have a xml file equivalent to a flight plan containing flight data and i want (in nasal) to put automaticaly each data in variable, such as velocities[i]= ..., altitude[i]= ...


For my part, i will start in using arrays, with hope there are no limitations.
sharrif
 
Posts: 39
Joined: Thu Jan 28, 2010 9:50 am
Location: France

Re: "Sophisticated AI aircraft" ... ?

Postby Hooray » Tue Feb 23, 2010 1:24 pm

Hi!

I'd like to follow an AI aicraft with realistic and "complex" behaviour. The simple way described on wiki just gives a heading, roll, ...


I am not sure what exactly you mean by "sophisticated AI aircraft" and "complex behavior", but AI aircraft in FlightGear are currently implemented in a different fashion from conventional FlightGear aircraft, i.e. these are actually separate aircraft models, textures and also logics/systems that drive each AI aircraft instance.

In other words, AI aircraft do not make use of FDM configuration files to create a realistic simulation, nor do they make use of the built-in autopilot facility, instead they use flight plans and a small performance-db.xml file to specify performance numbers for different types of aircraft (the latter of which is a relatively recent addition).

So it is normal to see less fidelity compared to conventional FlightGear aircraft that are simulated differently and more completely.

My idea (tested) was to record a previous flight done by me (thanks to a protocol dedicated to write directly in the good format), then reinject it in a flightplan of AI.


Well, to my knowledge AI aircraft cannot currently be driven by pre-recorded flight data.

On the other hand, having a way to optionally use such flight data to drive AI traffic would obviously be a pretty useful addition to the AI traffic system, as several others said already!

The plethora of possible instruction-like scenarios is an excellent example for the potential use-cases of such a feature.

But my tests don't work maybe because of limitations : flightplans are not dedicated to that ...


Yes, flight plans do not provide the "resolution" that you would normally require to redo/show a certain segment of previously recorded flight. Also, a flight plan works in terms of "waypoints" or route segments, whereas you are interested in replaying actual high fidelity flight data.

On the other hand, there are other FlightGear systems such as the multiplayer system or the replay system that do work with all of the required data.

Fundamentally, the AI traffic system that you are envisioning is basically a hybrid based on the current replay system and the multiplayer system, because it needs to record a user's flight data and be able to "replay" it as virtual traffic, in addition to the user's aircraft that is then also to be flown separately.

I can try to code if someone has a good guess how to start, because i don't want to go in a bad direction.


What do you mean by code?
Nasal scripting or are you familiar with C++ programming?
Are you able to build FlightGear from source?

If so, I would personally recommend to look into the replay and multiplayer systems, because these contain already all the features that you would need to extend the AI traffic system so that it can be driven from recorded flight data.

So if you are interested in doing C++ development, taking a look at these two systems would seem like a good idea to get started:

Basically, the replay system (implemented in $FG_SRC/Aircraft replay.c/h[xx])can show you how to sample flight data at runtime while the multiplayer system (implemented in $FG_SRC/Multiplayer) shows you how traffic nodes are inserted into FlightGear at runtime (internally, the multiplayer system uses pretty much the same AIModel backend as the AI Traffic system to render traffic).

You will need both capabilities to extend the AI system (implemented in $FG_SRC/AIModel) accordingly.

The replay system could probably be easily used by just exposing it to the property tree using a dedicated sub node in the tree, something along the lines of /replay which contains all relevant configuration parameters and another branch with the actual flight data sampled (like /replay/timestamp ).

This would also make it possible for replay data to be inspected/modified by Nasal scripts, at the same time adding the capability to serialize the replay buffer to an XML file for saving and loading recorded flights.

A flexible implementation would also allow the user to select those properties (or toplevel nodes) that are to be sampled (like a subscription), because this will obviously differ among different aircraft and use-case scenarios.

On the other hand, with some patience, you can probably also achieve this without any programming at all:

For example, doing a flight on multiplayer, recording the flight and replaying it on multiplayer while connecting to the same fgms instance with another fgfs client, will show the whole recorded flight so that you can fly in formation if you want to.
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: 11375
Joined: Tue Mar 25, 2008 8:40 am

Re: "Sophisticated AI aircraft" ... ?

Postby sharrif » Tue Feb 23, 2010 1:53 pm

Maybe too complex for me (the C++ part), but what an answer ! Thank you too, it gives me "ways".

I like the last "trick" ... I don't know if MP server accepts 2 versions of fgfs running on the same IP (?), but if it does, that would be a great solution ! If this works, i need to run fgfs without display for "my AI" (if someone knows how ?), if not my computer will explode :)

I wonder if MP accepts such a thing (= playback) : fgfs --generic=file,in,25,flight.out,playback,repeat --fdm=external --aircraft=xxx
sharrif
 
Posts: 39
Joined: Thu Jan 28, 2010 9:50 am
Location: France

Re: "Sophisticated AI aircraft" ... ?

Postby Hooray » Tue Feb 23, 2010 2:51 pm

I like the last "trick" ... I don't know if MP server accepts 2 versions of fgfs running on the same IP (?),


Yes, that should not be a problem - fgms and fgfs are not aware of replay being used or not-the protocol is so simple, that it doesn't really matter (you need to make sure to set up MP separately for each instance, though)

There is of course the obvious drawback that running multiple instances of FlightGear on the same machine (one for replaying a recorded flight, the other one for flying) will also at least double the load (CPU, RAM, GPU) on the computer.

So, your original idea to handle this scenario within one instance of FlightGear, isn't all that bad.

I do not think (or know) that you can disable the graphics window for a running FlightGear instance, however some time ago there was a property named "draw-otw" to control "out of the window" rendering.

I am not sure if this still works, last time I used this was before the PLIB->OSG transition took place.

(someone thinks i should mail this question to developpers ?)


That might actually be an idea: The maintainer and primary developer of the AI traffic system is also using these forums, so maybe you can even get in touch with him here (username:"durk").

In the past, he seemed pretty responsive and overall also very eager to implement community feature requests.

For example, we discussed last year an idea to enable AI traffic performance data to be customizable (instead of being hardcoded) by using a separate XML file and that idea was implemented pretty quickly:
viewtopic.php?f=5&t=3422
viewtopic.php?f=2&t=6681

And the issue of not being able to directly use standard FlightGear aircraft for displaying AI traffic was also discussed just a couple of days ago in another thread: viewtopic.php?f=4&t=6984

So, maybe it will become possible to simply use standard FG aircraft for this purpose some time soon.

Besides, there really is no reason why you shouldn't be able to get something to work by using some Nasal:

Thorsten wrote:The following could work if you have a table of all the flight data (position, airspeed, yaw, pitch, roll...):

* take the aircraft out of the AI system control, i.e. initialize it with zero airspeed
* make a Nasal control loop (I have achieved easily 20 fps with that for a single object, so it should work just fine without sudden jumps)
* move the aircraft around by setting continuously the position and orientation of the aircraft AI model in the property from the Nasal control loop, using an interpolation of your flight data table


Thinking some more about it, this sounds indeed like a workable solution.

Ideally, it would be possible to directly configure AI traffic to be driven by a Nasal script, so that the workaround can be ommitted, given that Nasal is already supported by scenery objects, it doesn't seem too far fetched to also allow Nasal to be embedded in or loaded directly from AI traffic files.

Thorsten wrote:since any property can be set from Nasal, you can in principle have the aircraft do about anything that can be adjusted in the property tree.


Yes, but this only holds true in theory: In practice, the possibilities are limited by tied properties and those that are updated/rewritten regularly during main loop invocations. In other words, you cannot modify all properties at runtime if they happen to be tied by C++ code or if they happen to be updated by other subsystems during the main loop.

This would only work if each subsystem could be individually disabled by setting a corresponding property, so that issues due to tied properties and unneeded updates do not occur.

If someone else has idea about the way to read (the lot of) pre-recorded flight datas ... Maybe we could mix the ideas : read automaticaly xml or text file and put it in arrays before running the pseudo realtime simulation. Someone knows how ? Maybe an example of parsexml() function could help me.


parsexml() is probably much more low level than what you need.

Also, I would refrain from using the generic protocol or logging facilities for the time being, simply because they output data in a format that would need to be separately processed by Nasal, instead I would come up with a custom sampler.

So, if I were to do something like this in Nasal and if I didn't want to touch the C++ source code, I would probably try something like the following:

  • create a Nasal function to sample properties at a configurable rate
  • add all relevant properties to a vector so that they can be easily sampled
  • set up a runtime configurable sample rate (listener)
  • write each sample to a dedicated subtree of the property tree (i.e. using the timestamp as toplevel node)
  • provide a way for the sampler to be stopped (e.g. using a listener)
  • once the sampler stops, write out the flight data to a property-tree conforming XML file by using the savexml fgcommand from Nasal

    And for replaying the flight using Nasal:
  • read in the XML file directly into the property tree (use a temporary location for readxml)
  • create a replay function in Nasal to read all data from the temporary location and write it to an AI traffic node as suggested above
  • again use a listener to provide a way to control the whole thing (stop/play)
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: 11375
Joined: Tue Mar 25, 2008 8:40 am

Re: "Sophisticated AI aircraft" ... ?

Postby sharrif » Tue Feb 23, 2010 5:16 pm

Things i tried now :
- replay works in MP

BUT i didn't manage to run 2 instances of fg on MP :(
(Error : failed to bind receive socket)

I tried other ports without success and other server than the first for AI, without success too.


updated : i found the solution here viewtopic.php?f=2&t=5190&p=37753&hilit=multiplayer+multiple#p37753
You have to configure different "in" port (and i set different callsign).

So this tricky solution works, waiting maybe an "offline" solution...
sharrif
 
Posts: 39
Joined: Thu Jan 28, 2010 9:50 am
Location: France

Re: "Sophisticated AI aircraft" ... ?

Postby durk » Tue Feb 23, 2010 5:56 pm

Hi Sharrif,

although I've been monitoring this thread, I haven't really focused my thoughts well enough to come up with a recommendation. In any case, it sounds like the most structural solution would require some modifications to the C++ code, although I do suspect that using the currently available FlightPlans would allow you to get approximately 50% of the work done. Let me summarize the intended goals here, and see if I get it right: In essence, you want to be able to simulate an AI aircraft to perform aerobatic manouvres. With the current FlightPlans, you can set a series of waypoints, where each waypoint contains a latitude, longitude, and altitude, which the AI aircraft will follow. Currently, the system has been designed preliminary with transport aircraft (be it military, commerical, or general aviation) in mind, so loops and or other drastic manouvers are not possible. Internally, the positions specified in the flightplan are used to let the AI aircraft climb/decent to specific altitudes, or let it steer to specific headings to reach the next waypoint, much like the way an airliner flies. What you want to achieve is more direct control over the aircraft's atttitude. Looking at the C++ code, I don't think there is a principle limitation. More specifically, looking at src/AIModels/AIAircraft.hxx, I see that the following functions are available:

void AccelTo(double speed);
void PitchTo(double angle);
void RollTo(double angle);
void YawTo(double angle);
void ClimbTo(double altitude);
void TurnTo(double heading);


Of these, AccelTo, ClimbTO, and TurnTo are used by the current waypoint based flight plans. I don't seen any principle limitation as to why there couldn't be instructions in a FlightPlan that would feed the PitchTo, RollTo, or YawTo, functions. This would probably require some modification of the xml code that reads the flightplans and that does the waypoint following logic, as well as some modifications of the performance database. The latter should be fairly straightforward (if necessary at all), the former requires some more thought. Also, although you can control the aircraft's attitude, this currently doesn't really affect the aicrafts climb performance, so that would have to be another problem to be tackeled. At this stage, I can't really tell how much work this would involve and therefore, I won't promise to start working on this right away. Nevertheless, this is how I see that your plan could be implemented. Please let me know whether it makes sense, and I'm happy to think a bit more about it. Suggestions are welcome.

Cheers,
Durk
durk
 
Posts: 354
Joined: Mon Nov 17, 2008 1:01 pm
Location: Ghent, Belgium
Callsign: PH-DRK
Version: git
OS: linux

Re: "Sophisticated AI aircraft" ... ?

Postby sharrif » Wed Feb 24, 2010 8:13 am

From my personnal point of view, the problem is to call a performance database for that.
For me, it's very interesting and it's a big opportunity to have datas from "real" fdm of flightgear (whatever the plane you choose, which is not the case for performance database i believe). Our computers (and fg) capacity doesn't permit 2 instances of fdm to run so we have to provide pre-recorded data, but for me pre-recorded data is not a pb.

In my simple mind of a non-developer, a boolean value set to true (+ more code...) could permit to force the "AI engine" to follow waypoints without care of performance data base, just in interpolating between "very near" values (= flight data recorded every X seconds or at X Hz, criteria to define). So we would have an AI version for real flightplan like commercial aircraft and "other" AI (with boolean to force) for "high dynamic" maneuver feed with pre-recorded flights. (i know : i describe the perfect world for me :) )

I guess it is not so simple to code etc. but tell me (no need huge details) if I'm completely wrong in the reflexion.

(maybe i can presume that people involved in viewtopic.php?f=2&t=5190&p=37753&hilit=multiple+instance#p37753, plus people used to dogfight or fly in formation would be interested too...)
sharrif
 
Posts: 39
Joined: Thu Jan 28, 2010 9:50 am
Location: France

Next

Return to AI Traffic

Who is online

Users browsing this forum: No registered users and 1 guest