CTRE Phoenix C++ 5.33.1
Pigeon2_StickyFaults.h
Go to the documentation of this file.
1/* Copyright (C) Cross The Road Electronics 2024 */
2#pragma once
3
4#include <cstdint>
5
6namespace ctre {
7namespace phoenix {
8namespace sensors {
9
10/**
11 * Sticky faults available to Pigeon
12 *
13 * @deprecated This device's Phoenix 5 API is deprecated for removal in the
14 * 2025 season. Users should update to Phoenix 6 firmware and migrate to the
15 * Phoenix 6 API. A migration guide is available at
16 * https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html.
17 *
18 * If the Phoenix 5 API must be used for this device, the device must have 22.X
19 * firmware. This firmware is available in Tuner X after selecting Phoenix 5 in
20 * the firmware year dropdown.
21 */
22struct [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
23 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
24 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
26 /**
27 * Device detects hardware failure
28 */
30 /**
31 * API error detected. Make sure API and firmware versions are compatible.
32 */
34 /**
35 * Device is under 6.5V
36 */
38 /**
39 * Device was powered-on or reset while robot is enabled.
40 * Check your breakers and wiring.
41 */
43 /**
44 * The device rotated at a rate that exceeded its maximum.
45 * Increase the range or slow the rate of rotation.
46 */
48 /**
49 * The device saw an acceleration that exceeded its maximum.
50 * Increase the range or avoid high-g events.
51 */
53 /**
54 * The device saw a magnetic field that exceeded its maximum.
55 * Keep the device far from strong magnetic fields.
56 */
58 /**
59 * The Pigeon saw motion as soon as it booted, and didn't
60 * attempt to self-test its features.
61 * This isn't an issue, but to prevent this don't turn the
62 * robot on while moving it.
63 */
65 /**
66 * The magnetometer failed its self-test.
67 * This is likely due to hardware damage, oftentimes from
68 * exposing the Pigeon to a very large magnetic field.
69 */
71 /**
72 * The gyro failed its self-test.
73 * This is likely due to hardware damage.
74 */
76 /**
77 * The Accelerometer failed its self-test.
78 * This is likely due to hardware damage, oftentimes from
79 * exposing the Pigeon to a very large impact.
80 */
82
83 /**
84 * @return true if any faults are tripped
85 */
86 bool HasAnyFault() const {
87 return HardwareFault |
88 APIError |
89 UnderVoltage |
90 ResetDuringEn |
91 SaturatedRotVelocity |
92 SaturatedAccel |
93 SaturatedMag |
94 BootIntoMotion |
95 MagnetometerFault |
96 GyroFault |
97 AccelFault;
98 }
99 /**
100 * @return Current fault list as a bit field
101 */
102 uint64_t ToBitfield() const {
103 uint64_t commonFaults = 0;
104 commonFaults |= HardwareFault ? 1 : 0; commonFaults <<= 1;
105 commonFaults |= APIError ? 1 : 0; commonFaults <<= 1;
106 commonFaults |= UnderVoltage ? 1 : 0; commonFaults <<= 1;
107 commonFaults |= ResetDuringEn ? 1 : 0; commonFaults <<= 1;
108
109 uint64_t deviceFaults = 0;
110 deviceFaults |= SaturatedRotVelocity ? 1 : 0; deviceFaults <<= 1;
111 deviceFaults |= SaturatedAccel ? 1 : 0; deviceFaults <<= 1;
112 deviceFaults |= SaturatedMag ? 1 : 0; deviceFaults <<= 1;
113 deviceFaults <<= 1; /* Unused bitfield */
114 deviceFaults <<= 1;
115 deviceFaults <<= 1;
116 deviceFaults |= BootIntoMotion ? 1 : 0; deviceFaults <<= 1;
117 deviceFaults |= MagnetometerFault ? 1 : 0; deviceFaults <<= 1;
118 deviceFaults |= GyroFault ? 1 : 0; deviceFaults <<= 1;
119 deviceFaults |= AccelFault ? 1 : 0; deviceFaults <<= 1;
120
121 return commonFaults | (deviceFaults << 30);
122 }
123 /**
124 * Updates current fault list with specified bit field of faults
125 *
126 * @param bits bit field of faults to update with
127 */
128 void Update(uint64_t bits) {
129 uint64_t mask = 1;
130 HardwareFault = (bits & mask) ? true : false; mask <<= 1;
131 APIError = (bits & mask) ? true : false; mask <<= 1;
132 UnderVoltage = (bits & mask) ? true : false; mask <<= 1;
133 ResetDuringEn = (bits & mask) ? true : false; mask <<= 1;
134 mask <<= 30; /* 30 faults currently unused */
135 AccelFault = (bits & mask) ? true : false; mask <<= 1;
136 GyroFault = (bits & mask) ? true : false; mask <<= 1;
137 MagnetometerFault = (bits & mask) ? true : false; mask <<= 1;
138 BootIntoMotion = (bits & mask) ? true : false; mask <<= 1;
139 mask <<= 1;
140 mask <<= 1;
141 mask <<= 1; /* unused bit field */
142 SaturatedMag = (bits & mask) ? true : false; mask <<= 1;
143 SaturatedAccel = (bits & mask) ? true : false; mask <<= 1;
144 SaturatedRotVelocity = (bits & mask) ? true : false; mask <<= 1;
145 }
146 /**
147 * Creates fault list with specified bit field of faults
148 *
149 * @param bits bit field of faults to update with
150 */
151 Pigeon2_StickyFaults(uint64_t bits) {
152 Update(bits);
153 }
155 Update(0); // Default everything to false
156 }
157};
158
159} // sensors
160} // phoenix
161} // ctre
namespace ctre
Definition: paramEnum.h:5
Sticky faults available to Pigeon.
Definition: Pigeon2_StickyFaults.h:25
bool SaturatedMag
The device saw a magnetic field that exceeded its maximum.
Definition: Pigeon2_StickyFaults.h:57
bool MagnetometerFault
The magnetometer failed its self-test.
Definition: Pigeon2_StickyFaults.h:70
Pigeon2_StickyFaults()
Definition: Pigeon2_StickyFaults.h:154
bool BootIntoMotion
The Pigeon saw motion as soon as it booted, and didn't attempt to self-test its features.
Definition: Pigeon2_StickyFaults.h:64
bool HasAnyFault() const
Definition: Pigeon2_StickyFaults.h:86
void Update(uint64_t bits)
Updates current fault list with specified bit field of faults.
Definition: Pigeon2_StickyFaults.h:128
uint64_t ToBitfield() const
Definition: Pigeon2_StickyFaults.h:102
bool SaturatedRotVelocity
The device rotated at a rate that exceeded its maximum.
Definition: Pigeon2_StickyFaults.h:47
bool SaturatedAccel
The device saw an acceleration that exceeded its maximum.
Definition: Pigeon2_StickyFaults.h:52
bool HardwareFault
Device detects hardware failure.
Definition: Pigeon2_StickyFaults.h:29
bool UnderVoltage
Device is under 6.5V.
Definition: Pigeon2_StickyFaults.h:37
bool ResetDuringEn
Device was powered-on or reset while robot is enabled.
Definition: Pigeon2_StickyFaults.h:42
Pigeon2_StickyFaults(uint64_t bits)
Creates fault list with specified bit field of faults.
Definition: Pigeon2_StickyFaults.h:151
bool APIError
API error detected.
Definition: Pigeon2_StickyFaults.h:33
bool GyroFault
The gyro failed its self-test.
Definition: Pigeon2_StickyFaults.h:75
bool AccelFault
The Accelerometer failed its self-test.
Definition: Pigeon2_StickyFaults.h:81