11
11
#include " independent_watchdog.h"
12
12
#include " tim.h"
13
13
14
- #define TIMEOUT_CYCLES 250000 // 25k = 1 sec fro testing 10/14/2023 => 250k = 10 sec
14
+ #define DATANEW_TIMEOUT 75
15
15
16
16
static uint32_t DisconnectionCount = 0 ;
17
17
float prevthrottle;
@@ -35,24 +35,17 @@ void SystemManager::flyManually() {
35
35
for (;;){
36
36
this ->rcInputs_ = rcController_->GetRCControl ();
37
37
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
46
40
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
+ }
56
49
57
50
watchdog_.refreshWatchdog (); // always hit the dog
58
51
0 commit comments