CTRE Phoenix C++ 5.33.1
StickyFaults.h
Go to the documentation of this file.
1/* Copyright (C) Cross The Road Electronics 2024 */
2#pragma once
3#include <sstream>
4namespace ctre {
5namespace phoenix {
6namespace motorcontrol {
7
8/**
9 * All the sticky faults available to motor controllers
10 */
12 /**
13 * Motor Controller is under 6.5V
14 */
16 /**
17 * Forward limit switch is tripped and device is trying to go forward
18 * Only trips when the device is limited
19 */
21 /**
22 * Reverse limit switch is tripped and device is trying to go reverse
23 * Only trips when the device is limited
24 */
26 /**
27 * Sensor is beyond forward soft limit and device is trying to go forward
28 * Only trips when the device is limited
29 */
31 /**
32 * Sensor is beyond reverse soft limit and device is trying to go reverse
33 * Only trips when the device is limited
34 */
36 /**
37 * Device was powered-on or reset while robot is enabled.
38 * Check your breakers and wiring.
39 */
41 /**
42 * Device's sensor overflowed
43 */
45 /**
46 * Device detects its sensor is out of phase
47 */
49 /**
50 * Not used, @see #ResetDuringEn
51 */
53 /**
54 * Remote Sensor is no longer detected on bus
55 */
57 /**
58 * Device detects an API error
59 */
61 /**
62 * Supply is well above the rated voltage of the hardware. This fault is specific to Brushless.
63 */
65 /**
66 * Supply is rapidly fluctuating and unstable. This fault is specific to Brushless.
67 */
69
70 /**
71 * @return true if any faults are tripped
72 */
73 bool HasAnyFault() const {
74 return UnderVoltage |
84 APIError |
87 }
88 /**
89 * @return Current fault list as a bit field
90 */
91 int ToBitfield() const {
92 int retval = 0;
93 int mask = 1;
94 retval |= UnderVoltage ? mask : 0; mask <<= 1;
95 retval |= ForwardLimitSwitch ? mask : 0; mask <<= 1;
96 retval |= ReverseLimitSwitch ? mask : 0; mask <<= 1;
97 retval |= ForwardSoftLimit ? mask : 0; mask <<= 1;
98 retval |= ReverseSoftLimit ? mask : 0; mask <<= 1;
99 retval |= ResetDuringEn ? mask : 0; mask <<= 1;
100 retval |= SensorOverflow ? mask : 0; mask <<= 1;
101 retval |= SensorOutOfPhase ? mask : 0; mask <<= 1;
102 retval |= HardwareESDReset ? mask : 0; mask <<= 1;
103 retval |= RemoteLossOfSignal ? mask : 0; mask <<= 1;
104 retval |= APIError ? mask : 0; mask <<= 1;
105 retval |= SupplyOverV ? mask : 0; mask <<= 1;
106 retval |= SupplyUnstable ? mask : 0; mask <<= 1;
107 return retval;
108 }
109 /**
110 * Creates fault list with specified bit field of faults
111 *
112 * @param bits bit field of faults to update with
113 */
114 StickyFaults(int bits) {
115 int mask = 1;
116 UnderVoltage = (bits & mask) ? true : false; mask <<= 1;
117 ForwardLimitSwitch = (bits & mask) ? true : false; mask <<= 1;
118 ReverseLimitSwitch = (bits & mask) ? true : false; mask <<= 1;
119 ForwardSoftLimit = (bits & mask) ? true : false; mask <<= 1;
120 ReverseSoftLimit = (bits & mask) ? true : false; mask <<= 1;
121 ResetDuringEn = (bits & mask) ? true : false; mask <<= 1;
122 SensorOverflow = (bits & mask) ? true : false; mask <<= 1;
123 SensorOutOfPhase = (bits & mask) ? true : false; mask <<= 1;
124 HardwareESDReset = (bits & mask) ? true : false; mask <<= 1;
125 RemoteLossOfSignal = (bits & mask) ? true : false; mask <<= 1;
126 APIError = (bits & mask) ? true : false; mask <<= 1;
127 SupplyOverV = (bits & mask) ? true : false; mask <<= 1;
128 SupplyUnstable = (bits & mask) ? true : false; mask <<= 1;
129 }
131 UnderVoltage = false;
132 ForwardLimitSwitch = false;
133 ReverseLimitSwitch = false;
134 ForwardSoftLimit = false;
135 ReverseSoftLimit = false;
136 ResetDuringEn = false;
137 SensorOverflow = false;
138 SensorOutOfPhase = false;
139 HardwareESDReset = false;
140 RemoteLossOfSignal = false;
141 APIError = false;
142 SupplyOverV = false;
143 SupplyUnstable = false;
144 }
145 /**
146 * @return string representation of current faults tripped
147 */
148 std::string ToString() {
149 std::stringstream work;
150 work << " UnderVoltage:" << (UnderVoltage ? "1" : "0");
151 work << " ForwardLimitSwitch:" << (ForwardLimitSwitch ? "1" : "0");
152 work << " ReverseLimitSwitch:" << (ReverseLimitSwitch ? "1" : "0");
153 work << " ForwardSoftLimit:" << (ForwardSoftLimit ? "1" : "0");
154 work << " ReverseSoftLimit:" << (ReverseSoftLimit ? "1" : "0");
155 work << " ResetDuringEn:" << (ResetDuringEn ? "1" : "0");
156 work << " SensorOverflow:" << (SensorOverflow ? "1" : "0");
157 work << " SensorOutOfPhase:" << (SensorOutOfPhase ? "1" : "0");
158 work << " HardwareESDReset:" << (HardwareESDReset ? "1" : "0");
159 work << " RemoteLossOfSignal:" << (RemoteLossOfSignal ? "1" : "0");
160 work << " APIError:" << (APIError ? "1" : "0");
161 work << " SupplyOverV:" << (SupplyOverV ? "1" : "0");
162 work << " SupplyUnstable:" << (SupplyUnstable ? "1" : "0");
163 return work.str();
164 }
165};
166
167} // namespace motorcontrol
168} // namespace phoenix
169} // namespace ctre
namespace ctre
Definition: paramEnum.h:5
All the sticky faults available to motor controllers.
Definition: StickyFaults.h:11
bool ReverseLimitSwitch
Reverse limit switch is tripped and device is trying to go reverse Only trips when the device is limi...
Definition: StickyFaults.h:25
bool RemoteLossOfSignal
Remote Sensor is no longer detected on bus.
Definition: StickyFaults.h:56
bool HardwareESDReset
Not used,.
Definition: StickyFaults.h:52
StickyFaults(int bits)
Creates fault list with specified bit field of faults.
Definition: StickyFaults.h:114
bool ForwardSoftLimit
Sensor is beyond forward soft limit and device is trying to go forward Only trips when the device is ...
Definition: StickyFaults.h:30
bool ForwardLimitSwitch
Forward limit switch is tripped and device is trying to go forward Only trips when the device is limi...
Definition: StickyFaults.h:20
std::string ToString()
Definition: StickyFaults.h:148
bool SensorOutOfPhase
Device detects its sensor is out of phase.
Definition: StickyFaults.h:48
int ToBitfield() const
Definition: StickyFaults.h:91
bool ReverseSoftLimit
Sensor is beyond reverse soft limit and device is trying to go reverse Only trips when the device is ...
Definition: StickyFaults.h:35
bool SensorOverflow
Device's sensor overflowed.
Definition: StickyFaults.h:44
bool HasAnyFault() const
Definition: StickyFaults.h:73
bool UnderVoltage
Motor Controller is under 6.5V.
Definition: StickyFaults.h:15
bool SupplyOverV
Supply is well above the rated voltage of the hardware.
Definition: StickyFaults.h:64
bool SupplyUnstable
Supply is rapidly fluctuating and unstable.
Definition: StickyFaults.h:68
bool APIError
Device detects an API error.
Definition: StickyFaults.h:60
StickyFaults()
Definition: StickyFaults.h:130
bool ResetDuringEn
Device was powered-on or reset while robot is enabled.
Definition: StickyFaults.h:40