ReduxLib C++ 2024.3.2
Loading...
Searching...
No Matches
CanandmagFaults.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 Canandmag, as returned by Canandmag::GetActiveFaults and Canandmag::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 CanandmagFaults(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: CanandmagFaults.h:13
constexpr CanandmagFaults(uint8_t field, bool valid)
Definition: CanandmagFaults.h:20
bool faultsValid
Definition: CanandmagFaults.h:75
bool powerCycle
Definition: CanandmagFaults.h:34
bool outOfTemperatureRange
Definition: CanandmagFaults.h:52
bool canGeneralError
Definition: CanandmagFaults.h:46
bool magnetOutOfRange
Definition: CanandmagFaults.h:64
bool canIdConflict
Definition: CanandmagFaults.h:40
bool hardwareFault
Definition: CanandmagFaults.h:58
bool underVolt
Definition: CanandmagFaults.h:69
Definition: CanandmagSettings.h:12