CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
PWM2Configs.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
10#include <units/angle.h>
11
12namespace ctre {
13namespace phoenix6 {
14
15
16namespace configs {
17
18/**
19 * \brief Configs related to the CANdi™ branded device's PWM interface
20 * on the Signal 2 input (S2IN)
21 *
22 * \details All the configs related to the PWM interface for the
23 * CANdi™ branded device on S1, including absolute sensor
24 * offset, absolute sensor discontinuity point and sensor
25 * direction.
26 */
28public:
29 constexpr PWM2Configs() = default;
30
31 /**
32 * \brief The offset applied to the PWM sensor. This offset is added
33 * to the reported sensor position.
34 *
35 * This can be used to zero the sensor position in applications where
36 * the sensor is 1:1 with the mechanism.
37 *
38 * - Minimum Value: -1
39 * - Maximum Value: 1
40 * - Default Value: 0.0
41 * - Units: rotations
42 */
43 units::angle::turn_t AbsoluteSensorOffset = 0.0_tr;
44 /**
45 * \brief The positive discontinuity point of the absolute sensor in
46 * rotations. This determines the point at which the absolute sensor
47 * wraps around, keeping the absolute position (after offset) in the
48 * range [x-1, x).
49 *
50 * - Setting this to 1 makes the absolute position unsigned [0, 1)
51 * - Setting this to 0.5 makes the absolute position signed [-0.5,
52 * 0.5)
53 * - Setting this to 0 makes the absolute position always negative
54 * [-1, 0)
55 *
56 * Many rotational mechanisms such as arms have a region of motion
57 * that is unreachable. This should be set to the center of that
58 * region of motion, in non-negative rotations. This affects the
59 * position of the device at bootup.
60 *
61 * \details For example, consider an arm which can travel from -0.2 to
62 * 0.6 rotations with a little leeway, where 0 is horizontally
63 * forward. Since -0.2 rotations has the same absolute position as 0.8
64 * rotations, we can say that the arm typically does not travel in the
65 * range (0.6, 0.8) rotations. As a result, the discontinuity point
66 * would be the center of that range, which is 0.7 rotations. This
67 * results in an absolute sensor range of [-0.3, 0.7) rotations.
68 *
69 * Given a total range of motion less than 1 rotation, users can
70 * calculate the discontinuity point using mean(lowerLimit,
71 * upperLimit) + 0.5. If that results in a value outside the range [0,
72 * 1], either cap the value to [0, 1], or add/subtract 1.0 rotation
73 * from your lower and upper limits of motion.
74 *
75 * On a Talon motor controller, this is only supported when using the
76 * PulseWidth sensor source.
77 *
78 * - Minimum Value: 0.0
79 * - Maximum Value: 1.0
80 * - Default Value: 0.5
81 * - Units: rotations
82 */
83 units::angle::turn_t AbsoluteSensorDiscontinuityPoint = 0.5_tr;
84 /**
85 * \brief Direction of the PWM sensor to determine positive rotation.
86 * Invert this so that forward motion on the mechanism results in an
87 * increase in PWM position.
88 *
89 * - Default Value: False
90 */
91 bool SensorDirection = false;
92
93 /**
94 * \brief Modifies this configuration's AbsoluteSensorOffset parameter and returns itself for
95 * method-chaining and easier to use config API.
96 *
97 * The offset applied to the PWM sensor. This offset is added to the
98 * reported sensor position.
99 *
100 * This can be used to zero the sensor position in applications where
101 * the sensor is 1:1 with the mechanism.
102 *
103 * - Minimum Value: -1
104 * - Maximum Value: 1
105 * - Default Value: 0.0
106 * - Units: rotations
107 *
108 * \param newAbsoluteSensorOffset Parameter to modify
109 * \returns Itself
110 */
111 constexpr PWM2Configs &WithAbsoluteSensorOffset(units::angle::turn_t newAbsoluteSensorOffset)
112 {
113 AbsoluteSensorOffset = std::move(newAbsoluteSensorOffset);
114 return *this;
115 }
116
117 /**
118 * \brief Modifies this configuration's AbsoluteSensorDiscontinuityPoint parameter and returns itself for
119 * method-chaining and easier to use config API.
120 *
121 * The positive discontinuity point of the absolute sensor in
122 * rotations. This determines the point at which the absolute sensor
123 * wraps around, keeping the absolute position (after offset) in the
124 * range [x-1, x).
125 *
126 * - Setting this to 1 makes the absolute position unsigned [0, 1)
127 * - Setting this to 0.5 makes the absolute position signed [-0.5,
128 * 0.5)
129 * - Setting this to 0 makes the absolute position always negative
130 * [-1, 0)
131 *
132 * Many rotational mechanisms such as arms have a region of motion
133 * that is unreachable. This should be set to the center of that
134 * region of motion, in non-negative rotations. This affects the
135 * position of the device at bootup.
136 *
137 * \details For example, consider an arm which can travel from -0.2 to
138 * 0.6 rotations with a little leeway, where 0 is horizontally
139 * forward. Since -0.2 rotations has the same absolute position as 0.8
140 * rotations, we can say that the arm typically does not travel in the
141 * range (0.6, 0.8) rotations. As a result, the discontinuity point
142 * would be the center of that range, which is 0.7 rotations. This
143 * results in an absolute sensor range of [-0.3, 0.7) rotations.
144 *
145 * Given a total range of motion less than 1 rotation, users can
146 * calculate the discontinuity point using mean(lowerLimit,
147 * upperLimit) + 0.5. If that results in a value outside the range [0,
148 * 1], either cap the value to [0, 1], or add/subtract 1.0 rotation
149 * from your lower and upper limits of motion.
150 *
151 * On a Talon motor controller, this is only supported when using the
152 * PulseWidth sensor source.
153 *
154 * - Minimum Value: 0.0
155 * - Maximum Value: 1.0
156 * - Default Value: 0.5
157 * - Units: rotations
158 *
159 * \param newAbsoluteSensorDiscontinuityPoint Parameter to modify
160 * \returns Itself
161 */
162 constexpr PWM2Configs &WithAbsoluteSensorDiscontinuityPoint(units::angle::turn_t newAbsoluteSensorDiscontinuityPoint)
163 {
164 AbsoluteSensorDiscontinuityPoint = std::move(newAbsoluteSensorDiscontinuityPoint);
165 return *this;
166 }
167
168 /**
169 * \brief Modifies this configuration's SensorDirection parameter and returns itself for
170 * method-chaining and easier to use config API.
171 *
172 * Direction of the PWM sensor to determine positive rotation. Invert
173 * this so that forward motion on the mechanism results in an increase
174 * in PWM position.
175 *
176 * - Default Value: False
177 *
178 * \param newSensorDirection Parameter to modify
179 * \returns Itself
180 */
181 constexpr PWM2Configs &WithSensorDirection(bool newSensorDirection)
182 {
183 SensorDirection = std::move(newSensorDirection);
184 return *this;
185 }
186
187
188
189 std::string ToString() const override;
190
191 std::string Serialize() const final;
192 ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final;
193};
194
195}
196}
197}
Configs related to the CANdi™ branded device's PWM interface on the Signal 2 input (S2IN)
Definition PWM2Configs.hpp:27
units::angle::turn_t AbsoluteSensorOffset
The offset applied to the PWM sensor.
Definition PWM2Configs.hpp:43
ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final
constexpr PWM2Configs & WithAbsoluteSensorDiscontinuityPoint(units::angle::turn_t newAbsoluteSensorDiscontinuityPoint)
Modifies this configuration's AbsoluteSensorDiscontinuityPoint parameter and returns itself for metho...
Definition PWM2Configs.hpp:162
units::angle::turn_t AbsoluteSensorDiscontinuityPoint
The positive discontinuity point of the absolute sensor in rotations.
Definition PWM2Configs.hpp:83
constexpr PWM2Configs & WithAbsoluteSensorOffset(units::angle::turn_t newAbsoluteSensorOffset)
Modifies this configuration's AbsoluteSensorOffset parameter and returns itself for method-chaining a...
Definition PWM2Configs.hpp:111
std::string Serialize() const final
std::string ToString() const override
constexpr PWM2Configs & WithSensorDirection(bool newSensorDirection)
Modifies this configuration's SensorDirection parameter and returns itself for method-chaining and ea...
Definition PWM2Configs.hpp:181
bool SensorDirection
Direction of the PWM sensor to determine positive rotation.
Definition PWM2Configs.hpp:91
Definition Configuration.hpp:17
Definition motor_constants.h:14