CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
DutyCycleOut.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/frequency.h>
11#include <units/time.h>
12#include <units/dimensionless.h>
13
14namespace ctre {
15namespace phoenix6 {
16namespace controls {
17
18/**
19 * Request a specified motor duty cycle.
20 *
21 * This control mode will output a proportion of the supplied voltage which is supplied by the user.
22 */
23class DutyCycleOut final : public ControlRequest {
24 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override;
25
26public:
27 /**
28 * \brief Proportion of supply voltage to apply in fractional units between -1
29 * and +1
30 *
31 * - Units: fractional
32 *
33 */
34 units::dimensionless::scalar_t Output;
35 /**
36 * \brief Set to true to use FOC commutation (requires Phoenix Pro), which
37 * increases peak power by ~15% on supported devices (see
38 * hardware#traits#SupportsFOC). Set to false to use trapezoidal commutation.
39 *
40 * FOC improves motor performance by leveraging torque (current) control.
41 * However, this may be inconvenient for applications that require specifying
42 * duty cycle or voltage. CTR-Electronics has developed a hybrid method that
43 * combines the performances gains of FOC while still allowing applications to
44 * provide duty cycle or voltage demand. This not to be confused with simple
45 * sinusoidal control or phase voltage control which lacks the performance
46 * gains.
47 */
48 bool EnableFOC = true;
49 /**
50 * \brief Set to true to static-brake the rotor when output is zero (or within
51 * deadband). Set to false to use the NeutralMode configuration setting
52 * (default). This flag exists to provide the fundamental behavior of this
53 * control when output is zero, which is to provide 0V to the motor.
54 */
56 /**
57 * \brief Set to true to force forward limiting. This allows users to use other
58 * limit switch sensors connected to robot controller. This also allows use of
59 * active sensors that require external power.
60 */
61 bool LimitForwardMotion = false;
62 /**
63 * \brief Set to true to force reverse limiting. This allows users to use other
64 * limit switch sensors connected to robot controller. This also allows use of
65 * active sensors that require external power.
66 */
67 bool LimitReverseMotion = false;
68 /**
69 * \brief Set to true to ignore hardware limit switches and the
70 * LimitForwardMotion and LimitReverseMotion parameters, instead allowing
71 * motion.
72 *
73 * This can be useful on mechanisms such as an intake/feeder, where a limit
74 * switch stops motion while intaking but should be ignored when feeding to a
75 * shooter.
76 *
77 * The hardware limit faults and Forward/ReverseLimit signals will still report
78 * the values of the limit switches regardless of this parameter.
79 */
81 /**
82 * \brief Set to true to ignore software limits, instead allowing motion.
83 *
84 * This can be useful when calibrating the zero point of a mechanism such as an
85 * elevator.
86 *
87 * The software limit faults will still report the values of the software limits
88 * regardless of this parameter.
89 */
91 /**
92 * \brief Set to true to delay applying this control request until a timesync
93 * boundary (requires Phoenix Pro and CANivore). This eliminates the impact of
94 * nondeterministic network delays in exchange for a larger but deterministic
95 * control latency.
96 *
97 * This requires setting the ControlTimesyncFreqHz config in MotorOutputConfigs.
98 * Additionally, when this is enabled, the UpdateFreqHz of this request should
99 * be set to 0 Hz.
100 */
101 bool UseTimesync = false;
102
103 /**
104 * \brief The frequency at which this control will update.
105 * This is designated in Hertz, with a minimum of 20 Hz
106 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
107 * Some update frequencies are not supported and will be
108 * promoted up to the next highest supported frequency.
109 *
110 * If this field is set to 0 Hz, the control request will
111 * be sent immediately as a one-shot frame. This may be useful
112 * for advanced applications that require outputs to be
113 * synchronized with data acquisition. In this case, we
114 * recommend not exceeding 50 ms between control calls.
115 */
116 units::frequency::hertz_t UpdateFreqHz{100_Hz};
117
118 /**
119 * \brief Request a specified motor duty cycle.
120 *
121 * \details This control mode will output a proportion of the supplied voltage
122 * which is supplied by the user.
123 *
124 * \param Output Proportion of supply voltage to apply in fractional units
125 * between -1 and +1
126 */
127 constexpr DutyCycleOut(units::dimensionless::scalar_t Output) : ControlRequest{},
128 Output{std::move(Output)}
129 {}
130
131 constexpr ~DutyCycleOut() override {}
132
133 /**
134 * \brief Gets the name of this control request.
135 *
136 * \returns Name of the control request
137 */
138 constexpr std::string_view GetName() const override
139 {
140 return "DutyCycleOut";
141 }
142
143 /**
144 * \brief Modifies this Control Request's Output parameter and returns itself for
145 * method-chaining and easier to use request API.
146 *
147 * Proportion of supply voltage to apply in fractional units between -1 and +1
148 *
149 * - Units: fractional
150 *
151 *
152 * \param newOutput Parameter to modify
153 * \returns Itself
154 */
155 constexpr DutyCycleOut &WithOutput(units::dimensionless::scalar_t newOutput)
156 {
157 Output = std::move(newOutput);
158 return *this;
159 }
160
161 /**
162 * \brief Modifies this Control Request's EnableFOC parameter and returns itself for
163 * method-chaining and easier to use request API.
164 *
165 * Set to true to use FOC commutation (requires Phoenix Pro), which increases
166 * peak power by ~15% on supported devices (see hardware#traits#SupportsFOC).
167 * Set to false to use trapezoidal commutation.
168 *
169 * FOC improves motor performance by leveraging torque (current) control.
170 * However, this may be inconvenient for applications that require specifying
171 * duty cycle or voltage. CTR-Electronics has developed a hybrid method that
172 * combines the performances gains of FOC while still allowing applications to
173 * provide duty cycle or voltage demand. This not to be confused with simple
174 * sinusoidal control or phase voltage control which lacks the performance
175 * gains.
176 *
177 * \param newEnableFOC Parameter to modify
178 * \returns Itself
179 */
180 constexpr DutyCycleOut &WithEnableFOC(bool newEnableFOC)
181 {
182 EnableFOC = std::move(newEnableFOC);
183 return *this;
184 }
185
186 /**
187 * \brief Modifies this Control Request's OverrideBrakeDurNeutral parameter and returns itself for
188 * method-chaining and easier to use request API.
189 *
190 * Set to true to static-brake the rotor when output is zero (or within
191 * deadband). Set to false to use the NeutralMode configuration setting
192 * (default). This flag exists to provide the fundamental behavior of this
193 * control when output is zero, which is to provide 0V to the motor.
194 *
195 * \param newOverrideBrakeDurNeutral Parameter to modify
196 * \returns Itself
197 */
198 constexpr DutyCycleOut &WithOverrideBrakeDurNeutral(bool newOverrideBrakeDurNeutral)
199 {
200 OverrideBrakeDurNeutral = std::move(newOverrideBrakeDurNeutral);
201 return *this;
202 }
203
204 /**
205 * \brief Modifies this Control Request's LimitForwardMotion parameter and returns itself for
206 * method-chaining and easier to use request API.
207 *
208 * Set to true to force forward limiting. This allows users to use other limit
209 * switch sensors connected to robot controller. This also allows use of active
210 * sensors that require external power.
211 *
212 * \param newLimitForwardMotion Parameter to modify
213 * \returns Itself
214 */
215 constexpr DutyCycleOut &WithLimitForwardMotion(bool newLimitForwardMotion)
216 {
217 LimitForwardMotion = std::move(newLimitForwardMotion);
218 return *this;
219 }
220
221 /**
222 * \brief Modifies this Control Request's LimitReverseMotion parameter and returns itself for
223 * method-chaining and easier to use request API.
224 *
225 * Set to true to force reverse limiting. This allows users to use other limit
226 * switch sensors connected to robot controller. This also allows use of active
227 * sensors that require external power.
228 *
229 * \param newLimitReverseMotion Parameter to modify
230 * \returns Itself
231 */
232 constexpr DutyCycleOut &WithLimitReverseMotion(bool newLimitReverseMotion)
233 {
234 LimitReverseMotion = std::move(newLimitReverseMotion);
235 return *this;
236 }
237
238 /**
239 * \brief Modifies this Control Request's IgnoreHardwareLimits parameter and returns itself for
240 * method-chaining and easier to use request API.
241 *
242 * Set to true to ignore hardware limit switches and the LimitForwardMotion and
243 * LimitReverseMotion parameters, instead allowing motion.
244 *
245 * This can be useful on mechanisms such as an intake/feeder, where a limit
246 * switch stops motion while intaking but should be ignored when feeding to a
247 * shooter.
248 *
249 * The hardware limit faults and Forward/ReverseLimit signals will still report
250 * the values of the limit switches regardless of this parameter.
251 *
252 * \param newIgnoreHardwareLimits Parameter to modify
253 * \returns Itself
254 */
255 constexpr DutyCycleOut &WithIgnoreHardwareLimits(bool newIgnoreHardwareLimits)
256 {
257 IgnoreHardwareLimits = std::move(newIgnoreHardwareLimits);
258 return *this;
259 }
260
261 /**
262 * \brief Modifies this Control Request's IgnoreSoftwareLimits parameter and returns itself for
263 * method-chaining and easier to use request API.
264 *
265 * Set to true to ignore software limits, instead allowing motion.
266 *
267 * This can be useful when calibrating the zero point of a mechanism such as an
268 * elevator.
269 *
270 * The software limit faults will still report the values of the software limits
271 * regardless of this parameter.
272 *
273 * \param newIgnoreSoftwareLimits Parameter to modify
274 * \returns Itself
275 */
276 constexpr DutyCycleOut &WithIgnoreSoftwareLimits(bool newIgnoreSoftwareLimits)
277 {
278 IgnoreSoftwareLimits = std::move(newIgnoreSoftwareLimits);
279 return *this;
280 }
281
282 /**
283 * \brief Modifies this Control Request's UseTimesync parameter and returns itself for
284 * method-chaining and easier to use request API.
285 *
286 * Set to true to delay applying this control request until a timesync boundary
287 * (requires Phoenix Pro and CANivore). This eliminates the impact of
288 * nondeterministic network delays in exchange for a larger but deterministic
289 * control latency.
290 *
291 * This requires setting the ControlTimesyncFreqHz config in MotorOutputConfigs.
292 * Additionally, when this is enabled, the UpdateFreqHz of this request should
293 * be set to 0 Hz.
294 *
295 * \param newUseTimesync Parameter to modify
296 * \returns Itself
297 */
298 constexpr DutyCycleOut &WithUseTimesync(bool newUseTimesync)
299 {
300 UseTimesync = std::move(newUseTimesync);
301 return *this;
302 }
303
304 /**
305 * \brief Sets the frequency at which this control will update.
306 * This is designated in Hertz, with a minimum of 20 Hz
307 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
308 * Some update frequencies are not supported and will be
309 * promoted up to the next highest supported frequency.
310 *
311 * If this field is set to 0 Hz, the control request will
312 * be sent immediately as a one-shot frame. This may be useful
313 * for advanced applications that require outputs to be
314 * synchronized with data acquisition. In this case, we
315 * recommend not exceeding 50 ms between control calls.
316 *
317 * \param newUpdateFreqHz Parameter to modify
318 * \returns Itself
319 */
320 constexpr DutyCycleOut &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
321 {
322 UpdateFreqHz = newUpdateFreqHz;
323 return *this;
324 }
325
326 /**
327 * \brief Returns a string representation of the object.
328 *
329 * \returns a string representation of the object.
330 */
331 std::string ToString() const override;
332
333 /**
334 * \brief Gets information about this control request.
335 *
336 * \returns Map of control parameter names and corresponding applied values
337 */
338 std::map<std::string, std::string> GetControlInfo() const override;
339};
340
341}
342}
343}
344
Common interface implemented by all control requests.
Definition ControlRequest.hpp:27
Request a specified motor duty cycle.
Definition DutyCycleOut.hpp:23
constexpr DutyCycleOut & WithOutput(units::dimensionless::scalar_t newOutput)
Modifies this Control Request's Output parameter and returns itself for method-chaining and easier to...
Definition DutyCycleOut.hpp:155
constexpr DutyCycleOut & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the frequency at which this control will update.
Definition DutyCycleOut.hpp:320
constexpr DutyCycleOut & WithEnableFOC(bool newEnableFOC)
Modifies this Control Request's EnableFOC parameter and returns itself for method-chaining and easier...
Definition DutyCycleOut.hpp:180
bool LimitForwardMotion
Set to true to force forward limiting.
Definition DutyCycleOut.hpp:61
constexpr DutyCycleOut & WithIgnoreSoftwareLimits(bool newIgnoreSoftwareLimits)
Modifies this Control Request's IgnoreSoftwareLimits parameter and returns itself for method-chaining...
Definition DutyCycleOut.hpp:276
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition DutyCycleOut.hpp:138
bool OverrideBrakeDurNeutral
Set to true to static-brake the rotor when output is zero (or within deadband).
Definition DutyCycleOut.hpp:55
units::dimensionless::scalar_t Output
Proportion of supply voltage to apply in fractional units between -1 and +1.
Definition DutyCycleOut.hpp:34
constexpr DutyCycleOut & WithIgnoreHardwareLimits(bool newIgnoreHardwareLimits)
Modifies this Control Request's IgnoreHardwareLimits parameter and returns itself for method-chaining...
Definition DutyCycleOut.hpp:255
units::frequency::hertz_t UpdateFreqHz
The frequency at which this control will update.
Definition DutyCycleOut.hpp:116
constexpr DutyCycleOut & WithLimitForwardMotion(bool newLimitForwardMotion)
Modifies this Control Request's LimitForwardMotion parameter and returns itself for method-chaining a...
Definition DutyCycleOut.hpp:215
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition DutyCycleOut.hpp:101
bool IgnoreSoftwareLimits
Set to true to ignore software limits, instead allowing motion.
Definition DutyCycleOut.hpp:90
constexpr DutyCycleOut(units::dimensionless::scalar_t Output)
Request a specified motor duty cycle.
Definition DutyCycleOut.hpp:127
std::string ToString() const override
Returns a string representation of the object.
constexpr ~DutyCycleOut() override
Definition DutyCycleOut.hpp:131
constexpr DutyCycleOut & WithLimitReverseMotion(bool newLimitReverseMotion)
Modifies this Control Request's LimitReverseMotion parameter and returns itself for method-chaining a...
Definition DutyCycleOut.hpp:232
constexpr DutyCycleOut & WithOverrideBrakeDurNeutral(bool newOverrideBrakeDurNeutral)
Modifies this Control Request's OverrideBrakeDurNeutral parameter and returns itself for method-chain...
Definition DutyCycleOut.hpp:198
constexpr DutyCycleOut & WithUseTimesync(bool newUseTimesync)
Modifies this Control Request's UseTimesync parameter and returns itself for method-chaining and easi...
Definition DutyCycleOut.hpp:298
bool IgnoreHardwareLimits
Set to true to ignore hardware limit switches and the LimitForwardMotion and LimitReverseMotion param...
Definition DutyCycleOut.hpp:80
bool EnableFOC
Set to true to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15% on supp...
Definition DutyCycleOut.hpp:48
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition DutyCycleOut.hpp:67
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
Definition motor_constants.h:14