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