Skip to content

Commit

Permalink
Fixed failsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzayrhuss353 committed Nov 22, 2024
1 parent 289e79d commit 856a6f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
1 change: 1 addition & 0 deletions Drivers/rc_receiver/Inc/rcreceiver_datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct RCControl{

RCControl operator=(const RCControl& other){
std::copy(other.ControlSignals, other.ControlSignals + SBUS_INPUT_CHANNELS, this->ControlSignals);
this->isDataNew = other.isDataNew; // Add this line to copy the isDataNew flag
return *this;
}

Expand Down
29 changes: 11 additions & 18 deletions SystemManager/Src/SystemManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "independent_watchdog.h"
#include "tim.h"

#define TIMEOUT_CYCLES 250000 // 25k = 1 sec fro testing 10/14/2023 => 250k = 10 sec
#define DATANEW_TIMEOUT 75

static uint32_t DisconnectionCount = 0;
float prevthrottle;
Expand All @@ -35,24 +35,17 @@ void SystemManager::flyManually() {
for(;;){
this->rcInputs_ = rcController_->GetRCControl();

//TO-DO: need to implement it using is_Data_New;
// boolean is true if data has not changed since the last cycle
bool is_unchanged{
rcInputs_.throttle == prevthrottle &&
rcInputs_.yaw == prevyaw &&
rcInputs_.roll == prevroll &&
rcInputs_.pitch == prevpitch
};
//Is_Data_new implementation for failsafe
if (!this->rcInputs_.isDataNew){ //if the data is not new

if (is_unchanged) {
DisconnectionCount += 1; // if its not changed we increment the timeout counter
if (DisconnectionCount > TIMEOUT_CYCLES) { // if timeout has occured
DisconnectionCount = TIMEOUT_CYCLES+1; // avoid overflow but keep value above threshold
this->rcInputs_.arm = 0; // failsafe
}
} else {
DisconnectionCount = 0; //if the data has changed we want to reset out counter
}
DisconnectionCount += 1; //increment the counter
if (DisconnectionCount > DATANEW_TIMEOUT){ //if the counter is greater than 75, then we can disarm
this->rcInputs_.arm = 0; //disarm the drone for failsafe
}
}
else{
DisconnectionCount = 0; //if the data is new, then we reset to 0.
}

watchdog_.refreshWatchdog(); // always hit the dog

Expand Down

0 comments on commit 856a6f2

Please sign in to comment.