Board index FlightGear Development AI Traffic

Populate AI Traffic with real traffic

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

Re: Populate AI Traffic with real traffic

Postby Hooray » Thu Oct 18, 2012 1:01 pm

Regarding inheritance: yes, absolutely true - I wanted to post a comment describing that (that's what OOP is about), but thought it might be too difficult - but it seems you are able to understand even complex topics pretty quickly! :D

Please let us know should you have any OOP related questions.
Note that you can make sure that only inherited classes can access certain members of a class by moving them to the "protected" section:

Code: Select all
class Foo {
public:
 // members here can be accessed from everywhere
protected:
 // members here can only be accessed from classes that are derived from Foo, such as in: class Foo2 : public Foo {};
private:
 // members here can only be accessed by methods of the Foo class
};


These are the basic concepts, there are some more difficult things like "friend" classes, but they won't be required here and would only complicate things.

Note that you generally differentiate between composition and aggregation, i.e. "is-a" or "has-a" - I suggest to briefly read these two explanations:
http://fr.wikipedia.org/wiki/Composition_(programmation)
http://fr.wikipedia.org/wiki/Agr%C3%A9g ... grammation)

Regarding pointers/heap memory (dynamically allocated memory via new): I only used the example, because I didn't know anything about the lifetime of your classes/objects. Which is important because stack-allocated memory is destroyed once the object is destroyed, heap memory will continue to be available.

Overall, I agree with Icecode's comments - but, I'd suggest to use so called "Smart Pointers" here, which look like templates (that you are using already!), but which manage memory allocation/freeing automatically for you. See the SGSharedPtr<> template

Basically, you would be adding this to your private/protected section:

Code: Select all
private:
 typedef std::vector<std::string> aircraft_list;
 SGSharedPtr<aircraft_list> _mAircraftList;


Note that the typedef is just intended to be an example here, to demonstrate the usage of the SGSharedPtr template

To pass around your own data structures, you usually use a typedef like this:

Code: Select all
class Foo {
public:
 typedef std::vector<std::string> aircraft_list;
 aircraft_list& get_list() const { return _mAircraftList; }
 
private:
 SGSharedPtr<aircraft_list> _mAircraftList;
};


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: Populate AI Traffic with real traffic

Postby F-JJTH » Thu Oct 18, 2012 9:35 pm

Thanks you Icecode GL & Hooray
Unforunately today has been a non productive day, after a lot of hours trying implement the inheritance system I abandoned this solution because I'm not able to fix all compilation error.

For now project is stalled because I don't know what to do more.

Hoping that tomorrow will be more productive 8)

PS: Oh I forgot a good new : planefinder.net is ready to let us using their data :) They propose a 60 seconds interval between each HTTP request.

Cheers,
Clément
User avatar
F-JJTH
 
Posts: 696
Joined: Fri Sep 09, 2011 12:02 pm

Re: Populate AI Traffic with real traffic

Postby Hooray » Thu Oct 18, 2012 10:08 pm

Just post your compilation errors here and I'm sure we can tell you what's wrong (maybe along with the lines of code that are mentioned in the errors).

EDIT: It might be a good idea to raise the whole issue on the FG devel mailing list, because it seems that there's a more holistic approach in progress using HLA: http://www.mail-archive.com/flightgear- ... 32045.html
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: Populate AI Traffic with real traffic

Postby F-JJTH » Fri Oct 19, 2012 11:14 pm

If I understand correctly :
HLA is a standard network protocol used by multiple (dozens? millions?) software to send data over network. For example (stupid) : if Call Of Duty use HLA to send data over network, FG should be able to display Call Of Duty player ?
"Call Of Duty" is not really a good example because I see that HLA protocol is mostly reserved for real time simulator software.

Indeed it should be interesting to use this protocol (if my understanding is correct), but concretely how many real time simulator software exist un the world ?
We can already consider every flight simulator software :
- FlightGear (of course ;) )
- Flight Simulator (development is now abandonned IIRC)
- X-Plane
- Microsoft Flight (not sure that they plan to implement HLA)
- Flight Legacy (fly simvol)

submarine simulator software
car simulator software
truck simulator sofware
ship simulator software
train simulator software

