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 F-JJTH » Tue Oct 16, 2012 8:10 pm

Yes FGAIS is a finished source code who use Curl.
The compilation works fine with g++ but don't work with cmake

You have download the source code of FGAIS here : http://clemaez.fr/flightgear/fgais_src.tar.gz
As you can see this source code use Curl and the compilation works perfectly with g++

I don't understand why cmake don't compile it :/

I f you are able to implement httpRequest from Simgear I'm ready to use it instead of Curl. I have no idea how to include it.
User avatar
F-JJTH
 
Posts: 697
Joined: Fri Sep 09, 2011 11:02 am

Re: Populate AI Traffic with real traffic

Postby Hooray » Tue Oct 16, 2012 8:16 pm

According to the error log that you posted, the CMakeList doesn't add the CURL_LIBS - these are undefined references. You merely need to add the cmake variable that specifies the libs for curl (libcurl) - so you succeeded already with everything else.
You can copy the missing line from your other CMakeList and everything should work 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: 10671
Joined: Tue Mar 25, 2008 8:40 am

Re: Populate AI Traffic with real traffic

Postby F-JJTH » Tue Oct 16, 2012 8:25 pm

The problem is that FGAIS doesn't use Cmake.
Here I'm forced to use Cmake because FGMS use Cmake.

I wrote FGAIS with the IDE CodeBlocks, for compiling FGAIS I had to do Ctrl+F9 and FGAIS was compiled automatically by CodeBlocks with g++
User avatar
F-JJTH
 
Posts: 697
Joined: Fri Sep 09, 2011 11:02 am

Re: Populate AI Traffic with real traffic

Postby Hooray » Tue Oct 16, 2012 8:32 pm

Like I mentioned earlier, the details are covered in our wiki: http://wiki.flightgear.org/Developing_using_CMake

Or just use google: cmake curl libcurl undefined reference.

And you'll see that you only need to:

1) edit CMakeLists.txt
2) add find_package(CURL REQUIRED)
3) edit src/server/CMakeLists.txt
4) add: target_link_libraries( $LIBS )

http://www.vtk.org/Wiki/CMake:How_To_Find_Libraries
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: 10671
Joined: Tue Mar 25, 2008 8:40 am

Re: Populate AI Traffic with real traffic

Postby F-JJTH » Tue Oct 16, 2012 8:48 pm

I have already googled during 2 hours with these keywords. You can be sure that Google is my best friend :) It's not my ususal to ask something without spend some hours on Google before.
I have already added find_package(CURL REQUIRED) (visible in my precedent commit)
There is no CmakeLists.txt in src/server

Also libcurl is already found as mentionned in my compilation log from my previous post:
Code: Select all
-- Found CURL: /usr/lib/x86_64-linux-gnu/libcurl.so
User avatar
F-JJTH
 
Posts: 697
Joined: Fri Sep 09, 2011 11:02 am

Re: Populate AI Traffic with real traffic

Postby Hooray » Tue Oct 16, 2012 8:50 pm

Yes, like I said: the ${LIBS} variable needs to be added via target_link_libraries(fgms)
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: 10671
Joined: Tue Mar 25, 2008 8:40 am

Re: Populate AI Traffic with real traffic

Postby F-JJTH » Tue Oct 16, 2012 9:08 pm

Ok problem solved :)
Thanks you Hooray !

The fix is : https://gitorious.org/~f-jjth/fgms/f-jj ... 6d4e08409b

Now I know the format of client position : it's a X=4214289.701480 Y=2548.23645 Y=84689.5254

If I correctly googled :
X=4214289.701480 Y=2548.23645 Y=84689.5254 is called "Cartesian" format
lat=21.25 long=62.11 alt=5136 is called "Geodetic" format

Hopefully SimGear provide a converter for that :)
User avatar
F-JJTH
 
Posts: 697
Joined: Fri Sep 09, 2011 11:02 am

Re: Populate AI Traffic with real traffic

Postby Hooray » Tue Oct 16, 2012 9:20 pm

You should really read my responses more carefully, I wouldn't respond if I couldn't answer your questions: viewtopic.php?f=23&t=17803&start=30#p168653 :D
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: 10671
Joined: Tue Mar 25, 2008 8:40 am

Re: Populate AI Traffic with real traffic

Postby F-JJTH » Tue Oct 16, 2012 10:57 pm

I just pushed a code who give the posssibility to construct an URL in order to download only JSON data for the area of the player but it's not the good solution.

The good solution should be :
- Download world aircraft position (sometimes there is more than 10 000)
- Create an object (OOP) called AIAicraft for each aircraft who has same variable than a FG_Player
- For each AIAircraft make the test :
Code: Select all
if ((Distance (AIAircraft->LastPos, CurrentPlayer->LastPos) < m_PlayerIsOutOfReach)
  sendTheAIPositionToThePlayer()
}


But as I said before, OOP is not yet in my skills... But it will :D
User avatar
F-JJTH
 
Posts: 697
Joined: Fri Sep 09, 2011 11:02 am

