CTRE Phoenix 6 C++ 26.50.0-alpha-1
Loading...
Searching...
No Matches
ClosedLoopGeneralConfigs.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
13namespace ctre {
14namespace phoenix6 {
15
16
17namespace configs {
18
19/**
20 * \brief Configs that affect general behavior during closed-looping.
21 *
22 * \details Includes Continuous Wrap features.
23 */
25public:
26 constexpr ClosedLoopGeneralConfigs() = default;
27
28 /**
29 * \brief Wrap position error within [-0.5, +0.5) mechanism rotations.
30 * Typically used for continuous position closed-loops like swerve
31 * azimuth.
32 *
33 * \details This uses the mechanism rotation value. If there is a gear
34 * ratio between the sensor and the mechanism, make sure to apply a
35 * SensorToMechanismRatio so the closed loop operates on the full
36 * rotation.
37 *
38 * - Default Value: False
39 */
40 bool ContinuousWrap = false;
41 /**
42 * \brief Wrap differential difference position error within [-0.5,
43 * +0.5) mechanism rotations. Typically used for continuous position
44 * closed-loops like a differential wrist.
45 *
46 * \details This uses the differential difference rotation value. If
47 * there is a gear ratio on the difference axis, make sure to apply a
48 * SensorToDifferentialRatio so the closed loop operates on the full
49 * rotation.
50 *
51 * - Default Value: False
52 */
54 /**
55 * \brief The position closed-loop error threshold for gain
56 * scheduling. When the absolute value of the closed-loop error is
57 * within the threshold (inclusive), the PID controller will
58 * automatically switch gains according to the configured
59 * GainSchedBehavior of the slot.
60 *
61 * When this is zero (default), no gain scheduling will occur.
62 * Additionally, this does not take effect for velocity closed-loop
63 * controls.
64 *
65 * \details This can be used to implement a closed-loop deadband or,
66 * less commonly, to switch to weaker gains when close to the target.
67 *
68 * - Minimum Value: 0.0
69 * - Maximum Value: 1.0
70 * - Default Value: 0.0
71 * - Units: rotations
72 */
73 wpi::units::turn_t GainSchedErrorThreshold = 0.0_tr;
74 /**
75 * \brief The behavior of kP output as the error crosses the
76 * GainSchedErrorThreshold during gain scheduling. The output of kP
77 * can be adjusted to maintain continuity in output, or it can be left
78 * discontinuous.
79 *
80 * - Default Value: signals#GainSchedKpBehaviorValue#Continuous
81 */
83
84 /**
85 * \brief Modifies this configuration's ContinuousWrap parameter and returns itself for
86 * method-chaining and easier to use config API.
87 *
88 * Wrap position error within [-0.5, +0.5) mechanism rotations.
89 * Typically used for continuous position closed-loops like swerve
90 * azimuth.
91 *
92 * \details This uses the mechanism rotation value. If there is a gear
93 * ratio between the sensor and the mechanism, make sure to apply a
94 * SensorToMechanismRatio so the closed loop operates on the full
95 * rotation.
96 *
97 * - Default Value: False
98 *
99 * \param newContinuousWrap Parameter to modify
100 * \returns Itself
101 */
102 constexpr ClosedLoopGeneralConfigs &WithContinuousWrap(bool newContinuousWrap)
103 {
104 ContinuousWrap = std::move(newContinuousWrap);
105 return *this;
106 }
107
108 /**
109 * \brief Modifies this configuration's DifferentialContinuousWrap parameter and returns itself for
110 * method-chaining and easier to use config API.
111 *
112 * Wrap differential difference position error within [-0.5, +0.5)
113 * mechanism rotations. Typically used for continuous position
114 * closed-loops like a differential wrist.
115 *
116 * \details This uses the differential difference rotation value. If
117 * there is a gear ratio on the difference axis, make sure to apply a
118 * SensorToDifferentialRatio so the closed loop operates on the full
119 * rotation.
120 *
121 * - Default Value: False
122 *
123 * \param newDifferentialContinuousWrap Parameter to modify
124 * \returns Itself
125 */
126 constexpr ClosedLoopGeneralConfigs &WithDifferentialContinuousWrap(bool newDifferentialContinuousWrap)
127 {
128 DifferentialContinuousWrap = std::move(newDifferentialContinuousWrap);
129 return *this;
130 }
131
132 /**
133 * \brief Modifies this configuration's GainSchedErrorThreshold parameter and returns itself for
134 * method-chaining and easier to use config API.
135 *
136 * The position closed-loop error threshold for gain scheduling. When
137 * the absolute value of the closed-loop error is within the threshold
138 * (inclusive), the PID controller will automatically switch gains
139 * according to the configured GainSchedBehavior of the slot.
140 *
141 * When this is zero (default), no gain scheduling will occur.
142 * Additionally, this does not take effect for velocity closed-loop
143 * controls.
144 *
145 * \details This can be used to implement a closed-loop deadband or,
146 * less commonly, to switch to weaker gains when close to the target.
147 *
148 * - Minimum Value: 0.0
149 * - Maximum Value: 1.0
150 * - Default Value: 0.0
151 * - Units: rotations
152 *
153 * \param newGainSchedErrorThreshold Parameter to modify
154 * \returns Itself
155 */
156 constexpr ClosedLoopGeneralConfigs &WithGainSchedErrorThreshold(wpi::units::turn_t newGainSchedErrorThreshold)
157 {
158 GainSchedErrorThreshold = std::move(newGainSchedErrorThreshold);
159 return *this;
160 }
161
162 /**
163 * \brief Modifies this configuration's GainSchedKpBehavior parameter and returns itself for
164 * method-chaining and easier to use config API.
165 *
166 * The behavior of kP output as the error crosses the
167 * GainSchedErrorThreshold during gain scheduling. The output of kP
168 * can be adjusted to maintain continuity in output, or it can be left
169 * discontinuous.
170 *
171 * - Default Value: signals#GainSchedKpBehaviorValue#Continuous
172 *
173 * \param newGainSchedKpBehavior Parameter to modify
174 * \returns Itself
175 */
177 {
178 GainSchedKpBehavior = std::move(newGainSchedKpBehavior);
179 return *this;
180 }
181
182
183
184 std::string ToString() const override;
185
186 std::string Serialize() const final;
187 ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final;
188};
189
190}
191}
192}
signals::GainSchedKpBehaviorValue GainSchedKpBehavior
The behavior of kP output as the error crosses the GainSchedErrorThreshold during gain scheduling.
Definition ClosedLoopGeneralConfigs.hpp:82
bool ContinuousWrap
Wrap position error within [-0.5, +0.5) mechanism rotations.
Definition ClosedLoopGeneralConfigs.hpp:40
wpi::units::turn_t GainSchedErrorThreshold
The position closed-loop error threshold for gain scheduling.
Definition ClosedLoopGeneralConfigs.hpp:73
constexpr ClosedLoopGeneralConfigs & WithContinuousWrap(bool newContinuousWrap)
Modifies this configuration's ContinuousWrap parameter and returns itself for method-chaining and eas...
Definition ClosedLoopGeneralConfigs.hpp:102
constexpr ClosedLoopGeneralConfigs & WithDifferentialContinuousWrap(bool newDifferentialContinuousWrap)
Modifies this configuration's DifferentialContinuousWrap parameter and returns itself for method-chai...
Definition ClosedLoopGeneralConfigs.hpp:126
ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final
bool DifferentialContinuousWrap
Wrap differential difference position error within [-0.5, +0.5) mechanism rotations.
Definition ClosedLoopGeneralConfigs.hpp:53
constexpr ClosedLoopGeneralConfigs & WithGainSchedKpBehavior(signals::GainSchedKpBehaviorValue newGainSchedKpBehavior)
Modifies this configuration's GainSchedKpBehavior parameter and returns itself for method-chaining an...
Definition ClosedLoopGeneralConfigs.hpp:176
constexpr ClosedLoopGeneralConfigs & WithGainSchedErrorThreshold(wpi::units::turn_t newGainSchedErrorThreshold)
Modifies this configuration's GainSchedErrorThreshold parameter and returns itself for method-chainin...
Definition ClosedLoopGeneralConfigs.hpp:156
Definition Configuration.hpp:17
Definition ExternalFeedbackConfigs.hpp:21
Definition ExternalFeedbackConfigs.hpp:16
Definition FrcUsageReport.hpp:12
Definition motor_constants.h:14
The behavior of kP output as the error crosses the GainSchedErrorThreshold during gain scheduling.
Definition SpnEnums.hpp:4995
static constexpr int Continuous
The gain scheduler will maintain continuity in the kP output as the error crosses the gain threshold.
Definition SpnEnums.hpp:5004