Ok, there is a lot of simulator software exist in the world but how many use multiplayer mode ? and how many use HLA protocol ? Moreover most of them are now abandonned or doesn't interesting for FlightGear (submarine are not really interesting in FG :) )
After asking my friend Google "software with HLA support" it seems that there no software who support it (at least for simulator software)

Finally what is the interest to implement HLA support if nobody use it ? The idea of a standard protocol for every simulator software is good, but if nobody use it... you see what I mean.

Of course we can say <<FlightGear could be the first software who use officialy and proudly HLA protocol>> it could be a good head up for the protocol, for the moment I see only 2 or 3 software who are able to implement HLA protocol (because the rest of software are no longer supported/developped)
Thus which simulator software still actively developped in the world ?
- FlightGear
- X-Plane
- Microsoft Flight
- Flight legacy (fly simvol)

I'm not sure that Microsoft Flight is interested to implement HLA protocol, thus is still only 2 softwares : FlightGear and X-Plane
Now the question is : Someone know if X-Plane plan to implement HLA protocol ? and for Flight legacy ?

In conclusion I would say : HLA protocol is a great idea but the problem come mostly from other software developper's who don't implement HLA in their software.

To come back at the subject :
Today was a better day than yesterday :)
Now I'm able to consult the list of AI aircraft where I need. I have also started to implement a "selector" who select only AI aircraft in area of the player. In fact this selector create a list of AI aircraft in the area of the player.

Unfortunately for the moment the list doesn't contain all AI aircraft that she should and I don't know why.
For example, I launch FG at KSFO, FGMS receive my position and start to select only AI aircraft in my area, but only 2 or 3 AI aircraft are added to the list instead of dozens of AI aircraft. Moreover the 2 or 3 AI aircraft in the list are not really in my area :/

I have commited all my work in the repo, if someone is able to take a look at it and say me where is the problem it's cool ;)
I have checked if I have inversed lat/lon somewhere in my source code but it seems that I haven't done this error.

The next work is :
Since I received the authorization to download aircraft position from planefinder.net every 60 seconds, I need to create a function who predict the position of each aircraft every 4 seconds (I plan to send AI traffic every 4 seconds).
In this way, each AI aircraft are associed to a kind of flight plan containing 15 positions:
0 sec : I receive fresh aircraft position from planefinder.net + I compute the next 15 positions of the aircraft at 4s interval (I know only the position, airspeed, heading of the aircraft to do that)
4 sec : I send the 1st computed positions
8 sec : I send the 2nd computed positions
...
...
56 sec : I send the 15th computed positions
0 sec : I receive fresh aircraft position from planefinder.net + I compute the 15 next positions of the aircraft at 4s interval
...
...

I think that you see what I mean. If someone has an idea of how to do that : say it :)

Cheers,
Clément
Last edited by F-JJTH on Sat Oct 20, 2012 5:05 pm, edited 1 time in total.
User avatar
F-JJTH
 
Posts: 696
Joined: Fri Sep 09, 2011 12:02 pm

Re: Populate AI Traffic with real traffic

Postby F-JJTH » Sat Oct 20, 2012 5:04 pm

Hooray,

Can you tell me if the function SGGeodesy::direct available here : http://gitorious.org/fg/simgear/blobs/m ... xx#line306 is able to predict position ?
I'm not sure to understand correctly it.

Thanks in advance
User avatar
F-JJTH
 
Posts: 696
Joined: Fri Sep 09, 2011 12:02 pm

Re: Populate AI Traffic with real traffic

Postby Hooray » Sat Oct 20, 2012 5:14 pm

Good find.
Yes, it will compute a new position - but it will not predict it, it will calculate it by specifiying an offset (course, distance).
You can find the description at the top of the function: https://gitorious.org/fg/simgear/blobs/ ... xx#line218

What we need in FGAIS is interpolation (or rather extrapolation) - i.e. based on time and speed vectors (vertical/horizontal).
FGMS/FG should already be using code like this to make the appearance of the 3D model appear smoothly
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: Populate AI Traffic with real traffic

Postby F-JJTH » Mon Oct 22, 2012 1:48 pm

Hi all,

I've solved the problem about the list of AI in area of player.
Now FGMS is able to download global AI traffic (worldwide) then select only AI traffic in area of player (100nm as for MP)

