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