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