Now I hesitate about the way of continuing the implementation... I have 2 solutions :
1) Send AI traffic position every 60 seconds to fgfs client (the player), then the fgfs client calcul himself the extrapolation.
I've take a quick look at the AIMgr in fgfs and it seems that AI works with "waypoint" that the AIMgr use one after one . We can imagine that each 60 seconds, the AI traffic sent by FGAIS is added as a waypoint.
But I need to explore the AI source code in order to know if it's doable. If someone has skills/knowledge with AI implementation let me know :)

2)On server side, create a function who calculate the position of the AI all 4 seconds from the new AI position received from planefinder.net. All positions should be stored in an array then sent each 4 seconds to fgfs client (the player).
This solution need a stable runtime : how to be sure that every fgfs client receive their AI traffic each 4 seconds ? If there is 3 or 4 client it's not a problem, but if there is 60 or 80 fgfs client ? Does server has enough time to send AI traffic to every client every 4 seconds ?

If you have a better idea, or an answer let me know ;)

Cheers,
Clément
User avatar
F-JJTH
 
Posts: 696
Joined: Fri Sep 09, 2011 12:02 pm

Re: Populate AI Traffic with real traffic

Postby stuart » Mon Oct 22, 2012 2:10 pm

Hi Clément,

Great work so far!

I don't think you can generate AI MP aircraft in the AI system with waypoints. IIRC they have to be created when FG starts. Even if it was possible, I don't think the system is accurate enough - when I tried using it for ship AIS last year I found that it wasn't quite good enough. I also don't think that architecturally this is something the client should do - ideally these should just be seen as other MP aircraft from the client perspective.

I think having the fgais interpolate the aircraft/ship position and transmit them every 4 seconds (or possibly more frequently) is a better approach. Don't worry about dropped packets, or large numbers of client - the FG client and fgms have to deal with that already.

-Stuart
G-MWLX
User avatar
stuart
Moderator
 
Posts: 1629
Joined: Wed Nov 29, 2006 10:56 am
Location: Edinburgh
Callsign: G-MWLX

Re: Populate AI Traffic with real traffic

Postby F-JJTH » Mon Oct 22, 2012 2:48 pm

Hi Stuart,

Ok I will forget the client side solution and work on server side.

transmit them every 4 seconds (or possibly more frequently)
More ? In fact it's less difficult to send more :) But I'm a bit worried about the amount of data sent by the server. With FGAIS the number of packet sent could be multiplied by 4 or 5. I don't know if every FGMS instance currently online are able to send all these data because some of them could be limited about the bandwidth.

If some FGMS maintener can let me know if it's a problem for them to increase the number of data by 4 or 5 it will be a good indication.

Cheers,
Clément
User avatar
F-JJTH
 
Posts: 696
Joined: Fri Sep 09, 2011 12:02 pm

Re: Populate AI Traffic with real traffic

Postby stuart » Mon Oct 22, 2012 3:54 pm

I'd need to check on my machine at home, but I think an MP client transmits at 10Hz by default, so 40x the rate your are proposing.

Given that all servers (should) see all clients, and we regularly see > 100 clients on MP, each FGMS instance is handling around 1000 messages per second. So, I think there's quite a lot of leeway available.

In anycase, I would suggest ensuring that it's configurable and the server implementation is capable of transmitting at 10Hz if required.

-Stuart
G-MWLX
User avatar
stuart
Moderator
 
Posts: 1629
Joined: Wed Nov 29, 2006 10:56 am
Location: Edinburgh
Callsign: G-MWLX

Re: Populate AI Traffic with real traffic

Postby F-JJTH » Tue Oct 23, 2012 8:28 pm

Hi,

I have moved the main part of FGAIS source code from fg_server.cxx to fg_ai.cxx. I prefer to separate the server part from the ai part.
Unfortunately this new source code organization bring a problem that I can't solve :/

I try to access to the list of player currently connected. This list is a part of the FG_SERVER class. I want to access to this list in the class FG_AIAircraft.
I created an accessor : getPlayerList() who provide a pointer to this list. But It doesn't work. The accessor is here : https://gitorious.org/~f-jjth/fgms/f-jj ... xx#line826

You can have a look at it here : https://gitorious.org/~f-jjth/fgms/f-jj ... xx#line489
The compilation works fine without error, and when I start to FGMS he should print "I'm a client" as many as client are connected. But when I connect my fgfs client to fgms nothing is printed :/

