CTRE Phoenix 6 C++ 26.0.0-beta-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 <units/angle.h>
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 units::angle::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 */
82
83 /**
84 * \brief Modifies this configuration's ContinuousWrap parameter and returns itself for
85 * method-chaining and easier to use config API.
86 *
87 * Wrap position error within [-0.5, +0.5) mechanism rotations.
88 * Typically used for continuous position closed-loops like swerve
89 * azimuth.
90 *
91 * \details This uses the mechanism rotation value. If there is a gear
92 * ratio between the sensor and the mechanism, make sure to apply a
93 * SensorToMechanismRatio so the closed loop operates on the full
94 * rotation.
95 *
96 * - Default Value: False
97 *
98 * \param newContinuousWrap Parameter to modify
99 * \returns Itself
100 */
101 constexpr ClosedLoopGeneralConfigs &WithContinuousWrap(bool newContinuousWrap)
102 {
103 ContinuousWrap = std::move(newContinuousWrap);
104 return *this;
105 }
106
107 /**
108 * \brief Modifies this configuration's DifferentialContinuousWrap parameter and returns itself for
109 * method-chaining and easier to use config API.
110 *
111 * Wrap differential difference position error within [-0.5, +0.5)
112 * mechanism rotations. Typically used for continuous position
113 * closed-loops like a differential wrist.
114 *
115 * \details This uses the differential difference rotation value. If
116 * there is a gear ratio on the difference axis, make sure to apply a
117 * SensorToDifferentialRatio so the closed loop operates on the full
118 * rotation.
119 *
120 * - Default Value: False
121 *
122 * \param newDifferentialContinuousWrap Parameter to modify
123 * \returns Itself
124 */
125 constexpr ClosedLoopGeneralConfigs &WithDifferentialContinuousWrap(bool newDifferentialContinuousWrap)
126 {
127 DifferentialContinuousWrap = std::move(newDifferentialContinuousWrap);
128 return *this;
129 }
130
131 /**
132 * \brief Modifies this configuration's GainSchedErrorThreshold parameter and returns itself for
133 * method-chaining and easier to use config API.
134 *
135 * The position closed-loop error threshold for gain scheduling. When
136 * the absolute value of the closed-loop error is within the threshold
137 * (inclusive), the PID controller will automatically switch gains
138 * according to the configured GainSchedBehavior of the slot.
139 *
140 * When this is zero (default), no gain scheduling will occur.
141 * Additionally, this does not take effect for velocity closed-loop
142 * controls.
143 *
144 * \details This can be used to implement a closed-loop deadband or,
145 * less commonly, to switch to weaker gains when close to the target.
146 *
147 * - Minimum Value: 0.0
148 * - Maximum Value: 1.0
149 * - Default Value: 0.0
150 * - Units: rotations
151 *
152 * \param newGainSchedErrorThreshold Parameter to modify
153 * \returns Itself
154 */
155 constexpr ClosedLoopGeneralConfigs &WithGainSchedErrorThreshold(units::angle::turn_t newGainSchedErrorThreshold)
156 {
157 GainSchedErrorThreshold = std::move(newGainSchedErrorThreshold);
158 return *this;
159 }
160
161 /**
162 * \brief Modifies this configuration's GainSchedKpBehavior parameter and returns itself for
163 * method-chaining and easier to use config API.
164 *
165 * The behavior of kP output as the error crosses the
166 * GainSchedErrorThreshold during gain scheduling. The output of kP
167 * can be adjusted to maintain continuity in output, or it can be left
168 * discontinuous.
169 *
170 *
171 * \param newGainSchedKpBehavior Parameter to modify
172 * \returns Itself
173 */
175 {
176 GainSchedKpBehavior = std::move(newGainSchedKpBehavior);
177 return *this;
178 }
179
180
181
182 std::string ToString() const override;
183
184 std::string Serialize() const final;
185 ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final;
186};
187
188}
189}
190}
Configs that affect general behavior during closed-looping.
Definition ClosedLoopGeneralConfigs.hpp:24
signals::GainSchedKpBehaviorValue GainSchedKpBehavior
The behavior of kP output as the error crosses the GainSchedErrorThreshold during gain scheduling.
Definition ClosedLoopGeneralConfigs.hpp:81
bool ContinuousWrap
Wrap position error within [-0.5, +0.5) mechanism rotations.
Definition ClosedLoopGeneralConfigs.hpp:40
constexpr ClosedLoopGeneralConfigs & WithContinuousWrap(bool newContinuousWrap)
Modifies this configuration's ContinuousWrap parameter and returns itself for method-chaining and eas...
Definition ClosedLoopGeneralConfigs.hpp:101
constexpr ClosedLoopGeneralConfigs & WithDifferentialContinuousWrap(bool newDifferentialContinuousWrap)
Modifies this configuration's DifferentialContinuousWrap parameter and returns itself for method-chai...
Definition ClosedLoopGeneralConfigs.hpp:125
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:174
units::angle::turn_t GainSchedErrorThreshold
The position closed-loop error threshold for gain scheduling.
Definition ClosedLoopGeneralConfigs.hpp:73
constexpr ClosedLoopGeneralConfigs & WithGainSchedErrorThreshold(units::angle::turn_t newGainSchedErrorThreshold)
Modifies this configuration's GainSchedErrorThreshold parameter and returns itself for method-chainin...
Definition ClosedLoopGeneralConfigs.hpp:155
Definition Configuration.hpp:17
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