Skip to content

Commit 15b8fb4

Browse files
committed
Update RobotBase to print fewer errors and immediately disable on enabled->disbled transition
1 parent 76ae4ff commit 15b8fb4

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

RobotBase.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "RobotBase.hpp"
2-
#include "ctre/phoenix6/unmanaged/Unmanaged.hpp" // for FeedEnable
2+
#include "ctre/phoenix6/unmanaged/Unmanaged.hpp"
33

44
int RobotBase::Run()
55
{
@@ -17,11 +17,11 @@ int RobotBase::Run()
1717
/* check if we're enabled */
1818
if (IsEnabled()) {
1919
/* enabled */
20-
if (_lastEnabled != 1) {
20+
if (!_lastEnabled.value_or(false)) {
2121
/* just switched, run enabled init */
2222
printf("Robot ENABLED\n");
2323
EnabledInit();
24-
_lastEnabled = 1;
24+
_lastEnabled = true;
2525
}
2626

2727
/* enable for 100 ms */
@@ -30,11 +30,16 @@ int RobotBase::Run()
3030
EnabledPeriodic();
3131
} else {
3232
/* disabled */
33-
if (_lastEnabled != 0) {
33+
if (_lastEnabled.value_or(true)) {
3434
/* just switched, run disabled init */
3535
printf("Robot DISABLED\n");
3636
DisabledInit();
37-
_lastEnabled = 0;
37+
38+
if (_lastEnabled.has_value()) {
39+
/* we were enabled, disable now */
40+
ctre::phoenix::unmanaged::FeedEnable(0);
41+
}
42+
_lastEnabled = false;
3843
}
3944

4045
/* run disabled periodic */

RobotBase.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "units/time.h"
44
#include <chrono>
5+
#include <optional>
56
#include <thread>
67
#include <stdint.h>
78

@@ -24,7 +25,7 @@ class RobotBase {
2425

2526
private:
2627
units::millisecond_t _loopTime = 20_ms;
27-
int _lastEnabled = -1;
28+
std::optional<bool> _lastEnabled;
2829

2930
public:
3031
/**
@@ -49,7 +50,7 @@ class RobotBase {
4950
int Run();
5051

5152
private:
52-
static constexpr auto kErrorTimeMs = 500;
53+
static constexpr auto kErrorTimeMs = 3000;
5354
std::chrono::time_point<std::chrono::steady_clock> _lastErrorTime = std::chrono::steady_clock::now();
5455

5556
/** Reports a loop overrun with debouncing. */

0 commit comments

Comments
 (0)