Why this pointer doesn't work ? why the variable "PlayerList" doesn't contain the list of player currently connected ?

Cheers,
Clément
User avatar
F-JJTH
 
Posts: 696
Joined: Fri Sep 09, 2011 12:02 pm

Re: Populate AI Traffic with real traffic

Postby Hooray » Tue Oct 23, 2012 8:44 pm

Hi, the C++ code is syntactically valid, but in your sendAITraffic() method you are creating a NEW FG_SERVER instance: https://gitorious.org/~f-jjth/fgms/f-jj ... xx#line500

What you really need to do here is to get a handle to the main fgms (FG_SERVER) instance (seems to be in https://gitorious.org/~f-jjth/fgms/f-jj ... cxx#line44 ), then you can also directly access the FG_SERVER instance - i.e. via a "friend class" (or function).
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: Populate AI Traffic with real traffic

Postby F-JJTH » Tue Oct 23, 2012 9:45 pm

Yep, indeed I create a new instance instead of access to the instance already created in main.cxx

How to create this "friend" function ?
User avatar
F-JJTH
 
Posts: 696
Joined: Fri Sep 09, 2011 12:02 pm

Re: Populate AI Traffic with real traffic

Postby Hooray » Tue Oct 23, 2012 9:59 pm

you could just keep it simple and make the Servant variable global, and include it via header file, or directly add this to the top of your fg_ai.cxx/hxx file:


extern FG_SERVER Servant;


Then you can directly use the Servant variable created in fg_server.cxx once it is used in global scope.
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: Populate AI Traffic with real traffic

Postby F-JJTH » Wed Oct 24, 2012 10:32 pm

Hi all,

Today has been a good day for me :)
Finally I have successfully implemented the inherited system ! Also I've reorganized my source code, now it's more easier to read and understand it. Some explanation :

ai_item.cxx/hxx => contain the class AI_Ship and class AI_Aircraft
fg_aimgr.cxx/hxx => contain all the function concerning AI traffic in AI_Mgr class
fg_server.cxx => contain the InitAITraffic() call and the sendAITraffic() call

You can see the source code here : https://gitorious.org/~f-jjth/fgms/f-jj ... src/server

New feature ! now FGAIS is optional. I can set it in the fgms.conf with :
Code: Select all
server.aitraffic = true/false


After all these good news (at least for me), come the problems :

My class AI_Mgr has 2 main functions :
1- downloadAITraffic()
2- sendAITraffic()

The function downloadAITraffic() must be able to make a new request to the provider each 60 seconds without freezing FGMS. This imply to launch downloadAITraffic() in a separate thread. In this separate thread, downloadAITraffic() must be able to fill attributes from AI_Mgr class. Once downloadAITraffic() filled the list of AI, the function sendAITraffic() do the rest of work.

Currently sendAITraffic() is not implemented (only some test line), for the moment my problem is on the downloadAITraffic() side.

My question is : how to launch downloadAITraffic() in a separate thread who is able to fill attribute from AI_Mgr class ?

I've already tried some technical solution without success like :
Code: Select all
void*
downloadAITraffic_helper
( void* arg )
{
  static_cast<AI_Mgr*>(arg)->downloadAITraffic();
  return NULL;
}

void
FG_AIAircraft::downloadAITraffic
()
{
  // My function is here
}

pthread_create (&dlAITraffic, NULL, downloadAITraffic_helper, NULL);

Code: Select all
void
*downloadAITraffic_helper
( void* )
{
  FG_AIAircraft ai;
  for (;;) {
    ai.downloadAITraffic();
  }
  return NULL;
}

void
FG_AIAircraft::downloadAITraffic
()
{
  // My function is here
}

pthread_create (&dlAITraffic, NULL, downloadAITraffic_helper, NULL);


The compilation work fine for these 2 solutions, but when a client connect to the server I have a SegFault.

In the past I was able to download AI traffic in another thread but at this time my function downloadAITraffic() was not a method of AI_Mgr class.

All help is welcome !


Cheers,
Clément
User avatar
F-JJTH
 
Posts: 696
Joined: Fri Sep 09, 2011 12:02 pm

PreviousNext

Return to AI Traffic

Who is online

Users browsing this forum: No registered users and 5 guests