ReduxLib C++ 2024.1.1-beta0
Loading...
Searching...
No Matches
CanandcoderFaults.h
1// Copyright (c) Redux Robotics and other contributors.
2// This is open source and can be modified and shared under the 3-clause BSD license.
3
4#pragma once
5#include <cinttypes>
6
8
9/**
10 * A class to hold device faults for the Canandcoder, as returned by Canandcoder::GetActiveFaults and Canandcoder::GetStickyFaults
11 * This class is immutable once constructed.
12 */
14 public:
15 /**
16 * Constructs from a fault field.
17 * @param field the fault bitfield
18 * @param valid whether data is valid or not
19 */
20 constexpr CanandcoderFaults(uint8_t field, bool valid) :
21 powerCycle(field & 0b1),
22 canIDConflict(field & 0b10),
23 canGeneralError(field & 0b100),
24 outOfTemperatureRange(field & 0b1000),
25 hardwareFault(field & 0b10000),
26 magnetOutOfRange(field & 0b100000),
27 underVolt(field & 0b1000000),
28 faultsValid(valid) {};
29
30 /**
31 * The power cycle fault flag, which is set to true when the encoder first boots.
32 * Clearing sticky faults and then checking this flag can be used to determine if the encoder rebooted.
33 */
35
36 /**
37 * The CAN ID conflict flag, which is set to true if there is a CAN id conflict.
38 * In practice, you should physically inspect the encoder to ensure it's not flashing blue.
39 */
41
42 /**
43 * The CAN general error flag, which will raise if the encoder cannot RX packets reliably.
44 * This is usually due to wiring issues, such as a shorted CAN bus
45 */
47
48 /**
49 * The temperature range flag, which will raise if the encoder is not between 0-70 degrees Celsius.
50 * This may be of concern if the encoder is near very active motors.
51 */
53
54 /**
55 * The hardware fault flag, which will raise if a hardware issue is detected.
56 * Generally will raise if the device's controller cannot read the physical sensor itself.
57 */
59
60 /**
61 * The magnet out of range flag, which will raise if the measured shaft's magnet is not detected.
62 * This will match the encoder's LED shining red in normal operation.
63 */
65
66 /**
67 * The undervolt flag, which will raise if the encoder is experiencing brownout conditions.
68 */
70
71 /**
72 * Flag if any faults data has been received at all from the encoder. This will be false until the first status frame arrives
73 * after either the start of robot code or after ClearStickyFaults is called.
74 */
76};
77}
Definition: CanandcoderFaults.h:13
constexpr CanandcoderFaults(uint8_t field, bool valid)
Definition: CanandcoderFaults.h:20
bool magnetOutOfRange
Definition: CanandcoderFaults.h:64
bool hardwareFault
Definition: CanandcoderFaults.h:58
bool outOfTemperatureRange
Definition: CanandcoderFaults.h:52
bool underVolt
Definition: CanandcoderFaults.h:69
bool canGeneralError
Definition: CanandcoderFaults.h:46
bool faultsValid
Definition: CanandcoderFaults.h:75
bool powerCycle
Definition: CanandcoderFaults.h:34
bool canIDConflict
Definition: CanandcoderFaults.h:40
Definition: CanandcoderStatus.h:8