1 | // created: 2012/04/18
|
---|
2 | // filename: main.cpp
|
---|
3 | //
|
---|
4 | // author: Guillaume Sanahuja
|
---|
5 | // Copyright Heudiasyc UMR UTC/CNRS 6599
|
---|
6 | //
|
---|
7 | // version: $Id: $
|
---|
8 | //
|
---|
9 | // purpose: main simulateur
|
---|
10 | //
|
---|
11 | //
|
---|
12 | /*********************************************************************/
|
---|
13 |
|
---|
14 | #include <tclap/CmdLine.h>
|
---|
15 | #include <Simulator.h>
|
---|
16 | #include <X4.h>
|
---|
17 | #include <X8.h>
|
---|
18 | #include <SimuImu.h>
|
---|
19 | #ifdef GL
|
---|
20 | #include <SimuCameraGL.h>
|
---|
21 | #include <Parser.h>
|
---|
22 | #include <Man.h>
|
---|
23 | #include <SimuUsGL.h>
|
---|
24 | #endif
|
---|
25 |
|
---|
26 |
|
---|
27 | using namespace TCLAP;
|
---|
28 | using namespace std;
|
---|
29 | using namespace flair::simulator;
|
---|
30 | using namespace flair::sensor;
|
---|
31 |
|
---|
32 | int port;
|
---|
33 | int opti_time;
|
---|
34 | string xml_file;
|
---|
35 | string media_path;
|
---|
36 | string scene_file;
|
---|
37 | string type;
|
---|
38 | string name;
|
---|
39 | string address;
|
---|
40 |
|
---|
41 | void parseOptions(int argc, char** argv) {
|
---|
42 | try {
|
---|
43 | CmdLine cmd("Command description message", ' ', "0.1");
|
---|
44 |
|
---|
45 | ValueArg<string> nameArg("n","name","uav name, also used for vrpn",true,"x4","string");
|
---|
46 | cmd.add( nameArg );
|
---|
47 |
|
---|
48 | ValueArg<string> xmlArg("x","xml","xml file",true,"./reglages.xml","string");
|
---|
49 | cmd.add( xmlArg );
|
---|
50 |
|
---|
51 | ValueArg<int> portArg("p","port","ground station port",true,9002,"int");
|
---|
52 | cmd.add( portArg );
|
---|
53 |
|
---|
54 | ValueArg<string> addressArg("a","address","ground station address",true,"127.0.0.1","string");
|
---|
55 | cmd.add( addressArg );
|
---|
56 |
|
---|
57 | ValueArg<string> typeArg("t","type","uav type, x4 or x8",true,"x4","string");
|
---|
58 | cmd.add( typeArg );
|
---|
59 |
|
---|
60 | ValueArg<int> optiArg("o","opti","optitrack time ms",false,0,"int");
|
---|
61 | cmd.add( optiArg );
|
---|
62 |
|
---|
63 | #ifdef GL
|
---|
64 | ValueArg<string> mediaArg("m","media","path to media files",true,"./","string");
|
---|
65 | cmd.add( mediaArg );
|
---|
66 |
|
---|
67 | ValueArg<string> sceneArg("s","scene","path to scene file",true,"./voliere.xml","string");
|
---|
68 | cmd.add( sceneArg );
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | cmd.parse( argc, argv );
|
---|
72 |
|
---|
73 | // Get the value parsed by each arg.
|
---|
74 | port=portArg.getValue();
|
---|
75 | xml_file = xmlArg.getValue();
|
---|
76 | opti_time = optiArg.getValue();
|
---|
77 | type = typeArg.getValue();
|
---|
78 | name=nameArg.getValue();
|
---|
79 | address=addressArg.getValue();
|
---|
80 | #ifdef GL
|
---|
81 | media_path=mediaArg.getValue();
|
---|
82 | scene_file=sceneArg.getValue();
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | } catch (ArgException &e) {
|
---|
86 | cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | int main(int argc, char* argv[]) {
|
---|
91 | Simulator *simu;
|
---|
92 | Model *drone;
|
---|
93 | SimuImu* imu;
|
---|
94 | #ifdef GL
|
---|
95 | SimuUsGL* us_gl;
|
---|
96 |
|
---|
97 | Camera *cam_av,*cam_bas;
|
---|
98 | Parser *gui;
|
---|
99 | Man *man;
|
---|
100 | #endif
|
---|
101 | parseOptions(argc,argv);
|
---|
102 |
|
---|
103 | simu= new Simulator("simulator",opti_time,90);
|
---|
104 | simu->SetupConnection(address,port);
|
---|
105 | simu->SetupUserInterface(xml_file);
|
---|
106 |
|
---|
107 | #ifdef GL
|
---|
108 | gui=new Parser(simu,960,480,640,480,media_path,scene_file);
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | if(type=="x4") {
|
---|
112 | drone=new X4(simu,name,0);
|
---|
113 | } else {
|
---|
114 | drone=new X8(simu,name,0);
|
---|
115 | }
|
---|
116 |
|
---|
117 | imu=new SimuImu(drone,"imu",0);
|
---|
118 |
|
---|
119 | #ifdef GL
|
---|
120 | us_gl=new SimuUsGL(drone,"us",0);
|
---|
121 | cam_bas=new SimuCameraGL(drone,"bottom camera",320,240,640,0,0);
|
---|
122 | cam_av=new SimuCameraGL(drone,"front camera",320,240,640,240,1);
|
---|
123 |
|
---|
124 | man=new Man(simu,"target");
|
---|
125 | #endif
|
---|
126 |
|
---|
127 | simu->RunSimu();
|
---|
128 |
|
---|
129 | delete simu;
|
---|
130 |
|
---|
131 | return 0;
|
---|
132 | }
|
---|
133 |
|
---|