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