CTRE Phoenix 6 C++ 26.50.0-alpha-1
Loading...
Searching...
No Matches
MagnetSensorConfigs.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
11#include <wpi/units/angle.hpp>
12
13namespace ctre {
14namespace phoenix6 {
15
16
17namespace configs {
18
19/**
20 * \brief Configs that affect the magnet sensor and how to interpret
21 * it.
22 *
23 * \details Includes sensor direction, the sensor discontinuity point,
24 * and the magnet offset.
25 */
27public:
28 constexpr MagnetSensorConfigs() = default;
29
30 /**
31 * \brief Direction of the sensor to determine positive rotation, as
32 * seen facing the LED side of the CANcoder.
33 *
34 * - Default Value: signals#SensorDirectionValue#CounterClockwise_Positive
35 */
37 /**
38 * \brief This offset is added to the reported position, allowing the
39 * application to trim the zero position. When set to the default
40 * value of zero, position reports zero when magnet north pole aligns
41 * with the LED.
42 *
43 * - Minimum Value: -1
44 * - Maximum Value: 1
45 * - Default Value: 0
46 * - Units: rotations
47 */
48 wpi::units::turn_t MagnetOffset = 0_tr;
49 /**
50 * \brief The positive discontinuity point of the absolute sensor in
51 * rotations. This determines the point at which the absolute sensor
52 * wraps around, keeping the absolute position (after offset) in the
53 * range [x-1, x).
54 *
55 * - Setting this to 1 makes the absolute position unsigned [0, 1)
56 * - Setting this to 0.5 makes the absolute position signed [-0.5,
57 * 0.5)
58 * - Setting this to 0 makes the absolute position always negative
59 * [-1, 0)
60 *
61 * Many rotational mechanisms such as arms have a region of motion
62 * that is unreachable. This should be set to the center of that
63 * region of motion, in non-negative rotations. This affects the
64 * position of the device at bootup.
65 *
66 * \details For example, consider an arm which can travel from -0.2 to
67 * 0.6 rotations with a little leeway, where 0 is horizontally
68 * forward. Since -0.2 rotations has the same absolute position as 0.8
69 * rotations, we can say that the arm typically does not travel in the
70 * range (0.6, 0.8) rotations. As a result, the discontinuity point
71 * would be the center of that range, which is 0.7 rotations. This
72 * results in an absolute sensor range of [-0.3, 0.7) rotations.
73 *
74 * Given a total range of motion less than 1 rotation, users can
75 * calculate the discontinuity point using mean(lowerLimit,
76 * upperLimit) + 0.5. If that results in a value outside the range [0,
77 * 1], either cap the value to [0, 1], or add/subtract 1.0 rotation
78 * from your lower and upper limits of motion.
79 *
80 * On a Talon motor controller, this is only supported when using the
81 * PulseWidth sensor source.
82 *
83 * - Minimum Value: 0.0
84 * - Maximum Value: 1.0
85 * - Default Value: 0.5
86 * - Units: rotations
87 */
88 wpi::units::turn_t AbsoluteSensorDiscontinuityPoint = 0.5_tr;
89
90 /**
91 * \brief Modifies this configuration's SensorDirection parameter and returns itself for
92 * method-chaining and easier to use config API.
93 *
94 * Direction of the sensor to determine positive rotation, as seen
95 * facing the LED side of the CANcoder.
96 *
97 * - Default Value: signals#SensorDirectionValue#CounterClockwise_Positive
98 *
99 * \param newSensorDirection Parameter to modify
100 * \returns Itself
101 */
103 {
104 SensorDirection = std::move(newSensorDirection);
105 return *this;
106 }
107
108 /**
109 * \brief Modifies this configuration's MagnetOffset parameter and returns itself for
110 * method-chaining and easier to use config API.
111 *
112 * This offset is added to the reported position, allowing the
113 * application to trim the zero position. When set to the default
114 * value of zero, position reports zero when magnet north pole aligns
115 * with the LED.
116 *
117 * - Minimum Value: -1
118 * - Maximum Value: 1
119 * - Default Value: 0
120 * - Units: rotations
121 *
122 * \param newMagnetOffset Parameter to modify
123 * \returns Itself
124 */
125 constexpr MagnetSensorConfigs &WithMagnetOffset(wpi::units::turn_t newMagnetOffset)
126 {
127 MagnetOffset = std::move(newMagnetOffset);
128 return *this;
129 }
130
131 /**
132 * \brief Modifies this configuration's AbsoluteSensorDiscontinuityPoint parameter and returns itself for
133 * method-chaining and easier to use config API.
134 *
135 * The positive discontinuity point of the absolute sensor in
136 * rotations. This determines the point at which the absolute sensor
137 * wraps around, keeping the absolute position (after offset) in the
138 * range [x-1, x).
139 *
140 * - Setting this to 1 makes the absolute position unsigned [0, 1)
141 * - Setting this to 0.5 makes the absolute position signed [-0.5,
142 * 0.5)
143 * - Setting this to 0 makes the absolute position always negative
144 * [-1, 0)
145 *
146 * Many rotational mechanisms such as arms have a region of motion
147 * that is unreachable. This should be set to the center of that
148 * region of motion, in non-negative rotations. This affects the
149 * position of the device at bootup.
150 *
151 * \details For example, consider an arm which can travel from -0.2 to
152 * 0.6 rotations with a little leeway, where 0 is horizontally
153 * forward. Since -0.2 rotations has the same absolute position as 0.8
154 * rotations, we can say that the arm typically does not travel in the
155 * range (0.6, 0.8) rotations. As a result, the discontinuity point
156 * would be the center of that range, which is 0.7 rotations. This
157 * results in an absolute sensor range of [-0.3, 0.7) rotations.
158 *
159 * Given a total range of motion less than 1 rotation, users can
160 * calculate the discontinuity point using mean(lowerLimit,
161 * upperLimit) + 0.5. If that results in a value outside the range [0,
162 * 1], either cap the value to [0, 1], or add/subtract 1.0 rotation
163 * from your lower and upper limits of motion.
164 *
165 * On a Talon motor controller, this is only supported when using the
166 * PulseWidth sensor source.
167 *
168 * - Minimum Value: 0.0
169 * - Maximum Value: 1.0
170 * - Default Value: 0.5
171 * - Units: rotations
172 *
173 * \param newAbsoluteSensorDiscontinuityPoint Parameter to modify
174 * \returns Itself
175 */
176 constexpr MagnetSensorConfigs &WithAbsoluteSensorDiscontinuityPoint(wpi::units::turn_t newAbsoluteSensorDiscontinuityPoint)
177 {
178 AbsoluteSensorDiscontinuityPoint = std::move(newAbsoluteSensorDiscontinuityPoint);
179 return *this;
180 }
181
182
183
184 std::string ToString() const override;
185
186 std::string Serialize() const final;
187 ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final;
188};
189
190}
191}
192}
ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final
wpi::units::turn_t MagnetOffset
This offset is added to the reported position, allowing the application to trim the zero position.
Definition MagnetSensorConfigs.hpp:48
constexpr MagnetSensorConfigs & WithAbsoluteSensorDiscontinuityPoint(wpi::units::turn_t newAbsoluteSensorDiscontinuityPoint)
Modifies this configuration's AbsoluteSensorDiscontinuityPoint parameter and returns itself for metho...
Definition MagnetSensorConfigs.hpp:176
wpi::units::turn_t AbsoluteSensorDiscontinuityPoint
The positive discontinuity point of the absolute sensor in rotations.
Definition MagnetSensorConfigs.hpp:88
constexpr MagnetSensorConfigs & WithSensorDirection(signals::SensorDirectionValue newSensorDirection)
Modifies this configuration's SensorDirection parameter and returns itself for method-chaining and ea...
Definition MagnetSensorConfigs.hpp:102
constexpr MagnetSensorConfigs & WithMagnetOffset(wpi::units::turn_t newMagnetOffset)
Modifies this configuration's MagnetOffset parameter and returns itself for method-chaining and easie...
Definition MagnetSensorConfigs.hpp:125
std::string ToString() const override
signals::SensorDirectionValue SensorDirection
Direction of the sensor to determine positive rotation, as seen facing the LED side of the CANcoder.
Definition MagnetSensorConfigs.hpp:36
Definition Configuration.hpp:17
Definition ExternalFeedbackConfigs.hpp:21
Definition ExternalFeedbackConfigs.hpp:16
Definition FrcUsageReport.hpp:12
Definition motor_constants.h:14
Direction of the sensor to determine positive rotation, as seen facing the LED side of the CANcoder.
Definition SpnEnums.hpp:195
static constexpr int CounterClockwise_Positive
Counter-clockwise motion reports positive rotation.
Definition SpnEnums.hpp:201