CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
CurrentLimitsConfigs.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/current.h>
11#include <units/time.h>
12
13namespace ctre {
14namespace phoenix6 {
15
16
17namespace configs {
18
19/**
20 * \brief Configs that directly affect current limiting features.
21 *
22 * \details Contains the supply/stator current limit thresholds and
23 * whether to enable them.
24 */
26public:
27 constexpr CurrentLimitsConfigs() = default;
28
29 /**
30 * \brief The amount of current allowed in the motor (motoring and
31 * regen current). Note this requires StatorCurrentLimitEnable to be
32 * true.
33 *
34 * For torque current control, this is applied in addition to the
35 * PeakForwardTorqueCurrent and PeakReverseTorqueCurrent in
36 * TorqueCurrentConfigs.
37 *
38 * Stator current is directly proportional to torque, so this limit
39 * can be used to restrict the torque output of the motor, such as
40 * preventing wheel slip for a drivetrain. Additionally, stator
41 * current limits can prevent brownouts during acceleration; supply
42 * current will never exceed the stator current limit and is often
43 * significantly lower than stator current.
44 *
45 * A reasonable starting point for a stator current limit is 120 A,
46 * with values commonly ranging from 80-160 A. Mechanisms with a hard
47 * stop may need a smaller limit to reduce the torque applied when
48 * running into the hard stop.
49 *
50 * - Minimum Value: 0.0
51 * - Maximum Value: 800.0
52 * - Default Value: 120
53 * - Units: A
54 */
55 units::current::ampere_t StatorCurrentLimit = 120_A;
56 /**
57 * \brief Enable motor stator current limiting.
58 *
59 * - Default Value: True
60 */
62 /**
63 * \brief The absolute maximum amount of supply current allowed. Note
64 * this requires SupplyCurrentLimitEnable to be true. Use
65 * SupplyCurrentLowerLimit and SupplyCurrentLowerTime to reduce the
66 * supply current limit after the time threshold is exceeded.
67 *
68 * Supply current is the current drawn from the battery, so this limit
69 * can be used to prevent breaker trips and improve battery longevity.
70 * Additionally, in scenarios where the robot experiences brownouts
71 * despite configuring stator current limits, a supply current limit
72 * can further help avoid brownouts. However, it is important to note
73 * that such brownouts may be caused by a bad battery or poor power
74 * wiring.
75 *
76 * A reasonable starting point for a supply current limit is 70 A with
77 * a lower limit of 40 A after 1.0 second. Supply current limits
78 * commonly range from 20-80 A depending on the breaker used.
79 *
80 * - Minimum Value: 0.0
81 * - Maximum Value: 800.0
82 * - Default Value: 70
83 * - Units: A
84 */
85 units::current::ampere_t SupplyCurrentLimit = 70_A;
86 /**
87 * \brief Enable motor supply current limiting.
88 *
89 * - Default Value: True
90 */
92 /**
93 * \brief The amount of supply current allowed after the regular
94 * SupplyCurrentLimit is active for longer than
95 * SupplyCurrentLowerTime. This allows higher current draws for a
96 * fixed period of time before reducing the current limit to protect
97 * breakers. This has no effect if SupplyCurrentLimit is lower than
98 * this value or SupplyCurrentLowerTime is 0.
99 *
100 * - Minimum Value: 0.0
101 * - Maximum Value: 500
102 * - Default Value: 40
103 * - Units: A
104 */
105 units::current::ampere_t SupplyCurrentLowerLimit = 40_A;
106 /**
107 * \brief Reduces supply current to the SupplyCurrentLowerLimit after
108 * limiting to SupplyCurrentLimit for this period of time. If this is
109 * set to 0, SupplyCurrentLowerLimit will be ignored.
110 *
111 * - Minimum Value: 0.0
112 * - Maximum Value: 5.0
113 * - Default Value: 1.0
114 * - Units: seconds
115 */
116 units::time::second_t SupplyCurrentLowerTime = 1.0_s;
117
118 /**
119 * \brief Modifies this configuration's StatorCurrentLimit parameter and returns itself for
120 * method-chaining and easier to use config API.
121 *
122 * The amount of current allowed in the motor (motoring and regen
123 * current). Note this requires StatorCurrentLimitEnable to be true.
124 *
125 * For torque current control, this is applied in addition to the
126 * PeakForwardTorqueCurrent and PeakReverseTorqueCurrent in
127 * TorqueCurrentConfigs.
128 *
129 * Stator current is directly proportional to torque, so this limit
130 * can be used to restrict the torque output of the motor, such as
131 * preventing wheel slip for a drivetrain. Additionally, stator
132 * current limits can prevent brownouts during acceleration; supply
133 * current will never exceed the stator current limit and is often
134 * significantly lower than stator current.
135 *
136 * A reasonable starting point for a stator current limit is 120 A,
137 * with values commonly ranging from 80-160 A. Mechanisms with a hard
138 * stop may need a smaller limit to reduce the torque applied when
139 * running into the hard stop.
140 *
141 * - Minimum Value: 0.0
142 * - Maximum Value: 800.0
143 * - Default Value: 120
144 * - Units: A
145 *
146 * \param newStatorCurrentLimit Parameter to modify
147 * \returns Itself
148 */
149 constexpr CurrentLimitsConfigs &WithStatorCurrentLimit(units::current::ampere_t newStatorCurrentLimit)
150 {
151 StatorCurrentLimit = std::move(newStatorCurrentLimit);
152 return *this;
153 }
154
155 /**
156 * \brief Modifies this configuration's StatorCurrentLimitEnable parameter and returns itself for
157 * method-chaining and easier to use config API.
158 *
159 * Enable motor stator current limiting.
160 *
161 * - Default Value: True
162 *
163 * \param newStatorCurrentLimitEnable Parameter to modify
164 * \returns Itself
165 */
166 constexpr CurrentLimitsConfigs &WithStatorCurrentLimitEnable(bool newStatorCurrentLimitEnable)
167 {
168 StatorCurrentLimitEnable = std::move(newStatorCurrentLimitEnable);
169 return *this;
170 }
171
172 /**
173 * \brief Modifies this configuration's SupplyCurrentLimit parameter and returns itself for
174 * method-chaining and easier to use config API.
175 *
176 * The absolute maximum amount of supply current allowed. Note this
177 * requires SupplyCurrentLimitEnable to be true. Use
178 * SupplyCurrentLowerLimit and SupplyCurrentLowerTime to reduce the
179 * supply current limit after the time threshold is exceeded.
180 *
181 * Supply current is the current drawn from the battery, so this limit
182 * can be used to prevent breaker trips and improve battery longevity.
183 * Additionally, in scenarios where the robot experiences brownouts
184 * despite configuring stator current limits, a supply current limit
185 * can further help avoid brownouts. However, it is important to note
186 * that such brownouts may be caused by a bad battery or poor power
187 * wiring.
188 *
189 * A reasonable starting point for a supply current limit is 70 A with
190 * a lower limit of 40 A after 1.0 second. Supply current limits
191 * commonly range from 20-80 A depending on the breaker used.
192 *
193 * - Minimum Value: 0.0
194 * - Maximum Value: 800.0
195 * - Default Value: 70
196 * - Units: A
197 *
198 * \param newSupplyCurrentLimit Parameter to modify
199 * \returns Itself
200 */
201 constexpr CurrentLimitsConfigs &WithSupplyCurrentLimit(units::current::ampere_t newSupplyCurrentLimit)
202 {
203 SupplyCurrentLimit = std::move(newSupplyCurrentLimit);
204 return *this;
205 }
206
207 /**
208 * \brief Modifies this configuration's SupplyCurrentLimitEnable parameter and returns itself for
209 * method-chaining and easier to use config API.
210 *
211 * Enable motor supply current limiting.
212 *
213 * - Default Value: True
214 *
215 * \param newSupplyCurrentLimitEnable Parameter to modify
216 * \returns Itself
217 */
218 constexpr CurrentLimitsConfigs &WithSupplyCurrentLimitEnable(bool newSupplyCurrentLimitEnable)
219 {
220 SupplyCurrentLimitEnable = std::move(newSupplyCurrentLimitEnable);
221 return *this;
222 }
223
224 /**
225 * \brief Modifies this configuration's SupplyCurrentLowerLimit parameter and returns itself for
226 * method-chaining and easier to use config API.
227 *
228 * The amount of supply current allowed after the regular
229 * SupplyCurrentLimit is active for longer than
230 * SupplyCurrentLowerTime. This allows higher current draws for a
231 * fixed period of time before reducing the current limit to protect
232 * breakers. This has no effect if SupplyCurrentLimit is lower than
233 * this value or SupplyCurrentLowerTime is 0.
234 *
235 * - Minimum Value: 0.0
236 * - Maximum Value: 500
237 * - Default Value: 40
238 * - Units: A
239 *
240 * \param newSupplyCurrentLowerLimit Parameter to modify
241 * \returns Itself
242 */
243 constexpr CurrentLimitsConfigs &WithSupplyCurrentLowerLimit(units::current::ampere_t newSupplyCurrentLowerLimit)
244 {
245 SupplyCurrentLowerLimit = std::move(newSupplyCurrentLowerLimit);
246 return *this;
247 }
248
249 /**
250 * \brief Modifies this configuration's SupplyCurrentLowerTime parameter and returns itself for
251 * method-chaining and easier to use config API.
252 *
253 * Reduces supply current to the SupplyCurrentLowerLimit after
254 * limiting to SupplyCurrentLimit for this period of time. If this is
255 * set to 0, SupplyCurrentLowerLimit will be ignored.
256 *
257 * - Minimum Value: 0.0
258 * - Maximum Value: 5.0
259 * - Default Value: 1.0
260 * - Units: seconds
261 *
262 * \param newSupplyCurrentLowerTime Parameter to modify
263 * \returns Itself
264 */
265 constexpr CurrentLimitsConfigs &WithSupplyCurrentLowerTime(units::time::second_t newSupplyCurrentLowerTime)
266 {
267 SupplyCurrentLowerTime = std::move(newSupplyCurrentLowerTime);
268 return *this;
269 }
270
271
272
273 std::string ToString() const override;
274
275 std::string Serialize() const final;
276 ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final;
277};
278
279}
280}
281}
Configs that directly affect current limiting features.
Definition CurrentLimitsConfigs.hpp:25
bool StatorCurrentLimitEnable
Enable motor stator current limiting.
Definition CurrentLimitsConfigs.hpp:61
constexpr CurrentLimitsConfigs & WithSupplyCurrentLimitEnable(bool newSupplyCurrentLimitEnable)
Modifies this configuration's SupplyCurrentLimitEnable parameter and returns itself for method-chaini...
Definition CurrentLimitsConfigs.hpp:218
constexpr CurrentLimitsConfigs & WithSupplyCurrentLimit(units::current::ampere_t newSupplyCurrentLimit)
Modifies this configuration's SupplyCurrentLimit parameter and returns itself for method-chaining and...
Definition CurrentLimitsConfigs.hpp:201
ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final
units::current::ampere_t SupplyCurrentLimit
The absolute maximum amount of supply current allowed.
Definition CurrentLimitsConfigs.hpp:85
units::current::ampere_t StatorCurrentLimit
The amount of current allowed in the motor (motoring and regen current).
Definition CurrentLimitsConfigs.hpp:55
constexpr CurrentLimitsConfigs & WithSupplyCurrentLowerTime(units::time::second_t newSupplyCurrentLowerTime)
Modifies this configuration's SupplyCurrentLowerTime parameter and returns itself for method-chaining...
Definition CurrentLimitsConfigs.hpp:265
constexpr CurrentLimitsConfigs & WithSupplyCurrentLowerLimit(units::current::ampere_t newSupplyCurrentLowerLimit)
Modifies this configuration's SupplyCurrentLowerLimit parameter and returns itself for method-chainin...
Definition CurrentLimitsConfigs.hpp:243
constexpr CurrentLimitsConfigs & WithStatorCurrentLimit(units::current::ampere_t newStatorCurrentLimit)
Modifies this configuration's StatorCurrentLimit parameter and returns itself for method-chaining and...
Definition CurrentLimitsConfigs.hpp:149
units::current::ampere_t SupplyCurrentLowerLimit
The amount of supply current allowed after the regular SupplyCurrentLimit is active for longer than S...
Definition CurrentLimitsConfigs.hpp:105
std::string ToString() const override
bool SupplyCurrentLimitEnable
Enable motor supply current limiting.
Definition CurrentLimitsConfigs.hpp:91
constexpr CurrentLimitsConfigs & WithStatorCurrentLimitEnable(bool newStatorCurrentLimitEnable)
Modifies this configuration's StatorCurrentLimitEnable parameter and returns itself for method-chaini...
Definition CurrentLimitsConfigs.hpp:166
units::time::second_t SupplyCurrentLowerTime
Reduces supply current to the SupplyCurrentLowerLimit after limiting to SupplyCurrentLimit for this p...
Definition CurrentLimitsConfigs.hpp:116
Definition Configuration.hpp:17
Definition motor_constants.h:14