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