CTRE Phoenix 6 C++ 24.3.0
AutoFeedEnable.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
10#include "frc/DriverStation.h"
11#include "frc/Notifier.h"
12#include "hal/simulation/MockHooks.h"
13#include <mutex>
14
15namespace ctre {
16namespace phoenix6 {
17namespace wpiutils {
18
20public:
22 {
23 static AutoFeedEnable *autoFeedEnable = new AutoFeedEnable{};
24 return *autoFeedEnable;
25 }
26
27private:
28 std::mutex _lck;
29 frc::Notifier _enableNotifier;
30 uint32_t _startCount = 0;
31
33 _enableNotifier{[] {
34 if (frc::DriverStation::IsEnabled()) {
36 }
37 }}
38 {}
39
40public:
41 /**
42 * \brief Starts feeding the enable signal to CTRE actuators.
43 */
44 void Start()
45 {
46 std::lock_guard<std::mutex> lock{_lck};
47 if (_startCount < UINT32_MAX) {
48 if (_startCount++ == 0) {
49 /* start if we were previously at 0 */
50 _enableNotifier.StartPeriodic(20_ms);
51 }
52 }
53 }
54
55 /**
56 * \brief Stops feeding the enable signal to CTRE actuators.
57 * The enable signal will only be stopped when all actuators
58 * have requested to stop the enable signal.
59 */
60 void Stop()
61 {
62 std::lock_guard<std::mutex> lock{_lck};
63 if (_startCount > 0) {
64 if (--_startCount == 0) {
65 /* stop if we are now at 0 */
66 _enableNotifier.Stop();
67 }
68 }
69 }
70};
71
72}
73}
74}
Definition: AutoFeedEnable.hpp:19
void Start()
Starts feeding the enable signal to CTRE actuators.
Definition: AutoFeedEnable.hpp:44
static AutoFeedEnable & GetInstance()
Definition: AutoFeedEnable.hpp:21
void Stop()
Stops feeding the enable signal to CTRE actuators.
Definition: AutoFeedEnable.hpp:60
CTREXPORT void FeedEnable(int timeoutMs)
Feed the robot enable.
Definition: string_util.hpp:15