Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit 856a6f2

Browse files
committed
Fixed failsafe
1 parent 289e79d commit 856a6f2

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
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: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "independent_watchdog.h"
1212
#include "tim.h"
1313

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

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

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

47-
if (is_unchanged) {
48-
DisconnectionCount += 1; // if its not changed we increment the timeout counter
49-
if (DisconnectionCount > TIMEOUT_CYCLES) { // if timeout has occured
50-
DisconnectionCount = TIMEOUT_CYCLES+1; // avoid overflow but keep value above threshold
51-
this->rcInputs_.arm = 0; // failsafe
52-
}
53-
} else {
54-
DisconnectionCount = 0; //if the data has changed we want to reset out counter
55-
}
41+
DisconnectionCount += 1; //increment the counter
42+
if (DisconnectionCount > DATANEW_TIMEOUT){ //if the counter is greater than 75, then we can disarm
43+
this->rcInputs_.arm = 0; //disarm the drone for failsafe
44+
}
45+
}
46+
else{
47+
DisconnectionCount = 0; //if the data is new, then we reset to 0.
48+
}
5649

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

0 commit comments

Comments
 (0)