Changeset 105 in flair-src
- Timestamp:
- Oct 18, 2016, 9:13:08 AM (8 years ago)
- Location:
- trunk/demos/PidStandalone
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/demos/PidStandalone/simulator/CMakeLists.txt
r44 r105 3 3 4 4 SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) 5 SET(F RAMEWORK_USE_SIMULATOR TRUE)6 SET(F RAMEWORK_USE_SIMULATOR_GL TRUE)5 SET(FLAIR_USE_SIMULATOR TRUE) 6 SET(FLAIR_USE_SIMULATOR_GL TRUE) 7 7 8 include($ENV{ IGEP_ROOT}/uav_dev/cmake_modules/GlobalCmakeUAV.cmake)9 include(${F RAMEWORK_USE_FILE})8 include($ENV{FLAIR_ROOT}/flair-dev/cmake-modules/GlobalCmakeFlair.cmake) 9 include(${FLAIR_USE_FILE}) 10 10 11 11 SET(SRC_FILES … … 13 13 ) 14 14 15 LINK_DIRECTORIES (16 ${FRAMEWORK_LIBRARY_DIR}17 )18 19 15 INCLUDE_DIRECTORIES( 20 ${F RAMEWORK_INCLUDE_DIR}16 ${FLAIR_INCLUDE_DIR} 21 17 ) 22 18 … … 26 22 ) 27 23 28 TARGET_LINK_LIBRARIES(${PROJECT_NAME}_rt ${F RAMEWORK_LIBRARIES_RT})24 TARGET_LINK_LIBRARIES(${PROJECT_NAME}_rt ${FLAIR_LIBRARIES_RT}) 29 25 30 26 #non real time executable … … 33 29 ) 34 30 35 TARGET_LINK_LIBRARIES(${PROJECT_NAME}_nrt ${F RAMEWORK_LIBRARIES_NRT})31 TARGET_LINK_LIBRARIES(${PROJECT_NAME}_nrt ${FLAIR_LIBRARIES_NRT}) -
trunk/demos/PidStandalone/simulator/src/main.cpp
r44 r105 26 26 using namespace TCLAP; 27 27 using namespace std; 28 using namespace f ramework::simulator;29 using namespace f ramework::sensor;28 using namespace flair::simulator; 29 using namespace flair::sensor; 30 30 31 31 int port; -
trunk/demos/PidStandalone/uav/CMakeLists.txt
r44 r105 3 3 4 4 SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) 5 SET(F RAMEWORK_USE_FILTER TRUE)6 SET(F RAMEWORK_USE_SENSOR_ACTUATOR TRUE)7 SET(F RAMEWORK_USE_META TRUE)8 SET(F RAMEWORK_USE_OPTITRACKTRUE)5 SET(FLAIR_USE_FILTER TRUE) 6 SET(FLAIR_USE_SENSOR_ACTUATOR TRUE) 7 SET(FLAIR_USE_META TRUE) 8 SET(FLAIR_USE_VRPN TRUE) 9 9 10 include($ENV{ IGEP_ROOT}/uav_dev/cmake_modules/GlobalCmakeUAV.cmake)11 include(${F RAMEWORK_USE_FILE})10 include($ENV{FLAIR_ROOT}/flair-dev/cmake-modules/GlobalCmakeFlair.cmake) 11 include(${FLAIR_USE_FILE}) 12 12 13 13 SET(SRC_FILES … … 16 16 ) 17 17 18 LINK_DIRECTORIES (19 ${FRAMEWORK_LIBRARY_DIR}20 )21 22 18 INCLUDE_DIRECTORIES( 23 ${F RAMEWORK_INCLUDE_DIR}19 ${FLAIR_INCLUDE_DIR} 24 20 ) 25 21 … … 29 25 ) 30 26 31 TARGET_LINK_LIBRARIES(${PROJECT_NAME}_rt ${F RAMEWORK_LIBRARIES_RT})27 TARGET_LINK_LIBRARIES(${PROJECT_NAME}_rt ${FLAIR_LIBRARIES_RT}) 32 28 33 29 #non real time executable … … 36 32 ) 37 33 38 TARGET_LINK_LIBRARIES(${PROJECT_NAME}_nrt ${F RAMEWORK_LIBRARIES_NRT})34 TARGET_LINK_LIBRARIES(${PROJECT_NAME}_nrt ${FLAIR_LIBRARIES_NRT}) -
trunk/demos/PidStandalone/uav/src/PidUav.cpp
r44 r105 29 29 30 30 using namespace std; 31 using namespace f ramework::core;32 using namespace f ramework::sensor;33 using namespace f ramework::gui;34 using namespace f ramework::filter;35 using namespace f ramework::meta;31 using namespace flair::core; 32 using namespace flair::sensor; 33 using namespace flair::gui; 34 using namespace flair::filter; 35 using namespace flair::meta; 36 36 37 37 /* … … 41 41 ** =================================================================== 42 42 */ 43 PidUav::PidUav(Uav* uav,TargetController *controller): behaviourMode(BehaviourMode_t::Default),UavStateMachine(uav,controller) { 44 my_uRoll=new Pid(setupLawTab->At(1,1),"custom uRoll"); 45 my_uRoll->UseDefaultPlot(graphLawTab->LastRowLastCol()); 46 my_uPitch=new Pid(setupLawTab->At(1,0),"custom uPitch"); 47 my_uPitch->UseDefaultPlot(graphLawTab->NewRow()); 43 PidUav::PidUav(Uav *uav, TargetController *controller) 44 : behaviourMode(BehaviourMode_t::Default), 45 UavStateMachine(uav, controller) { 46 my_uRoll = new Pid(setupLawTab->At(1, 1), "custom uRoll"); 47 my_uRoll->UseDefaultPlot(graphLawTab->LastRowLastCol()); 48 my_uPitch = new Pid(setupLawTab->At(1, 0), "custom uPitch"); 49 my_uPitch->UseDefaultPlot(graphLawTab->NewRow()); 48 50 } 49 51 50 52 void PidUav::SignalEvent(Event_t event) { 51 52 switch(event) {53 54 //always take off in default mode55 behaviourMode=BehaviourMode_t::Default;56 57 58 //return to default mode59 60 behaviourMode=BehaviourMode_t::Default;61 62 53 UavStateMachine::SignalEvent(event); 54 switch (event) { 55 case Event_t::TakingOff: 56 // always take off in default mode 57 behaviourMode = BehaviourMode_t::Default; 58 break; 59 case Event_t::EnteringFailSafeMode: 60 // return to default mode 61 Thread::Info("Entering failSafe mode\n"); 62 behaviourMode = BehaviourMode_t::Default; 63 break; 64 } 63 65 } 64 66 65 67 bool PidUav::StartCustomMode() { 66 //ask UavStateMachine to enter in custom torques67 68 69 70 71 72 73 74 75 68 // ask UavStateMachine to enter in custom torques 69 if (SetTorqueMode(TorqueMode_t::Custom)) { 70 Thread::Info("CustomTorques: start\n"); 71 my_uPitch->Reset(); 72 my_uRoll->Reset(); 73 return true; 74 } else { 75 Thread::Warn("CustomTorques: could not start\n"); 76 return false; 77 } 76 78 } 77 79 78 80 void PidUav::StartOscillatingMode() { 79 if (behaviourMode==BehaviourMode_t::Default) {80 if (!StartCustomMode()) return;81 }82 behaviourMode=BehaviourMode_t::Oscillating;83 Thread::Info("Entering oscillating mode\n");84 //remove the 'D' effect with a strong 'P'85 81 if (behaviourMode == BehaviourMode_t::Default) { 82 if (!StartCustomMode()) 83 return; 84 } 85 behaviourMode = BehaviourMode_t::Oscillating; 86 Thread::Info("Entering oscillating mode\n"); 87 // remove the 'D' effect with a strong 'P' 86 88 } 87 89 88 90 void PidUav::ExtraCheckJoystick(void) { 89 static bool wasOscillatingModeButtonPressed=false; 90 // controller button R1 enters optical flow mode 91 if(GetJoystick()->IsButtonPressed(9)) { // R1 92 if (!wasOscillatingModeButtonPressed) { 93 wasOscillatingModeButtonPressed=true; 94 if (behaviourMode!=BehaviourMode_t::Oscillating) StartOscillatingMode(); 95 } 96 } else { 97 wasOscillatingModeButtonPressed=false; 91 static bool wasOscillatingModeButtonPressed = false; 92 // controller button R1 enters optical flow mode 93 if (GetJoystick()->IsButtonPressed(9)) { // R1 94 if (!wasOscillatingModeButtonPressed) { 95 wasOscillatingModeButtonPressed = true; 96 if (behaviourMode != BehaviourMode_t::Oscillating) 97 StartOscillatingMode(); 98 98 } 99 } else { 100 wasOscillatingModeButtonPressed = false; 101 } 99 102 } 100 103 101 104 void PidUav::ComputeCustomTorques(Euler &torques) { 102 103 //overload default torques calculation for pitch and roll104 const AhrsData *refOrientation=GetDefaultReferenceOrientation();105 106 107 refOrientation->GetQuaternionAndAngularRates(refQuaternion,refAngularRates);108 Euler refAngles=refQuaternion.ToEuler();105 ComputeDefaultTorques(torques); 106 // overload default torques calculation for pitch and roll 107 const AhrsData *refOrientation = GetDefaultReferenceOrientation(); 108 Quaternion refQuaternion; 109 Vector3D refAngularRates; 110 refOrientation->GetQuaternionAndAngularRates(refQuaternion, refAngularRates); 111 Euler refAngles = refQuaternion.ToEuler(); 109 112 110 const AhrsData *currentOrientation=GetDefaultOrientation(); 111 Quaternion currentQuaternion; 112 Vector3D currentAngularRates; 113 currentOrientation->GetQuaternionAndAngularRates(currentQuaternion,currentAngularRates); 114 Euler currentAngles=currentQuaternion.ToEuler(); 113 const AhrsData *currentOrientation = GetDefaultOrientation(); 114 Quaternion currentQuaternion; 115 Vector3D currentAngularRates; 116 currentOrientation->GetQuaternionAndAngularRates(currentQuaternion, 117 currentAngularRates); 118 Euler currentAngles = currentQuaternion.ToEuler(); 115 119 116 my_uRoll->SetValues(currentAngles.roll-refAngles.roll,currentAngularRates.x); 117 my_uRoll->Update(GetTime()); 118 torques.roll=my_uRoll->Output(); 120 my_uRoll->SetValues(currentAngles.roll - refAngles.roll, 121 currentAngularRates.x); 122 my_uRoll->Update(GetTime()); 123 torques.roll = my_uRoll->Output(); 119 124 120 my_uPitch->SetValues(currentAngles.pitch-refAngles.pitch,currentAngularRates.y); 121 my_uPitch->Update(GetTime()); 122 torques.pitch=my_uPitch->Output(); 125 my_uPitch->SetValues(currentAngles.pitch - refAngles.pitch, 126 currentAngularRates.y); 127 my_uPitch->Update(GetTime()); 128 torques.pitch = my_uPitch->Output(); 123 129 } 124 130 125 PidUav::~PidUav() { 126 } 131 PidUav::~PidUav() {} -
trunk/demos/PidStandalone/uav/src/PidUav.h
r44 r105 17 17 #include <UavStateMachine.h> 18 18 19 namespace framework { 20 namespace core { 21 class FrameworkManager; 22 class cvmatrix; 23 } 24 namespace gui { 25 class GroupBox; 26 class DoubleSpinBox; 27 } 28 namespace filter { 29 class Pid; 30 } 31 namespace sensor { 32 class TargetController; 33 } 19 namespace flair { 20 namespace core { 21 class cvmatrix; 22 } 23 namespace gui { 24 class GroupBox; 25 class DoubleSpinBox; 26 } 27 namespace filter { 28 class Pid; 29 } 30 namespace sensor { 31 class TargetController; 32 } 34 33 } 35 34 36 class PidUav : public framework::meta::UavStateMachine { 37 public: 38 PidUav(framework::meta::Uav* uav, framework::sensor::TargetController *controller); 39 ~PidUav(); 35 class PidUav : public flair::meta::UavStateMachine { 36 public: 37 PidUav(flair::meta::Uav *uav, 38 flair::sensor::TargetController *controller); 39 ~PidUav(); 40 40 41 protected: 42 void SignalEvent(Event_t event); 43 void ExtraCheckJoystick(void); 44 private: 45 void ComputeCustomTorques(framework::core::Euler &torques); 46 bool StartCustomMode(); 47 void StartOscillatingMode(); 48 framework::filter::Pid *my_uPitch,*my_uRoll; 49 enum class BehaviourMode_t { 50 Default, 51 Oscillating 52 }; 53 BehaviourMode_t behaviourMode; 41 protected: 42 void SignalEvent(Event_t event); 43 void ExtraCheckJoystick(void); 44 45 private: 46 void ComputeCustomTorques(flair::core::Euler &torques); 47 bool StartCustomMode(); 48 void StartOscillatingMode(); 49 flair::filter::Pid *my_uPitch, *my_uRoll; 50 enum class BehaviourMode_t { Default, Oscillating }; 51 BehaviourMode_t behaviourMode; 54 52 }; 55 53 -
trunk/demos/PidStandalone/uav/src/main.cpp
r44 r105 22 22 using namespace TCLAP; 23 23 using namespace std; 24 using namespace f ramework::core;25 using namespace f ramework::meta;26 using namespace f ramework::sensor;24 using namespace flair::core; 25 using namespace flair::meta; 26 using namespace flair::sensor; 27 27 28 28 string uav_type; … … 35 35 string address; 36 36 37 void parseOptions(int argc, char **argv);37 void parseOptions(int argc, char **argv); 38 38 39 int main(int argc, char *argv[]) { 40 parseOptions(argc, argv); 39 41 40 int main(int argc, char* argv[]) { 41 parseOptions(argc,argv); 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); 42 49 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 Uav *drone = CreateUav(manager, name, uav_type); 51 TargetEthController *controller = 52 new TargetEthController(manager, "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); 50 66 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); 67 app->Start(); 68 app->Join(); 63 69 64 app->Start(); 65 app->Join(); 66 67 delete manager; 70 delete manager; 68 71 } 69 72 70 void parseOptions(int argc, char **argv) {71 73 void parseOptions(int argc, char **argv) { 74 try { 72 75 73 76 CmdLine cmd("Command description message", ' ', "0.1"); 74 77 75 ValueArg<string> nameArg("n","name","uav name",true,"x4","string");76 cmd.add( nameArg);78 ValueArg<string> nameArg("n", "name", "uav name", true, "x4", "string"); 79 cmd.add(nameArg); 77 80 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 ); 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); 80 86 81 ValueArg<string> xmlArg("x","xml","fichier xml",true,"./reglages.xml","string"); 82 cmd.add( xmlArg ); 87 ValueArg<string> xmlArg("x", "xml", "fichier xml", true, "./reglages.xml", 88 "string"); 89 cmd.add(xmlArg); 83 90 84 ValueArg<string> logsArg("l","logs","repertoire des logs",true,"/media/ram","string"); 85 cmd.add( logsArg ); 91 ValueArg<string> logsArg("l", "logs", "repertoire des logs", true, 92 "/media/ram", "string"); 93 cmd.add(logsArg); 86 94 87 ValueArg<int> portArg("p","port","port pour station sol",true,9000,"int"); 88 cmd.add( portArg ); 95 ValueArg<int> portArg("p", "port", "port pour station sol", true, 9000, 96 "int"); 97 cmd.add(portArg); 89 98 90 ValueArg<string> addressArg("a","address","addresse station sol",true,"127.0.0.1","string"); 91 cmd.add( addressArg ); 99 ValueArg<string> addressArg("a", "address", "addresse station sol", true, 100 "127.0.0.1", "string"); 101 cmd.add(addressArg); 92 102 93 SwitchArg headlessArg("e","headless","headless mode", false);94 cmd.add( headlessArg);103 SwitchArg headlessArg("e", "headless", "headless mode", false); 104 cmd.add(headlessArg); 95 105 96 cmd.parse( argc, argv);106 cmd.parse(argc, argv); 97 107 98 99 uav_type=typeArg.getValue();100 101 port=portArg.getValue();102 103 name=nameArg.getValue();104 address=addressArg.getValue();105 headless=headlessArg.getValue();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(); 106 116 107 } catch (ArgException &e) // catch any exceptions 108 { cerr << "error: " << e.error() << " for arg " << e.argId() << endl; } 117 } catch (ArgException &e) // catch any exceptions 118 { 119 cerr << "error: " << e.error() << " for arg " << e.argId() << endl; 120 } 109 121 }
Note:
See TracChangeset
for help on using the changeset viewer.