Changeset 38 in flair-src for trunk/lib/FlairMeta/src
- Timestamp:
- Jun 23, 2016, 10:15:30 AM (8 years ago)
- Location:
- trunk/lib/FlairMeta/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairMeta/src/MetaDualShock3.cpp
r15 r38 18 18 #include "MetaDualShock3.h" 19 19 #include "MetaDualShock3_impl.h" 20 #include "TargetController.h" 20 21 #include "JoyReference.h" 21 22 #include <Tab.h> … … 30 31 using namespace flair::filter; 31 32 using namespace flair::gui; 33 using namespace flair::sensor; 32 34 33 35 namespace flair { … … 35 37 36 38 MetaDualShock3::MetaDualShock3(FrameworkManager *parent, string name, 37 uint16_t port, uint8_t priority)38 : TargetEthController(parent, name, port, priority) {39 TargetController *controller) 40 : controller(controller),IODevice((IODevice*)controller, name) { 39 41 pimpl_ = new MetaDualShock3_impl(this, name); 40 42 parent->AddDeviceToLog(pimpl_->joy_ref); 41 Start();43 controller->Start(); 42 44 } 43 45 … … 49 51 50 52 void MetaDualShock3::ErrorNotify(void) { 51 TargetEthController::FlashLed(4, 10,0);52 TargetEthController::Rumble(0xff, 20, 0,0);53 controller->FlashLed(4,10,0); 54 controller->Rumble(0xff,20,0,0); 53 55 } 54 56 55 void MetaDualShock3::Rumble(uint8_t left_force, uint8_t left_timeout, 56 uint8_t right_force, uint8_t right_timeout) { 57 TargetEthController::Rumble(left_force, left_timeout, right_force, 58 right_timeout); 57 void MetaDualShock3::Rumble(uint8_t left_force,uint8_t left_timeout,uint8_t right_force,uint8_t right_timeout) { 58 controller->Rumble(left_force,left_timeout,right_force,right_timeout); 59 59 } 60 60 61 61 void MetaDualShock3::SetLedON(unsigned int ledId) { 62 TargetEthController::SetLedOn(ledId);62 controller->SetLedOn(ledId); 63 63 } 64 64 65 65 void MetaDualShock3::SetLedOFF(unsigned int ledId) { 66 TargetEthController::SetLedOff(ledId);66 controller->SetLedOff(ledId); 67 67 } 68 68 69 void MetaDualShock3::FlashLed(unsigned int ledId, uint8_t on_timeout, 70 uint8_t off_timeout) { 71 TargetEthController::FlashLed(ledId, on_timeout, off_timeout); 69 void MetaDualShock3::FlashLed(unsigned int ledId,uint8_t on_timeout,uint8_t off_timeout) { 70 controller->FlashLed(ledId,on_timeout,off_timeout); 72 71 } 73 72 … … 91 90 92 91 float MetaDualShock3::PitchTrim(void) const { 93 return pimpl_->joy_ref->PitchTrim(); 92 return pimpl_->joy_ref->PitchTrim(); 93 } 94 95 void MetaDualShock3::UpdateFrom(const flair::core::io_data *data) { 96 pimpl_->UpdateFrom(data); 94 97 } 95 98 -
trunk/lib/FlairMeta/src/MetaDualShock3.h
r15 r38 14 14 #define METADUALSHOCK3_H 15 15 16 #include <TargetEthController.h> 16 #include <TargetController.h> 17 #include <IODevice.h> 17 18 18 19 namespace flair { … … 35 36 * \brief Classe intégrant la manette MetaDualShock3 36 37 */ 37 class MetaDualShock3 : public sensor::TargetEthController{38 class MetaDualShock3 : public core::IODevice { 38 39 friend class ::MetaDualShock3_impl; 39 40 40 41 public: 41 42 MetaDualShock3(core::FrameworkManager *parent, std::string name, 42 uint16_t port, uint8_t priority);43 sensor::TargetController *controller); 43 44 ~MetaDualShock3(); 44 45 core::AhrsData *GetReferenceOrientation(void) const; … … 66 67 void FlashLed(unsigned int ledId, uint8_t on_timeout, uint8_t off_timeout); 67 68 68 private: 69 class MetaDualShock3_impl *pimpl_; 70 }; 69 private: 70 class MetaDualShock3_impl* pimpl_; 71 void UpdateFrom(const flair::core::io_data *data); 72 sensor::TargetController *controller; 73 }; 71 74 } // end namespace meta 72 75 } // end namespace flair -
trunk/lib/FlairMeta/src/MetaDualShock3_impl.cpp
r15 r38 29 29 using namespace flair::meta; 30 30 31 MetaDualShock3_impl::MetaDualShock3_impl(MetaDualShock3 *self, string name) 32 : IODevice((IODevice *)self, name) { 33 joy_ref = new JoyReference(self->GetTab()->NewRow(), "consignes joy"); 31 MetaDualShock3_impl::MetaDualShock3_impl(MetaDualShock3 *self, string name) { 32 joy_ref=new JoyReference(self->controller->GetTab()->NewRow(),"consignes joy"); 34 33 this->self = self; 35 34 joy_init = false; … … 50 49 51 50 // up 52 if (self-> IsButtonPressed(12)) {51 if (self->controller->IsButtonPressed(12)) { 53 52 if (!wasPitchTrimDownButtonPressed) { 54 53 joy_ref->PitchTrimDown(); … … 60 59 61 60 // down 62 if (self-> IsButtonPressed(13)) {61 if (self->controller->IsButtonPressed(13)) { 63 62 if (!wasPitchTrimUpButtonPressed) { 64 63 joy_ref->PitchTrimUp(); … … 70 69 71 70 // right 72 if (self-> IsButtonPressed(15)) {71 if (self->controller->IsButtonPressed(15)) { 73 72 if (!wasRollTrimUpButtonPressed) { 74 73 joy_ref->RollTrimUp(); … … 80 79 81 80 // left 82 if (self-> IsButtonPressed(14)) {81 if (self->controller->IsButtonPressed(14)) { 83 82 if (!wasRollTrimDownButtonPressed) { 84 83 joy_ref->RollTrimDown(); … … 107 106 108 107 if (!joy_init) { 109 self-> TargetEthController::FlashLed(1, 10, 10);108 self->controller->FlashLed(1, 10, 10); 110 109 joy_init = true; 111 110 } -
trunk/lib/FlairMeta/src/UavStateMachine.cpp
r15 r38 51 51 using namespace flair::meta; 52 52 53 UavStateMachine::UavStateMachine(Uav *inUav, uint16_t ds3Port) 54 : Thread(getFrameworkManager(), "UavStateMachine", 50), uav(inUav), 55 failSafeMode(true), flagConnectionLost(false), flagBatteryLow(false), 56 flagZTrajectoryFinished(false) { 57 altitudeState = AltitudeState_t::Stopped; 58 uav->UseDefaultPlot(); 53 UavStateMachine::UavStateMachine(Uav* inUav,TargetController *controller): 54 Thread(getFrameworkManager(),"UavStateMachine",50), 55 uav(inUav),controller(controller),failSafeMode(true),flagConnectionLost(false),flagBatteryLow(false),flagCriticalSensorLost(false),flagZTrajectoryFinished(false),safeToFly(true){ 56 altitudeState=AltitudeState_t::Stopped; 57 uav->UseDefaultPlot(); 59 58 60 59 Tab *uavTab = new Tab(getFrameworkManager()->GetTabWidget(), "uav", 0); … … 90 89 uZ->AddDeviceToLog(uYaw); 91 90 92 joy = new MetaDualShock3(getFrameworkManager(), "dualshock3", ds3Port, 30);93 uav->GetAhrs()->AddPlot(joy->GetReferenceOrientation(),DataPlot::Blue);91 joy=new MetaDualShock3(getFrameworkManager(),"uav high level controller",controller); 92 uav->GetAhrs()->AddPlot(joy->GetReferenceOrientation(),DataPlot::Blue); 94 93 95 94 altitudeMode = AltitudeMode_t::Manual; … … 124 123 } 125 124 126 const TargetController *UavStateMachine::GetJoystick(void) const { return joy; } 125 const TargetController *UavStateMachine::GetJoystick(void) const { 126 return controller; 127 } 127 128 128 129 const Quaternion &UavStateMachine::GetCurrentQuaternion(void) const { … … 253 254 // The Uav target altitude has reached its landing value (typically 0) 254 255 // but the real Uav altitude may not have reach this value yet because of 255 // command delay. Moreover, it 256 // may never exactly reach this value if the ground is not perfectly 257 // leveled (critical case: there's a 256 // command delay. Moreover, it may never exactly reach this value if the 257 // ground is not perfectly leveled (critical case: there's a 258 258 // deep and narrow hole right in the sensor line of sight). That's why we 259 259 // have a 2 phases landing strategy. … … 424 424 flagZTrajectoryFinished = false; 425 425 426 if (altitudeState == AltitudeState_t::Stopped) { // && 427 // GetBatteryMonitor()->IsBatteryLow()==false) 428 // The uav always takes off in fail safe mode 429 EnterFailSafeMode(); 430 joy->SetLedOFF(4); // DualShock3::led4 431 joy->SetLedOFF(1); // DualShock3::led1 432 joy->Rumble(0x70); 433 joy->SetZRef(0); 426 if((altitudeState==AltitudeState_t::Stopped) && safeToFly) {// && GetBatteryMonitor()->IsBatteryLow()==false) 427 //The uav always takes off in fail safe mode 428 EnterFailSafeMode(); 429 joy->SetLedOFF(4);//DualShock3::led4 430 joy->SetLedOFF(1);//DualShock3::led1 431 joy->Rumble(0x70); 432 joy->SetZRef(0); 434 433 435 434 uZ->SetOffset(); // positionne l'offset de compensation de la gravité à sa … … 458 457 joy->Rumble(0x70); 459 458 460 altitudeTrajectory->StopTraj(); 461 joy->SetZRef(0); 462 altitudeTrajectory->StartTraj( 463 currentAltitude, 464 desiredLandingAltitude->Value()); // shouldn't it be groundAltitude? 465 SignalEvent(Event_t::StartLanding); 466 altitudeState = AltitudeState_t::StartLanding; 467 } else { 468 joy->ErrorNotify(); 469 } 459 altitudeTrajectory->StopTraj(); 460 joy->SetZRef(0); 461 altitudeTrajectory->StartTraj(currentAltitude,desiredLandingAltitude->Value()); //shouldn't it be groundAltitude? 462 SignalEvent(Event_t::StartLanding); 463 altitudeState=AltitudeState_t::StartLanding; 464 } else if (altitudeState==AltitudeState_t::TakingOff) { 465 EmergencyLand(); 466 } else { 467 joy->ErrorNotify(); 468 } 469 } 470 471 void UavStateMachine::EmergencyLand(void) { 472 //Gradually decrease motor speed 473 //Called if landing is required during take off (motors are accelerating but Uav did not actually left the ground yet), or if critical sensors have been lost (attitude is lost) 474 altitudeState=AltitudeState_t::FinishLanding; 475 safeToFly=false; 476 Printf("Emergency landing!\n"); 470 477 } 471 478 … … 494 501 495 502 void UavStateMachine::EmergencyStop(void) { 496 if (altitudeState != AltitudeState_t::Stopped) { 497 StopMotors(); 498 EnterFailSafeMode(); 499 joy->Rumble(0x70); 500 SignalEvent(Event_t::EmergencyStop); 501 } 503 if(altitudeState!=AltitudeState_t::Stopped) { 504 StopMotors(); 505 EnterFailSafeMode(); 506 joy->Rumble(0x70); 507 SignalEvent(Event_t::EmergencyStop); 508 } 509 safeToFly=false; 502 510 } 503 511 … … 534 542 } 535 543 } 536 if ((altitudeState == AltitudeState_t::TakingOff || 537 altitudeState == AltitudeState_t::Stabilized) && 538 uav->GetBatteryMonitor()->IsBatteryLow() && !flagBatteryLow) { 539 flagBatteryLow = true; 540 Printf("Battery Low\n"); 541 EnterFailSafeMode(); 542 Land(); 543 } 544 if((altitudeState==AltitudeState_t::TakingOff || altitudeState==AltitudeState_t::Stabilized) && uav->GetBatteryMonitor()->IsBatteryLow() && !flagBatteryLow) { 545 flagBatteryLow=true; 546 Thread::Err("Low Battery\n"); 547 EnterFailSafeMode(); 548 Land(); 549 } 550 Time now=GetTime(); 551 if ((altitudeState==AltitudeState_t::Stopped) && (now-uav->GetAhrs()->lastUpdate>(Time)100*1000*1000)) { //100ms 552 flagCriticalSensorLost=true; 553 Thread::Err("Critical sensor lost\n"); 554 EnterFailSafeMode(); 555 EmergencyLand(); 556 } 544 557 } 545 558 … … 554 567 static bool isSafeModeButtonPressed = false; 555 568 556 if ( joy->IsButtonPressed(1)) { // select569 if (controller->IsButtonPressed(1)) { // select 557 570 if (!isEmergencyStopButtonPressed) { 558 571 isEmergencyStopButtonPressed = true; … … 563 576 isEmergencyStopButtonPressed = false; 564 577 565 if ( joy->IsButtonPressed(0)) { // start578 if (controller->IsButtonPressed(0)) { // start 566 579 if (!isTakeOffButtonPressed) { 567 580 isTakeOffButtonPressed = true; … … 585 598 // check if l1,l2,r1 and r2 are not pressed 586 599 // to allow a combination in user program 587 if ( joy->IsButtonPressed(5) && !joy->IsButtonPressed(6) &&588 ! joy->IsButtonPressed(7) && !joy->IsButtonPressed(9) &&589 ! joy->IsButtonPressed(10)) {600 if (controller->IsButtonPressed(5) && !controller->IsButtonPressed(6) && 601 !controller->IsButtonPressed(7) && !controller->IsButtonPressed(9) && 602 !controller->IsButtonPressed(10)) { 590 603 if (!isSafeModeButtonPressed) { 591 604 isSafeModeButtonPressed = true; -
trunk/lib/FlairMeta/src/UavStateMachine.h
r15 r38 101 101 }; 102 102 103 UavStateMachine(meta::Uav *uav, uint16_t ds3Port = 20000);104 ~UavStateMachine();103 UavStateMachine(meta::Uav* uav, sensor::TargetController* controller); 104 ~UavStateMachine(); 105 105 106 106 const core::Quaternion &GetCurrentQuaternion(void) const; … … 110 110 const meta::Uav *GetUav(void) const; 111 111 112 void Land(void); 113 void TakeOff(void); 114 void EmergencyStop(void); 115 //! Used to signal an event 116 /*! 117 \param event the event which occured 118 */ 119 virtual void SignalEvent(Event_t event); 112 void Land(void); 113 void EmergencyLand(void); 114 void TakeOff(void); 115 void EmergencyStop(void); 116 //! Used to signal an event 117 /*! 118 \param event the event which occured 119 */ 120 virtual void SignalEvent(Event_t event); 120 121 121 122 virtual const core::AhrsData *GetOrientation(void) const; … … 262 263 263 264 meta::Uav *uav; 265 sensor::TargetController *controller; 264 266 265 267 core::Quaternion currentQuaternion; … … 289 291 bool flagBatteryLow; 290 292 bool flagConnectionLost; 293 bool flagCriticalSensorLost; 291 294 bool flagZTrajectoryFinished; 295 bool safeToFly; 292 296 filter::NestedSat *uRoll, *uPitch; 293 297 filter::Pid *uYaw; -
trunk/lib/FlairMeta/src/unexported/MetaDualShock3_impl.h
r15 r38 14 14 #define METADUALSHOCK3_IMPL_H 15 15 16 #include < IODevice.h>16 #include <MetaDualShock3.h> 17 17 18 18 namespace flair { … … 29 29 * \brief Classe intégrant la manette DualShock3 et les consignes joystick 30 30 */ 31 class MetaDualShock3_impl : public flair::core::IODevice{31 class MetaDualShock3_impl { 32 32 public: 33 33 MetaDualShock3_impl(flair::meta::MetaDualShock3 *self, std::string name); 34 34 ~MetaDualShock3_impl(); 35 35 flair::filter::JoyReference *joy_ref; 36 void UpdateFrom(const flair::core::io_data *data); 36 37 37 38 private: 38 void UpdateFrom(const flair::core::io_data *data);39 39 flair::meta::MetaDualShock3 *self; 40 40 bool joy_init;
Note:
See TracChangeset
for help on using the changeset viewer.