[44] | 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 |
|
---|
| 22 | using namespace TCLAP;
|
---|
| 23 | using namespace std;
|
---|
| 24 | using namespace framework::core;
|
---|
| 25 | using namespace framework::meta;
|
---|
| 26 | using namespace framework::sensor;
|
---|
| 27 |
|
---|
| 28 | string uav_type;
|
---|
| 29 | string dsp_file;
|
---|
| 30 | string log_path;
|
---|
| 31 | bool headless;
|
---|
| 32 | int port;
|
---|
| 33 | string xml_file;
|
---|
| 34 | string name;
|
---|
| 35 | string address;
|
---|
| 36 |
|
---|
| 37 | void parseOptions(int argc, char** argv);
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | int main(int argc, char* argv[]) {
|
---|
| 41 | parseOptions(argc,argv);
|
---|
| 42 |
|
---|
| 43 | FrameworkManager *manager;
|
---|
| 44 | manager= new FrameworkManager(name);
|
---|
| 45 | if (!headless) {
|
---|
| 46 | manager->SetupConnection(address,port);
|
---|
| 47 | }
|
---|
| 48 | manager->SetupUserInterface(xml_file);
|
---|
| 49 | manager->SetupLogger(log_path);
|
---|
| 50 |
|
---|
| 51 | Uav* drone=CreateUav(manager,name,uav_type);
|
---|
| 52 | TargetEthController *controller=new TargetEthController(manager,"Dualshock3",20000);
|
---|
| 53 | //EmulatedController *controller=new EmulatedController(manager,"Emulated Controller");
|
---|
| 54 | // controller->AddStep(10000,"Waiting for AHRS stabilization",0,0.,0.,0.,0.);
|
---|
| 55 | // controller->AddStep(500,"Takeoff",(uint16_t)EmulatedController::ButtonType::start,0.,0.,0.,0.);
|
---|
| 56 | // controller->AddStep(3000,"Waiting for flight stabilization",0,0.,0.,0.,0.);
|
---|
| 57 | /* controller->AddStep(2000,"fly left",0,-0.3,0.,0.,0.);
|
---|
| 58 | controller->AddStep(1000,"fly right",0,0.3,0.,0.,0.);*/
|
---|
| 59 | // controller->AddStep(500,"Land",(uint16_t)EmulatedController::ButtonType::start,0.,0.,0.,0.);
|
---|
| 60 | // controller->AddStep(3000,"Waiting for landing",0,0.,0.,0.,0.);
|
---|
| 61 | // controller->AddStep(500,"Stop",(uint16_t)EmulatedController::ButtonType::select,0.,0.,0.,0.);
|
---|
| 62 | PidUav* app=new PidUav(drone,controller);
|
---|
| 63 |
|
---|
| 64 | app->Start();
|
---|
| 65 | app->Join();
|
---|
| 66 |
|
---|
| 67 | delete manager;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | void parseOptions(int argc, char** argv) {
|
---|
| 71 | try {
|
---|
| 72 |
|
---|
| 73 | CmdLine cmd("Command description message", ' ', "0.1");
|
---|
| 74 |
|
---|
| 75 | ValueArg<string> nameArg("n","name","uav name",true,"x4","string");
|
---|
| 76 | cmd.add( nameArg );
|
---|
| 77 |
|
---|
| 78 | ValueArg<string> typeArg("t","type","uav type: ardrone2, hds_x4, hds_x8, hds_xufo, hds_simu or hds_simux (with x the number of the simulated uav)",true,"hds_x4","string");
|
---|
| 79 | cmd.add( typeArg );
|
---|
| 80 |
|
---|
| 81 | ValueArg<string> xmlArg("x","xml","fichier xml",true,"./reglages.xml","string");
|
---|
| 82 | cmd.add( xmlArg );
|
---|
| 83 |
|
---|
| 84 | ValueArg<string> logsArg("l","logs","repertoire des logs",true,"/media/ram","string");
|
---|
| 85 | cmd.add( logsArg );
|
---|
| 86 |
|
---|
| 87 | ValueArg<int> portArg("p","port","port pour station sol",true,9000,"int");
|
---|
| 88 | cmd.add( portArg );
|
---|
| 89 |
|
---|
| 90 | ValueArg<string> addressArg("a","address","addresse station sol",true,"127.0.0.1","string");
|
---|
| 91 | cmd.add( addressArg );
|
---|
| 92 |
|
---|
| 93 | SwitchArg headlessArg("e","headless","headless mode", false);
|
---|
| 94 | cmd.add( headlessArg );
|
---|
| 95 |
|
---|
| 96 | cmd.parse( argc, argv );
|
---|
| 97 |
|
---|
| 98 | // Get the value parsed by each arg.
|
---|
| 99 | uav_type=typeArg.getValue();
|
---|
| 100 | log_path = logsArg.getValue();
|
---|
| 101 | port=portArg.getValue();
|
---|
| 102 | xml_file = xmlArg.getValue();
|
---|
| 103 | name=nameArg.getValue();
|
---|
| 104 | address=addressArg.getValue();
|
---|
| 105 | headless=headlessArg.getValue();
|
---|
| 106 |
|
---|
| 107 | } catch (ArgException &e) // catch any exceptions
|
---|
| 108 | { cerr << "error: " << e.error() << " for arg " << e.argId() << endl; }
|
---|
| 109 | }
|
---|