CTRE Phoenix C++ 5.33.1
CANCoderFaults.h
Go to the documentation of this file.
1/* Copyright (C) Cross The Road Electronics 2024 */
2#pragma once
3
4namespace ctre {
5 namespace phoenix {
6 namespace sensors {
7
8 /**
9 * Faults available to CANCoderFaults
10 *
11 * @deprecated This device's Phoenix 5 API is deprecated for removal in the
12 * 2025 season. Users should update to Phoenix 6 firmware and migrate to the
13 * Phoenix 6 API. A migration guide is available at
14 * https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html.
15 *
16 * If the Phoenix 5 API must be used for this device, the device must have 22.X
17 * firmware. This firmware is available in Tuner X after selecting Phoenix 5 in
18 * the firmware year dropdown.
19 */
20 struct [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
21 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
22 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
24 /**
25 * Device detects hardware failure
26 */
28 /**
29 * API error detected. Make sure API and firmware versions are compatible.
30 */
32 /**
33 * Device is under 6.5V
34 */
36 /**
37 * Device was powered-on or reset while robot is enabled.
38 * Check your breakers and wiring.
39 */
41 /**
42 * Magnet strength is too weak to provide reliable results
43 * Make sure CANCoder is close to the magnet being used
44 */
46 /**
47 * @return true if any faults are tripped
48 */
49 bool HasAnyFault() const {
50 return HardwareFault |
51 APIError |
52 UnderVoltage |
53 ResetDuringEn |
54 MagnetTooWeak;
55 }
56 /**
57 * @return Current fault list as a bit field
58 */
59 int ToBitfield() const {
60 int retval = 0;
61 int mask = 1;
62 retval |= HardwareFault ? mask : 0; mask <<= 1;
63 retval |= APIError ? mask : 0; mask <<= 1;
64 retval |= UnderVoltage ? mask : 0; mask <<= 1;
65 retval |= ResetDuringEn ? mask : 0; mask <<= 1;
66 mask <<= 3; /* 3 faults currently unused */
67 retval |= MagnetTooWeak ? mask : 0; mask <<= 1;
68 return retval;
69 }
70 /**
71 * Updates current fault list with specified bit field of faults
72 *
73 * @param bits bit field of faults to update with
74 */
75 void Update(int bits) {
76 int mask = 1;
77 HardwareFault = (bits & mask) ? true : false; mask <<= 1;
78 APIError = (bits & mask) ? true : false; mask <<= 1;
79 UnderVoltage = (bits & mask) ? true : false; mask <<= 1;
80 ResetDuringEn = (bits & mask) ? true : false; mask <<= 1;
81 mask <<= 3; /* 3 faults currently unused */
82 MagnetTooWeak = (bits & mask) ? true : false; mask <<= 1;
83 }
84 /**
85 * Updates current fault list with specified bit field of faults
86 *
87 * @param bits bit field of faults to update with
88 */
89 CANCoderFaults(int bits) {
90 Update(bits);
91 }
93 HardwareFault = false;
94 APIError = false;
95 UnderVoltage = false;
96 ResetDuringEn = false;
97 MagnetTooWeak = false;
98 }
99 };
100
101 } // namespace sensors
102 } // namespace phoenix
103} // namespace ctre
104
namespace ctre
Definition: paramEnum.h:5
Faults available to CANCoderFaults.
Definition: CANCoderFaults.h:23
bool HasAnyFault() const
Definition: CANCoderFaults.h:49
bool ResetDuringEn
Device was powered-on or reset while robot is enabled.
Definition: CANCoderFaults.h:40
bool HardwareFault
Device detects hardware failure.
Definition: CANCoderFaults.h:27
bool APIError
API error detected.
Definition: CANCoderFaults.h:31
bool UnderVoltage
Device is under 6.5V.
Definition: CANCoderFaults.h:35
void Update(int bits)
Updates current fault list with specified bit field of faults.
Definition: CANCoderFaults.h:75
bool MagnetTooWeak
Magnet strength is too weak to provide reliable results Make sure CANCoder is close to the magnet bei...
Definition: CANCoderFaults.h:45
CANCoderFaults(int bits)
Updates current fault list with specified bit field of faults.
Definition: CANCoderFaults.h:89
int ToBitfield() const
Definition: CANCoderFaults.h:59
CANCoderFaults()
Definition: CANCoderFaults.h:92