source: flair-src/trunk/demos/PidStandalone/uav/src/main.cpp@ 437

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

add exit failure

File size: 3.5 KB
Line 
1// created: 2016/06/01
2// filename: main.cpp
3//
4// author: Gildas Bayard
5// Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7// version: $Id: $
8//
9// purpose: exemple de code x4
10//
11//
12/*********************************************************************/
13
14#include "PidUav.h"
15#include <UavFactory.h>
16#include <FrameworkManager.h>
17#include <stdio.h>
18#include <tclap/CmdLine.h>
19#include <TargetEthController.h>
20#include <EmulatedController.h>
21
22using namespace TCLAP;
23using namespace std;
24using namespace flair::core;
25using namespace flair::meta;
26using namespace flair::sensor;
27
28string uav_type;
29string dsp_file;
30string log_path;
31bool headless;
32int port;
33string xml_file;
34string name;
35string address;
36
37void parseOptions(int argc, char **argv);
38
39int main(int argc, char *argv[]) {
40 parseOptions(argc, argv);
41
42 FrameworkManager *manager;
43 manager = new FrameworkManager(name);
44 if (!headless) {
45 manager->SetupConnection(address, port);
46 }
47 manager->SetupUserInterface(xml_file);
48 manager->SetupLogger(log_path);
49
50 Uav *drone = CreateUav(name, uav_type);
51 TargetEthController *controller =
52 new TargetEthController("Dualshock3", 20000);
53 // EmulatedController *controller=new EmulatedController(manager,"Emulated
54 // Controller");
55 // controller->AddStep(10000,"Waiting for AHRS
56 // stabilization",0,0.,0.,0.,0.);
57 // controller->AddStep(500,"Takeoff",(uint16_t)EmulatedController::ButtonType::start,0.,0.,0.,0.);
58 // controller->AddStep(3000,"Waiting for flight
59 // stabilization",0,0.,0.,0.,0.);
60 /* controller->AddStep(2000,"fly left",0,-0.3,0.,0.,0.);
61 controller->AddStep(1000,"fly right",0,0.3,0.,0.,0.);*/
62 // controller->AddStep(500,"Land",(uint16_t)EmulatedController::ButtonType::start,0.,0.,0.,0.);
63 // controller->AddStep(3000,"Waiting for landing",0,0.,0.,0.,0.);
64 // controller->AddStep(500,"Stop",(uint16_t)EmulatedController::ButtonType::select,0.,0.,0.,0.);
65 PidUav *app = new PidUav(drone, controller);
66
67 app->Start();
68 app->Join();
69
70 delete manager;
71}
72
73void parseOptions(int argc, char **argv) {
74 try {
75
76 CmdLine cmd("Command description message", ' ', "0.1");
77
78 ValueArg<string> nameArg("n", "name", "uav name", true, "x4", "string");
79 cmd.add(nameArg);
80
81 ValueArg<string> typeArg(
82 "t", "type", "uav type: ardrone2, hds_x4, hds_x8, hds_xufo, hds_simu "
83 "or hds_simux (with x the number of the simulated uav)",
84 true, "hds_x4", "string");
85 cmd.add(typeArg);
86
87 ValueArg<string> xmlArg("x", "xml", "fichier xml", true, "./reglages.xml",
88 "string");
89 cmd.add(xmlArg);
90
91 ValueArg<string> logsArg("l", "logs", "repertoire des logs", true,
92 "/media/ram", "string");
93 cmd.add(logsArg);
94
95 ValueArg<int> portArg("p", "port", "port pour station sol", true, 9000,
96 "int");
97 cmd.add(portArg);
98
99 ValueArg<string> addressArg("a", "address", "addresse station sol", true,
100 "127.0.0.1", "string");
101 cmd.add(addressArg);
102
103 SwitchArg headlessArg("e", "headless", "headless mode", false);
104 cmd.add(headlessArg);
105
106 cmd.parse(argc, argv);
107
108 // Get the value parsed by each arg.
109 uav_type = typeArg.getValue();
110 log_path = logsArg.getValue();
111 port = portArg.getValue();
112 xml_file = xmlArg.getValue();
113 name = nameArg.getValue();
114 address = addressArg.getValue();
115 headless = headlessArg.getValue();
116
117 } catch (ArgException &e) {
118 cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
119 exit(EXIT_FAILURE);
120 }
121}
Note: See TracBrowser for help on using the repository browser.