CTRE Phoenix C++ 5.33.1
Faults.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 faults available to motor controllers
10 */
11struct Faults {
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 detects hardware failure
38 */
40 /**
41 * Device was powered-on or reset while robot is enabled.
42 * Check your breakers and wiring.
43 */
45 /**
46 * Device's sensor overflowed
47 */
49 /**
50 * Device detects its sensor is out of phase
51 */
53 /**
54 * Not used, @see ResetDuringEn
55 */
57 /**
58 * Remote Sensor is no longer detected on bus
59 */
61 /**
62 * API error detected. Make sure API and firmware versions are compatible.
63 */
65 /**
66 * Supply is well above the rated voltage of the hardware. This fault is specific to Brushless.
67 */
69 /**
70 * Supply is rapidly fluctuating and unstable. This fault is specific to Brushless.
71 */
73
74 /**
75 * @return true if any faults are tripped
76 */
77 bool HasAnyFault() const {
78 return UnderVoltage |
89 APIError |
92 }
93 /**
94 * @return Current fault list as a bit field
95 */
96 int ToBitfield() const {
97 int retval = 0;
98 int mask = 1;
99 retval |= UnderVoltage ? mask : 0; mask <<= 1;
100 retval |= ForwardLimitSwitch ? mask : 0; mask <<= 1;
101 retval |= ReverseLimitSwitch ? mask : 0; mask <<= 1;
102 retval |= ForwardSoftLimit ? mask : 0; mask <<= 1;
103 retval |= ReverseSoftLimit ? mask : 0; mask <<= 1;
104 retval |= HardwareFailure ? mask : 0; mask <<= 1;
105 retval |= ResetDuringEn ? mask : 0; mask <<= 1;
106 retval |= SensorOverflow ? mask : 0; mask <<= 1;
107 retval |= SensorOutOfPhase ? mask : 0; mask <<= 1;
108 retval |= HardwareESDReset ? mask : 0; mask <<= 1;
109 retval |= RemoteLossOfSignal ? mask : 0; mask <<= 1;
110 retval |= APIError ? mask : 0; mask <<= 1;
111 retval |= SupplyOverV ? mask : 0; mask <<= 1;
112 retval |= SupplyUnstable ? mask : 0; mask <<= 1;
113 return retval;
114 }
115 /**
116 * Creates fault list with specified bit field of faults
117 *
118 * @param bits bit field of faults to update with
119 */
120 Faults(int bits) {
121 int mask = 1;
122 UnderVoltage = (bits & mask) ? true : false; mask <<= 1;
123 ForwardLimitSwitch = (bits & mask) ? true : false; mask <<= 1;
124 ReverseLimitSwitch = (bits & mask) ? true : false; mask <<= 1;
125 ForwardSoftLimit = (bits & mask) ? true : false; mask <<= 1;
126 ReverseSoftLimit = (bits & mask) ? true : false; mask <<= 1;
127 HardwareFailure = (bits & mask) ? true : false; mask <<= 1;
128 ResetDuringEn = (bits & mask) ? true : false; mask <<= 1;
129 SensorOverflow = (bits & mask) ? true : false; mask <<= 1;
130 SensorOutOfPhase = (bits & mask) ? true : false; mask <<= 1;
131 HardwareESDReset = (bits & mask) ? true : false; mask <<= 1;
132 RemoteLossOfSignal = (bits & mask) ? true : false; mask <<= 1;
133 APIError = (bits & mask) ? true : false; mask <<= 1;
134 SupplyOverV = (bits & mask) ? true : false; mask <<= 1;
135 SupplyUnstable = (bits & mask) ? true : false; mask <<= 1;
136 }
138 UnderVoltage = false;
139 ForwardLimitSwitch = false;
140 ReverseLimitSwitch = false;
141 ForwardSoftLimit = false;
142 ReverseSoftLimit = false;
143 HardwareFailure =false;
144 ResetDuringEn = false;
145 SensorOverflow = false;
146 SensorOutOfPhase = false;
147 HardwareESDReset = false;
148 RemoteLossOfSignal = false;
149 APIError = false;
150 SupplyOverV = false;
151 SupplyUnstable = false;
152 }
153 /**
154 * @return string representation of current faults tripped
155 */
156 std::string ToString() {
157 std::stringstream work;
158 work << " UnderVoltage:" << (UnderVoltage ? "1" : "0");
159 work << " ForwardLimitSwitch:" << (ForwardLimitSwitch ? "1" : "0");
160 work << " ReverseLimitSwitch:" << (ReverseLimitSwitch ? "1" : "0");
161 work << " ForwardSoftLimit:" << (ForwardSoftLimit ? "1" : "0");
162 work << " ReverseSoftLimit:" << (ReverseSoftLimit ? "1" : "0");
163 work << " HardwareFailure:" << (HardwareFailure ? "1" : "0");
164 work << " ResetDuringEn:" << (ResetDuringEn ? "1" : "0");
165 work << " SensorOverflow:" << (SensorOverflow ? "1" : "0");
166 work << " SensorOutOfPhase:" << (SensorOutOfPhase ? "1" : "0");
167 work << " HardwareESDReset:" << (HardwareESDReset ? "1" : "0");
168 work << " RemoteLossOfSignal:" << (RemoteLossOfSignal ? "1" : "0");
169 work << " APIError:" << (APIError ? "1" : "0");
170 work << " SupplyOverV:" << (SupplyOverV ? "1" : "0");
171 work << " SupplyUnstable:" << (SupplyUnstable ? "1" : "0");
172 return work.str();
173 }
174};
175
176} // namespace motorcontrol
177} // namespace phoenix
178} // namespace ctre
namespace ctre
Definition: paramEnum.h:5
All the faults available to motor controllers.
Definition: Faults.h:11
int ToBitfield() const
Definition: Faults.h:96
bool ForwardLimitSwitch
Forward limit switch is tripped and device is trying to go forward Only trips when the device is limi...
Definition: Faults.h:20
bool HardwareESDReset
Not used,.
Definition: Faults.h:56
bool ForwardSoftLimit
Sensor is beyond forward soft limit and device is trying to go forward Only trips when the device is ...
Definition: Faults.h:30
Faults()
Definition: Faults.h:137
std::string ToString()
Definition: Faults.h:156
bool ReverseSoftLimit
Sensor is beyond reverse soft limit and device is trying to go reverse Only trips when the device is ...
Definition: Faults.h:35
bool SensorOverflow
Device's sensor overflowed.
Definition: Faults.h:48
bool SensorOutOfPhase
Device detects its sensor is out of phase.
Definition: Faults.h:52
Faults(int bits)
Creates fault list with specified bit field of faults.
Definition: Faults.h:120
bool HasAnyFault() const
Definition: Faults.h:77
bool ResetDuringEn
Device was powered-on or reset while robot is enabled.
Definition: Faults.h:44
bool RemoteLossOfSignal
Remote Sensor is no longer detected on bus.
Definition: Faults.h:60
bool HardwareFailure
Device detects hardware failure.
Definition: Faults.h:39
bool SupplyOverV
Supply is well above the rated voltage of the hardware.
Definition: Faults.h:68
bool UnderVoltage
Motor Controller is under 6.5V.
Definition: Faults.h:15
bool ReverseLimitSwitch
Reverse limit switch is tripped and device is trying to go reverse Only trips when the device is limi...
Definition: Faults.h:25
bool SupplyUnstable
Supply is rapidly fluctuating and unstable.
Definition: Faults.h:72
bool APIError
API error detected.
Definition: Faults.h:64