File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#include " RobotBase.hpp"
2- #include " ctre/phoenix6/unmanaged/Unmanaged.hpp" // for FeedEnable
2+ #include " ctre/phoenix6/unmanaged/Unmanaged.hpp"
33
44int 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 */
Original file line number Diff line number Diff line change 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
2526private:
2627 units::millisecond_t _loopTime = 20_ms;
27- int _lastEnabled = - 1 ;
28+ std::optional< bool > _lastEnabled;
2829
2930public:
3031 /* *
@@ -49,7 +50,7 @@ class RobotBase {
4950 int Run ();
5051
5152private:
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. */
You can’t perform that action at this time.
0 commit comments