Re: Populate AI Traffic with real traffic

Postby Hooray » Tue Oct 16, 2012 11:01 pm

Please don't worry about your C++/OOP skills: Certainly there's no question that we can't get sorted here, there are so many experienced programmers here.
Also, let's be honest: You have demonstrated remarkably fast learning, even without any C++ background, you have apparently been able to understand the concepts of the existing source code, and adapted it to your needs - you are probably much smarter than you think! Seriously, most people who have tried this previously didn't get that far, despite some C++ background.

So if you have any specific questions, please post them here, so that we can get them sorted quickly!
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: 10671
Joined: Tue Mar 25, 2008 8:40 am

Re: Populate AI Traffic with real traffic

Postby Hooray » Tue Oct 16, 2012 11:05 pm

To add a class named AIAircraft, just do this (in your header/hxx file):

Code: Select all
class AIAircraft {
public:
// add your public methods/variables here
private:
// add your private methods/variables here (only accessible from your class)
};


To initialize the class, you will want to use a so called "constructor" which has the same name as the class itself, i.e.:

Code: Select all
AIAircraft() {
}


This is added to your cxx file, prefixed with the namespace (=name of the class):

Code: Select all
AIAircraft::AIAircraft() {
 
}


To add any arguments to the constructor:


Code: Select all
AIAircraft::AIAircraft(double lat, double lon, double alt) {
 
}
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: 10671
Joined: Tue Mar 25, 2008 8:40 am

Re: Populate AI Traffic with real traffic

Postby F-JJTH » Wed Oct 17, 2012 10:02 pm

Now FGMS is able to receive and parse AI traffic every 20 seconds :)
https://gitorious.org/~f-jjth/fgms/f-jj ... 71d8eb2deb

My current issue is :
For the moment the list of AI aircraft is in fg_ai.cxx
and I'm not able to consult the list in this file (fg_server.cxx)

I need to access to the list of AI aircraft here in order to compare
the distance Player/AI and send only AI in area of Player


Hope to be able to fix it tomorrow.

Cheers,
Clément
User avatar
F-JJTH
 
Posts: 697
Joined: Fri Sep 09, 2011 11:02 am

Re: Populate AI Traffic with real traffic

Postby Hooray » Wed Oct 17, 2012 10:15 pm

WOW, promising progress!!

BTW: you only need to include the header file in fg_server.cxx so that you can directly access all public fields/methods from the other file.
You can also add a method (function) to get a pointer to your list of AI traffic.

Stripped down example:

test.hxx
Code: Select all
class Foo {
public:
 std::vector<int>& getList() const {return mList; }
private:
 std::vector<int> mList;
};


server.cxx
Code: Select all
#include "test.hxx"

 Foo * f = new Foo();
 f->getList();
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: 10671
Joined: Tue Mar 25, 2008 8:40 am

Re: Populate AI Traffic with real traffic

Postby F-JJTH » Thu Oct 18, 2012 5:00 am

I just discorvered the "heritage" that should be better use for me.

Currently I'm goind to create 2 class :
Code: Select all
class FG_AIAircraft {

}

class FG_AIShip {

}


But it seems that's possible to do :
Code: Select all
class FG_AI {

}

class Aircraft : public FG_AI {

}

class Ship : public FG_AI {

}


I will need to redone a part of my code in order to match this new technique of coding.

@Hooray : I seen that "new" keyword is kind of depreciated because it's more difficult to free the memory (Foo* f = new foo(); should be finished by delete f;)
Is it possible to replace
Code: Select all
#include "test.hxx"

Foo * f = new Foo();
f->getList();


by

Code: Select all
#include "test.hxx"

Foo f;
f.getList();


The result is the same ?
User avatar
F-JJTH
 
Posts: 697
Joined: Fri Sep 09, 2011 11:02 am

Re: Populate AI Traffic with real traffic

Postby Icecode GL » Thu Oct 18, 2012 7:35 am

@Hooray : I seen that "new" keyword is kind of depreciated because it's more difficult to free the memory (Foo* f = new foo(); should be finished by delete f;)
Is it possible to replace

Code: Select all
    #include "test.hxx"

    Foo * f = new Foo();
    f->getList();


by

Code: Select all
    #include "test.hxx"

    Foo f;
    f.getList();


The result is the same ?


The result is the same, but it depends on what you want to do with the variable later.

In the first case, you are using a pointer and allocating dynamic memory to it. This is useful when you want to move the pointer around (passing to functions etc.), since you only pass the memory address, which is much smaller (in most cases) than the value itself. In C++ this is not necessary since you can pass by reference. So my recommendation would be: don't use pointers unless you need to pass them a lot.

See this and this for some information about both topics (pointers and dynamic memory).
Icecode GL
 
Posts: 415
Joined: Thu Aug 12, 2010 12:17 pm
Location: Spain
Callsign: icecode
Version: GIT
OS: Arch Linux

PreviousNext

Return to AI Traffic

Who is online

Users browsing this forum: No registered users and 1 guest