CTRE Phoenix 6 C++ 24.50.0-alpha-2
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 <mutex>
13
14namespace ctre {
15namespace phoenix6 {
16namespace wpiutils {
17
19public:
21 {
22 static AutoFeedEnable *autoFeedEnable = new AutoFeedEnable{};
23 return *autoFeedEnable;
24 }
25
26private:
27 std::mutex _lck;
28 frc::Notifier _enableNotifier;
29 uint32_t _startCount = 0;
30
32 _enableNotifier{[] {
33 if (frc::DriverStation::IsEnabled()) {
35 }
36 }}
37 {}
38
39public:
40 /**
41 * \brief Starts feeding the enable signal to CTRE actuators.
42 */
43 void Start()
44 {
45 std::lock_guard<std::mutex> lock{_lck};
46 if (_startCount < UINT32_MAX) {
47 if (_startCount++ == 0) {
48 /* start if we were previously at 0 */
49 _enableNotifier.StartPeriodic(20_ms);
50 }
51 }
52 }
53
54 /**
55 * \brief Stops feeding the enable signal to CTRE actuators.
56 * The enable signal will only be stopped when all actuators
57 * have requested to stop the enable signal.
58 */
59 void Stop()
60 {
61 std::lock_guard<std::mutex> lock{_lck};
62 if (_startCount > 0) {
63 if (--_startCount == 0) {
64 /* stop if we are now at 0 */
65 _enableNotifier.Stop();
66 }
67 }
68 }
69};
70
71}
72}
73}
Definition: AutoFeedEnable.hpp:18
void Start()
Starts feeding the enable signal to CTRE actuators.
Definition: AutoFeedEnable.hpp:43
static AutoFeedEnable & GetInstance()
Definition: AutoFeedEnable.hpp:20
void Stop()
Stops feeding the enable signal to CTRE actuators.
Definition: AutoFeedEnable.hpp:59
CTREXPORT void FeedEnable(int timeoutMs)
Feed the robot enable.
Represents the state of one swerve module.
Definition: StatusCodes.h:18