Skip to content

Commit 14c9b8a

Browse files
committed
Fixed failsafe feature
1 parent 4022461 commit 14c9b8a

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

Drivers/rc_receiver/inc/rcreceiver_datatypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct RCControl{
4141

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

SystemManager/Src/SystemManager.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern "C" {
2323
#include "log_util.h"
2424
}
2525

26+
#define DATANEW_TIMEOUT 75
2627
#define TIMEOUT_CYCLES 250000 // 25k = 1 sec fro testing 10/14/2023 => 250k = 10 sec
2728
#define TIMOUT_MS 10000 // 10 sec
2829

@@ -147,21 +148,17 @@ void SystemManager::systemManagerTask() {
147148

148149
this->rcInputs_ = rcController_->GetRCControl();
149150

150-
// TO-DO: need to implement it using is_Data_New;
151-
// boolean is true if data has not changed since the last cycle
152-
bool is_unchanged{rcInputs_.throttle == prevthrottle && rcInputs_.yaw == prevyaw &&
153-
rcInputs_.roll == prevroll && rcInputs_.pitch == prevpitch};
154-
155-
if (is_unchanged) {
156-
DisconnectionCount += 1; // if its not changed we increment the timeout counter
157-
if (DisconnectionCount > TIMEOUT_CYCLES) { // if timeout has occured
158-
DisconnectionCount =
159-
TIMEOUT_CYCLES + 1; // avoid overflow but keep value above threshold
160-
this->rcInputs_.arm = 0; // failsafe
161-
}
162-
} else {
163-
DisconnectionCount = 0; // if the data has changed we want to reset out counter
164-
}
151+
//Is_Data_new implementation for failsafe
152+
if (!this->rcInputs_.isDataNew){ //if the data is not new
153+
154+
DisconnectionCount += 1; //increment the counter
155+
if (DisconnectionCount > DATANEW_TIMEOUT){ //if the counter is greater than 75, then we can disarm
156+
this->rcInputs_.arm = 0; //disarm the drone for failsafe
157+
}
158+
}
159+
else{
160+
DisconnectionCount = 0; //if the data is new, then we reset to 0.
161+
}
165162

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

0 commit comments

Comments
 (0)