source: flair-src/trunk/demos/PidStandalone/simulator/src/main.cpp@ 445

Last change on this file since 445 was 291, checked in by Sanahuja Guillaume, 6 years ago

add exit failure

File size: 2.9 KB
Line 
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 <Parser.h>
21#include <SimuUsGL.h>
22#endif
23
24
25using namespace TCLAP;
26using namespace std;
27using namespace flair::simulator;
28using namespace flair::sensor;
29
30int port;
31int opti_time;
32string xml_file;
33string media_path;
34string scene_file;
35string type;
36string name;
37string address;
38
39void parseOptions(int argc, char** argv)
40{
41 try
42 {
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
61 ValueArg<int> optiArg("o","opti","optitrack time ms",false,0,"int");
62 cmd.add( optiArg );
63
64#ifdef GL
65 ValueArg<string> mediaArg("m","media","path to media files",true,"./","string");
66 cmd.add( mediaArg );
67
68 ValueArg<string> sceneArg("s","scene","path to scene file",true,"./voliere.xml","string");
69 cmd.add( sceneArg );
70#endif
71
72 cmd.parse( argc, argv );
73
74 // Get the value parsed by each arg.
75 port=portArg.getValue();
76 xml_file = xmlArg.getValue();
77 opti_time = optiArg.getValue();
78 type = typeArg.getValue();
79 name=nameArg.getValue();
80 address=addressArg.getValue();
81#ifdef GL
82 media_path=mediaArg.getValue();
83 scene_file=sceneArg.getValue();
84#endif
85
86 } catch (ArgException &e) {
87 cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
88 exit(EXIT_FAILURE);
89 }
90}
91
92
93int main(int argc, char* argv[])
94{
95 Simulator *simu;
96 Model *drone;
97 SimuImu* imu;
98#ifdef GL
99 SimuUsGL* us_gl;
100 Parser *gui;
101#endif
102 parseOptions(argc,argv);
103
104 simu= new Simulator("simulator",opti_time,90);
105 simu->SetupConnection(address,port);
106 simu->SetupUserInterface(xml_file);
107
108#ifdef GL
109 gui=new Parser(1024, 768, 1024, 768,media_path,scene_file);
110#endif
111
112 if(type=="x4")
113 {
114 drone=new X4(name,0);
115 }
116 else
117 {
118 drone=new X8(name,0);
119 }
120 imu=new SimuImu(drone,"imu",0,0);
121
122#ifdef GL
123 us_gl=new SimuUsGL(drone,"us",0,0);
124#endif
125
126 simu->RunSimu();
127
128 delete simu;
129
130 return 0;
131}
132
Note: See TracBrowser for help on using the repository browser.