CTRE Phoenix 6 C++ 26.50.0-alpha-1
Loading...
Searching...
No Matches
Slot2Configs.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
11#include <wpi/units/angle.hpp>
12#include <wpi/units/dimensionless.hpp>
13
14namespace ctre {
15namespace phoenix6 {
16namespace configs { class SlotConfigs; }
17
18namespace configs {
19
20/**
21 * \brief Gains for the specified slot.
22 *
23 * \details If this slot is selected, these gains are used in closed
24 * loop control requests.
25 */
27public:
28 constexpr Slot2Configs() = default;
29
30 /**
31 * \brief Proportional gain.
32 *
33 * \details The units for this gain is dependent on the control mode.
34 * Since this gain is multiplied by error in the input, the units
35 * should be defined as units of output per unit of input error. For
36 * example, when controlling velocity using a duty cycle closed loop,
37 * the units for the proportional gain will be duty cycle per rps, or
38 * 1/rps.
39 *
40 * - Minimum Value: 0
41 * - Maximum Value: 3.4e+38
42 * - Default Value: 0
43 * - Units:
44 */
45 wpi::units::scalar_t kP = 0;
46 /**
47 * \brief Integral gain.
48 *
49 * \details The units for this gain is dependent on the control mode.
50 * Since this gain is multiplied by error in the input integrated over
51 * time (in units of seconds), the units should be defined as units of
52 * output per unit of integrated input error. For example, when
53 * controlling velocity using a duty cycle closed loop, integrating
54 * velocity over time results in rps * s = rotations. Therefore, the
55 * units for the integral gain will be duty cycle per rotation of
56 * accumulated error, or 1/rot.
57 *
58 * - Minimum Value: 0
59 * - Maximum Value: 3.4e+38
60 * - Default Value: 0
61 * - Units:
62 */
63 wpi::units::scalar_t kI = 0;
64 /**
65 * \brief Derivative gain.
66 *
67 * \details The units for this gain is dependent on the control mode.
68 * Since this gain is multiplied by the derivative of error in the
69 * input with respect to time (in units of seconds), the units should
70 * be defined as units of output per unit of the differentiated input
71 * error. For example, when controlling velocity using a duty cycle
72 * closed loop, the derivative of velocity with respect to time is rot
73 * per sec², which is acceleration. Therefore, the units for the
74 * derivative gain will be duty cycle per unit of acceleration error,
75 * or 1/(rot per sec²).
76 *
77 * - Minimum Value: 0
78 * - Maximum Value: 3.4e+38
79 * - Default Value: 0
80 * - Units:
81 */
82 wpi::units::scalar_t kD = 0;
83 /**
84 * \brief Static feedforward gain.
85 *
86 * \details This is added to the closed loop output. The unit for this
87 * constant is dependent on the control mode, typically fractional
88 * duty cycle, voltage, or torque current.
89 *
90 * The sign is typically determined by reference velocity when using
91 * position, velocity, and Motion Magic® closed loop modes. However,
92 * when using position closed loop with zero velocity reference (no
93 * motion profiling), the application can instead use the position
94 * closed loop error by setting the Static Feedforward Sign
95 * configuration parameter. When doing so, we recommend the minimal
96 * amount of kS, otherwise the motor output may dither when closed
97 * loop error is near zero.
98 *
99 * - Minimum Value: -128
100 * - Maximum Value: 127
101 * - Default Value: 0
102 * - Units:
103 */
104 wpi::units::scalar_t kS = 0;
105 /**
106 * \brief Velocity feedforward gain.
107 *
108 * \details The units for this gain is dependent on the control mode.
109 * Since this gain is multiplied by the requested velocity, the units
110 * should be defined as units of output per unit of requested input
111 * velocity. For example, when controlling velocity using a duty cycle
112 * closed loop, the units for the velocity feedfoward gain will be
113 * duty cycle per requested rps, or 1/rps.
114 *
115 * - Minimum Value: 0
116 * - Maximum Value: 3.4e+38
117 * - Default Value: 0
118 * - Units:
119 */
120 wpi::units::scalar_t kV = 0;
121 /**
122 * \brief Acceleration feedforward gain.
123 *
124 * \details The units for this gain is dependent on the control mode.
125 * Since this gain is multiplied by the requested acceleration, the
126 * units should be defined as units of output per unit of requested
127 * input acceleration. For example, when controlling velocity using a
128 * duty cycle closed loop, the units for the acceleration feedfoward
129 * gain will be duty cycle per requested rot per sec², or 1/(rot per
130 * sec²).
131 *
132 * - Minimum Value: 0
133 * - Maximum Value: 3.4e+38
134 * - Default Value: 0
135 * - Units:
136 */
137 wpi::units::scalar_t kA = 0;
138 /**
139 * \brief Gravity feedforward/feedback gain. The type of gravity
140 * compensation is selected by #GravityType.
141 *
142 * \details This is added to the closed loop output. The sign is
143 * determined by the gravity type. The unit for this constant is
144 * dependent on the control mode, typically fractional duty cycle,
145 * voltage, or torque current.
146 *
147 * Note that kG may be negative for some counterbalanced mechanisms.
148 *
149 * - Minimum Value: -128
150 * - Maximum Value: 127
151 * - Default Value: 0
152 * - Units:
153 */
154 wpi::units::scalar_t kG = 0;
155 /**
156 * \brief Gravity feedforward/feedback type.
157 *
158 * This determines the type of the gravity feedforward/feedback.
159 *
160 * Choose Elevator_Static for systems where the gravity feedforward is
161 * constant, such as an elevator. The gravity feedforward output will
162 * always be positive.
163 *
164 * Choose Arm_Cosine for systems where the gravity feedback is
165 * dependent on the angular position of the mechanism, such as an arm.
166 * The gravity feedback output will vary depending on the mechanism
167 * angular position. Note that the sensor offset and ratios must be
168 * configured so that the sensor position is 0 when the mechanism is
169 * horizonal, and one rotation of the mechanism corresponds to one
170 * rotation of the sensor position.
171 *
172 * - Default Value: signals#GravityTypeValue#Elevator_Static
173 */
175 /**
176 * \brief Static feedforward sign during position closed loop.
177 *
178 * This determines the sign of the applied kS during position
179 * closed-loop modes. The default behavior uses the velocity reference
180 * sign. This works well with velocity closed loop, Motion Magic®
181 * controls, and position closed loop when velocity reference is
182 * specified (motion profiling).
183 *
184 * However, when using position closed loop with zero velocity
185 * reference (no motion profiling), the application may want to apply
186 * static feedforward based on the closed loop error sign instead.
187 * When doing so, we recommend using the minimal amount of kS,
188 * otherwise the motor output may dither when closed loop error is
189 * near zero.
190 *
191 * - Default Value: signals#StaticFeedforwardSignValue#UseVelocitySign
192 */
194 /**
195 * \brief Gravity feedback position offset when using the Arm/Cosine
196 * gravity type.
197 *
198 * This is an offset applied to the position of the arm, within
199 * (-0.25, 0.25) rot, before calculating the output of kG. This is
200 * useful when the center of gravity of the arm is offset from the
201 * actual zero point of the arm, such as when the arm and intake form
202 * an L shape.
203 *
204 * - Minimum Value: -0.25
205 * - Maximum Value: 0.25
206 * - Default Value: 0
207 * - Units: rotations
208 */
209 wpi::units::turn_t GravityArmPositionOffset = 0_tr;
210 /**
211 * \brief The behavior of the gain scheduler on this slot. This
212 * specifies which gains to use while within the configured
213 * GainSchedErrorThreshold. The default is to continue using the
214 * specified slot.
215 *
216 * \details Gain scheduling will not take effect when running velocity
217 * closed-loop controls.
218 *
219 * - Default Value: signals#GainSchedBehaviorValue#Inactive
220 */
222
223 /**
224 * \brief Modifies this configuration's kP parameter and returns itself for
225 * method-chaining and easier to use config API.
226 *
227 * Proportional gain.
228 *
229 * \details The units for this gain is dependent on the control mode.
230 * Since this gain is multiplied by error in the input, the units
231 * should be defined as units of output per unit of input error. For
232 * example, when controlling velocity using a duty cycle closed loop,
233 * the units for the proportional gain will be duty cycle per rps, or
234 * 1/rps.
235 *
236 * - Minimum Value: 0
237 * - Maximum Value: 3.4e+38
238 * - Default Value: 0
239 * - Units:
240 *
241 * \param newKP Parameter to modify
242 * \returns Itself
243 */
244 constexpr Slot2Configs &WithKP(wpi::units::scalar_t newKP)
245 {
246 kP = std::move(newKP);
247 return *this;
248 }
249
250 /**
251 * \brief Modifies this configuration's kI parameter and returns itself for
252 * method-chaining and easier to use config API.
253 *
254 * Integral gain.
255 *
256 * \details The units for this gain is dependent on the control mode.
257 * Since this gain is multiplied by error in the input integrated over
258 * time (in units of seconds), the units should be defined as units of
259 * output per unit of integrated input error. For example, when
260 * controlling velocity using a duty cycle closed loop, integrating
261 * velocity over time results in rps * s = rotations. Therefore, the
262 * units for the integral gain will be duty cycle per rotation of
263 * accumulated error, or 1/rot.
264 *
265 * - Minimum Value: 0
266 * - Maximum Value: 3.4e+38
267 * - Default Value: 0
268 * - Units:
269 *
270 * \param newKI Parameter to modify
271 * \returns Itself
272 */
273 constexpr Slot2Configs &WithKI(wpi::units::scalar_t newKI)
274 {
275 kI = std::move(newKI);
276 return *this;
277 }
278
279 /**
280 * \brief Modifies this configuration's kD parameter and returns itself for
281 * method-chaining and easier to use config API.
282 *
283 * Derivative gain.
284 *
285 * \details The units for this gain is dependent on the control mode.
286 * Since this gain is multiplied by the derivative of error in the
287 * input with respect to time (in units of seconds), the units should
288 * be defined as units of output per unit of the differentiated input
289 * error. For example, when controlling velocity using a duty cycle
290 * closed loop, the derivative of velocity with respect to time is rot
291 * per sec², which is acceleration. Therefore, the units for the
292 * derivative gain will be duty cycle per unit of acceleration error,
293 * or 1/(rot per sec²).
294 *
295 * - Minimum Value: 0
296 * - Maximum Value: 3.4e+38
297 * - Default Value: 0
298 * - Units:
299 *
300 * \param newKD Parameter to modify
301 * \returns Itself
302 */
303 constexpr Slot2Configs &WithKD(wpi::units::scalar_t newKD)
304 {
305 kD = std::move(newKD);
306 return *this;
307 }
308
309 /**
310 * \brief Modifies this configuration's kS parameter and returns itself for
311 * method-chaining and easier to use config API.
312 *
313 * Static feedforward gain.
314 *
315 * \details This is added to the closed loop output. The unit for this
316 * constant is dependent on the control mode, typically fractional
317 * duty cycle, voltage, or torque current.
318 *
319 * The sign is typically determined by reference velocity when using
320 * position, velocity, and Motion Magic® closed loop modes. However,
321 * when using position closed loop with zero velocity reference (no
322 * motion profiling), the application can instead use the position
323 * closed loop error by setting the Static Feedforward Sign
324 * configuration parameter. When doing so, we recommend the minimal
325 * amount of kS, otherwise the motor output may dither when closed
326 * loop error is near zero.
327 *
328 * - Minimum Value: -128
329 * - Maximum Value: 127
330 * - Default Value: 0
331 * - Units:
332 *
333 * \param newKS Parameter to modify
334 * \returns Itself
335 */
336 constexpr Slot2Configs &WithKS(wpi::units::scalar_t newKS)
337 {
338 kS = std::move(newKS);
339 return *this;
340 }
341
342 /**
343 * \brief Modifies this configuration's kV parameter and returns itself for
344 * method-chaining and easier to use config API.
345 *
346 * Velocity feedforward gain.
347 *
348 * \details The units for this gain is dependent on the control mode.
349 * Since this gain is multiplied by the requested velocity, the units
350 * should be defined as units of output per unit of requested input
351 * velocity. For example, when controlling velocity using a duty cycle
352 * closed loop, the units for the velocity feedfoward gain will be
353 * duty cycle per requested rps, or 1/rps.
354 *
355 * - Minimum Value: 0
356 * - Maximum Value: 3.4e+38
357 * - Default Value: 0
358 * - Units:
359 *
360 * \param newKV Parameter to modify
361 * \returns Itself
362 */
363 constexpr Slot2Configs &WithKV(wpi::units::scalar_t newKV)
364 {
365 kV = std::move(newKV);
366 return *this;
367 }
368
369 /**
370 * \brief Modifies this configuration's kA parameter and returns itself for
371 * method-chaining and easier to use config API.
372 *
373 * Acceleration feedforward gain.
374 *
375 * \details The units for this gain is dependent on the control mode.
376 * Since this gain is multiplied by the requested acceleration, the
377 * units should be defined as units of output per unit of requested
378 * input acceleration. For example, when controlling velocity using a
379 * duty cycle closed loop, the units for the acceleration feedfoward
380 * gain will be duty cycle per requested rot per sec², or 1/(rot per
381 * sec²).
382 *
383 * - Minimum Value: 0
384 * - Maximum Value: 3.4e+38
385 * - Default Value: 0
386 * - Units:
387 *
388 * \param newKA Parameter to modify
389 * \returns Itself
390 */
391 constexpr Slot2Configs &WithKA(wpi::units::scalar_t newKA)
392 {
393 kA = std::move(newKA);
394 return *this;
395 }
396
397 /**
398 * \brief Modifies this configuration's kG parameter and returns itself for
399 * method-chaining and easier to use config API.
400 *
401 * Gravity feedforward/feedback gain. The type of gravity compensation
402 * is selected by #GravityType.
403 *
404 * \details This is added to the closed loop output. The sign is
405 * determined by the gravity type. The unit for this constant is
406 * dependent on the control mode, typically fractional duty cycle,
407 * voltage, or torque current.
408 *
409 * Note that kG may be negative for some counterbalanced mechanisms.
410 *
411 * - Minimum Value: -128
412 * - Maximum Value: 127
413 * - Default Value: 0
414 * - Units:
415 *
416 * \param newKG Parameter to modify
417 * \returns Itself
418 */
419 constexpr Slot2Configs &WithKG(wpi::units::scalar_t newKG)
420 {
421 kG = std::move(newKG);
422 return *this;
423 }
424
425 /**
426 * \brief Modifies this configuration's GravityType parameter and returns itself for
427 * method-chaining and easier to use config API.
428 *
429 * Gravity feedforward/feedback type.
430 *
431 * This determines the type of the gravity feedforward/feedback.
432 *
433 * Choose Elevator_Static for systems where the gravity feedforward is
434 * constant, such as an elevator. The gravity feedforward output will
435 * always be positive.
436 *
437 * Choose Arm_Cosine for systems where the gravity feedback is
438 * dependent on the angular position of the mechanism, such as an arm.
439 * The gravity feedback output will vary depending on the mechanism
440 * angular position. Note that the sensor offset and ratios must be
441 * configured so that the sensor position is 0 when the mechanism is
442 * horizonal, and one rotation of the mechanism corresponds to one
443 * rotation of the sensor position.
444 *
445 * - Default Value: signals#GravityTypeValue#Elevator_Static
446 *
447 * \param newGravityType Parameter to modify
448 * \returns Itself
449 */
451 {
452 GravityType = std::move(newGravityType);
453 return *this;
454 }
455
456 /**
457 * \brief Modifies this configuration's StaticFeedforwardSign parameter and returns itself for
458 * method-chaining and easier to use config API.
459 *
460 * Static feedforward sign during position closed loop.
461 *
462 * This determines the sign of the applied kS during position
463 * closed-loop modes. The default behavior uses the velocity reference
464 * sign. This works well with velocity closed loop, Motion Magic®
465 * controls, and position closed loop when velocity reference is
466 * specified (motion profiling).
467 *
468 * However, when using position closed loop with zero velocity
469 * reference (no motion profiling), the application may want to apply
470 * static feedforward based on the closed loop error sign instead.
471 * When doing so, we recommend using the minimal amount of kS,
472 * otherwise the motor output may dither when closed loop error is
473 * near zero.
474 *
475 * - Default Value: signals#StaticFeedforwardSignValue#UseVelocitySign
476 *
477 * \param newStaticFeedforwardSign Parameter to modify
478 * \returns Itself
479 */
481 {
482 StaticFeedforwardSign = std::move(newStaticFeedforwardSign);
483 return *this;
484 }
485
486 /**
487 * \brief Modifies this configuration's GravityArmPositionOffset parameter and returns itself for
488 * method-chaining and easier to use config API.
489 *
490 * Gravity feedback position offset when using the Arm/Cosine gravity
491 * type.
492 *
493 * This is an offset applied to the position of the arm, within
494 * (-0.25, 0.25) rot, before calculating the output of kG. This is
495 * useful when the center of gravity of the arm is offset from the
496 * actual zero point of the arm, such as when the arm and intake form
497 * an L shape.
498 *
499 * - Minimum Value: -0.25
500 * - Maximum Value: 0.25
501 * - Default Value: 0
502 * - Units: rotations
503 *
504 * \param newGravityArmPositionOffset Parameter to modify
505 * \returns Itself
506 */
507 constexpr Slot2Configs &WithGravityArmPositionOffset(wpi::units::turn_t newGravityArmPositionOffset)
508 {
509 GravityArmPositionOffset = std::move(newGravityArmPositionOffset);
510 return *this;
511 }
512
513 /**
514 * \brief Modifies this configuration's GainSchedBehavior parameter and returns itself for
515 * method-chaining and easier to use config API.
516 *
517 * The behavior of the gain scheduler on this slot. This specifies
518 * which gains to use while within the configured
519 * GainSchedErrorThreshold. The default is to continue using the
520 * specified slot.
521 *
522 * \details Gain scheduling will not take effect when running velocity
523 * closed-loop controls.
524 *
525 * - Default Value: signals#GainSchedBehaviorValue#Inactive
526 *
527 * \param newGainSchedBehavior Parameter to modify
528 * \returns Itself
529 */
531 {
532 GainSchedBehavior = std::move(newGainSchedBehavior);
533 return *this;
534 }
535
536 /**
537 * Converts the provided value to an instance of this type.
538 *
539 * \param value The value to convert
540 * \returns Converted value
541 */
542 static Slot2Configs From(SlotConfigs const &value);
543
544 std::string ToString() const override;
545
546 std::string Serialize() const final;
547 ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final;
548};
549
550}
551}
552}
Definition Configuration.hpp:17
signals::GravityTypeValue GravityType
Gravity feedforward/feedback type.
Definition Slot2Configs.hpp:174
constexpr Slot2Configs & WithGravityType(signals::GravityTypeValue newGravityType)
Modifies this configuration's GravityType parameter and returns itself for method-chaining and easier...
Definition Slot2Configs.hpp:450
static Slot2Configs From(SlotConfigs const &value)
Converts the provided value to an instance of this type.
wpi::units::scalar_t kP
Proportional gain.
Definition Slot2Configs.hpp:45
constexpr Slot2Configs & WithKV(wpi::units::scalar_t newKV)
Modifies this configuration's kV parameter and returns itself for method-chaining and easier to use c...
Definition Slot2Configs.hpp:363
ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final
constexpr Slot2Configs & WithGravityArmPositionOffset(wpi::units::turn_t newGravityArmPositionOffset)
Modifies this configuration's GravityArmPositionOffset parameter and returns itself for method-chaini...
Definition Slot2Configs.hpp:507
constexpr Slot2Configs & WithKD(wpi::units::scalar_t newKD)
Modifies this configuration's kD parameter and returns itself for method-chaining and easier to use c...
Definition Slot2Configs.hpp:303
wpi::units::scalar_t kV
Velocity feedforward gain.
Definition Slot2Configs.hpp:120
constexpr Slot2Configs & WithStaticFeedforwardSign(signals::StaticFeedforwardSignValue newStaticFeedforwardSign)
Modifies this configuration's StaticFeedforwardSign parameter and returns itself for method-chaining ...
Definition Slot2Configs.hpp:480
std::string Serialize() const final
wpi::units::scalar_t kS
Static feedforward gain.
Definition Slot2Configs.hpp:104
wpi::units::turn_t GravityArmPositionOffset
Gravity feedback position offset when using the Arm/Cosine gravity type.
Definition Slot2Configs.hpp:209
constexpr Slot2Configs & WithKS(wpi::units::scalar_t newKS)
Modifies this configuration's kS parameter and returns itself for method-chaining and easier to use c...
Definition Slot2Configs.hpp:336
constexpr Slot2Configs & WithKA(wpi::units::scalar_t newKA)
Modifies this configuration's kA parameter and returns itself for method-chaining and easier to use c...
Definition Slot2Configs.hpp:391
constexpr Slot2Configs & WithKI(wpi::units::scalar_t newKI)
Modifies this configuration's kI parameter and returns itself for method-chaining and easier to use c...
Definition Slot2Configs.hpp:273
wpi::units::scalar_t kG
Gravity feedforward/feedback gain.
Definition Slot2Configs.hpp:154
constexpr Slot2Configs & WithKP(wpi::units::scalar_t newKP)
Modifies this configuration's kP parameter and returns itself for method-chaining and easier to use c...
Definition Slot2Configs.hpp:244
wpi::units::scalar_t kD
Derivative gain.
Definition Slot2Configs.hpp:82
signals::StaticFeedforwardSignValue StaticFeedforwardSign
Static feedforward sign during position closed loop.
Definition Slot2Configs.hpp:193
wpi::units::scalar_t kI
Integral gain.
Definition Slot2Configs.hpp:63
constexpr Slot2Configs & WithKG(wpi::units::scalar_t newKG)
Modifies this configuration's kG parameter and returns itself for method-chaining and easier to use c...
Definition Slot2Configs.hpp:419
constexpr Slot2Configs & WithGainSchedBehavior(signals::GainSchedBehaviorValue newGainSchedBehavior)
Modifies this configuration's GainSchedBehavior parameter and returns itself for method-chaining and ...
Definition Slot2Configs.hpp:530
std::string ToString() const override
wpi::units::scalar_t kA
Acceleration feedforward gain.
Definition Slot2Configs.hpp:137
signals::GainSchedBehaviorValue GainSchedBehavior
The behavior of the gain scheduler on this slot.
Definition Slot2Configs.hpp:221
Gains for the specified slot.
Definition SlotConfigs.hpp:26
Definition ExternalFeedbackConfigs.hpp:21
Definition ExternalFeedbackConfigs.hpp:16
Definition FrcUsageReport.hpp:12
Definition motor_constants.h:14
The behavior of the gain scheduler on this slot.
Definition SpnEnums.hpp:5059
static constexpr int Inactive
No gain scheduling will occur.
Definition SpnEnums.hpp:5065
Gravity feedforward/feedback type.
Definition SpnEnums.hpp:1488
static constexpr int Elevator_Static
The system's gravity feedforward is constant, such as an elevator.
Definition SpnEnums.hpp:1495
Static feedforward sign during position closed loop.
Definition SpnEnums.hpp:2475
static constexpr int UseVelocitySign
Use the velocity reference sign.
Definition SpnEnums.hpp:2483