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