CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
DifferentialConstants.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
12namespace ctre {
13namespace phoenix6 {
14namespace mechanisms {
15
16/**
17 * \brief Sensor sources for a differential Pigeon 2.
18 */
20 /**
21 * \brief Use the yaw component of the Pigeon 2.
22 */
23 Yaw,
24 /**
25 * \brief Use the pitch component of the Pigeon 2.
26 */
27 Pitch,
28 /**
29 * \brief Use the roll component of the Pigeon 2.
30 */
31 Roll,
32};
33
34/**
35 * \brief Sensor sources for a differential CTR Electronics'
36 * CANdi™ branded device.
37 */
39 /**
40 * \brief Use a pulse-width encoder remotely attached to the Sensor Input 1 (S1IN).
41 */
42 PWM1,
43 /**
44 * \brief Use a pulse-width encoder remotely attached to the Sensor Input 2 (S2IN).
45 */
46 PWM2,
47 /**
48 * \brief Use a quadrature encoder remotely attached to the two Sensor Inputs.
49 */
51};
52
53/**
54 * \brief All constants for setting up the motors of a differential mechanism.
55 */
56template <std::derived_from<configs::ParentConfiguration> MotorConfigsT>
58 constexpr DifferentialMotorConstants() = default;
59
60 /**
61 * \brief Name of the CAN bus the mechanism is on. Possible CAN bus strings are:
62 *
63 * - "rio" for the native roboRIO CAN bus
64 * - CANivore name or serial number
65 * - SocketCAN interface (non-FRC Linux only)
66 * - "*" for any CANivore seen by the program
67 * - empty string (default) to select the default for the system:
68 * - "rio" on roboRIO
69 * - "can0" on Linux
70 * - "*" on Windows
71 *
72 * Note that all devices must be on the same CAN bus.
73 */
74 std::string_view CANBusName = "";
75 /**
76 * \brief CAN ID of the leader motor in the differential mechanism. The leader
77 * will have the differential output added to its regular output.
78 */
79 int LeaderId = 0;
80 /**
81 * \brief CAN ID of the follower motor in the differential mechanism. The
82 * follower will have the differential output subtracted from its regular
83 * output.
84 */
85 int FollowerId = 0;
86 /**
87 * \brief The alignment of the differential leader and follower motors, ignoring
88 * the configured inverts.
89 */
91 /**
92 * \brief The ratio of sensor rotations to the differential mechanism's
93 * difference output, where a ratio greater than 1 is a reduction.
94 *
95 * When not using a separate sensor on the difference axis, the sensor is
96 * considered half of the difference between the two motor controllers'
97 * mechanism positions/velocities. As a result, this should be set to the gear
98 * ratio on the difference axis in that scenario, or any gear ratio between the
99 * sensor and the mechanism differential when using another sensor source.
100 */
101 units::dimensionless::scalar_t SensorToDifferentialRatio = 1.0;
102 /**
103 * \brief The update rate of the closed-loop controllers. This determines the
104 * update rate of the differential leader's DifferentialOutput status signal,
105 * the follower's Position and Velocity signals, and the relevant signals for
106 * any other selected differential sensor.
107 */
108 units::frequency::hertz_t ClosedLoopRate = 100_Hz;
109 /**
110 * \brief The initial configs used to configure the differential leader. The
111 * default value is the factory-default.
112 *
113 * Users may change the initial configuration as they need. Any config that's
114 * not referenced in the DifferentialMotorConstants class is available to be
115 * changed.
116 *
117 * The list of configs that will be overwritten is as follows:
118 *
119 * - configs#DifferentialSensorsConfigs (automatic based on the devices used)
120 *
121 */
122 MotorConfigsT LeaderInitialConfigs = {};
123 /**
124 * \brief The initial configs used to configure the differential follower. The
125 * default value is the factory-default.
126 *
127 * Users may change the initial configuration as they need. Any config that's
128 * not referenced in the DifferentialMotorConstants class is available to be
129 * changed.
130 *
131 * The list of configs that will be overwritten is as follows:
132 *
133 * - configs#DifferentialSensorsConfigs (factory defaulted)
134 * - configs#MotorOutputConfigs#Inverted (determined from #Alignment and the
135 * #LeaderInitialConfigs invert)
136 *
137 * If #FollowerUsesCommonLeaderConfigs is set to true (default), the following
138 * configs are copied from #LeaderInitialConfigs:
139 *
140 * - configs#AudioConfigs
141 * - configs#CurrentLimitsConfigs
142 * - configs#MotorOutputConfigs (except configs#MotorOutputConfigs#Inverted)
143 * - configs#TorqueCurrentConfigs
144 * - configs#VoltageConfigs
145 *
146 */
147 MotorConfigsT FollowerInitialConfigs = {};
148 /**
149 * \brief Whether the follower should overwrite some of its initial configs with
150 * common configs from the #LeaderInitialConfigs, such as current limits. The
151 * list of configs that are copied is documented in #FollowerInitialConfigs.
152 */
154
155 /**
156 * \brief Modifies the CANBusName parameter and returns itself.
157 *
158 * Name of the CAN bus the mechanism is on. Possible CAN bus strings are:
159 *
160 * - "rio" for the native roboRIO CAN bus
161 * - CANivore name or serial number
162 * - SocketCAN interface (non-FRC Linux only)
163 * - "*" for any CANivore seen by the program
164 * - empty string (default) to select the default for the system:
165 * - "rio" on roboRIO
166 * - "can0" on Linux
167 * - "*" on Windows
168 *
169 * Note that all devices must be on the same CAN bus.
170 *
171 * \param newCANBusName Parameter to modify
172 * \returns this object
173 */
174 constexpr DifferentialMotorConstants<MotorConfigsT> &WithCANBusName(std::string_view newCANBusName)
175 {
176 this->CANBusName = newCANBusName;
177 return *this;
178 }
179
180 /**
181 * \brief Modifies the LeaderId parameter and returns itself.
182 *
183 * CAN ID of the leader motor in the differential mechanism. The leader will
184 * have the differential output added to its regular output.
185 *
186 * \param newLeaderId Parameter to modify
187 * \returns this object
188 */
190 {
191 this->LeaderId = newLeaderId;
192 return *this;
193 }
194
195 /**
196 * \brief Modifies the FollowerId parameter and returns itself.
197 *
198 * CAN ID of the follower motor in the differential mechanism. The follower will
199 * have the differential output subtracted from its regular output.
200 *
201 * \param newFollowerId Parameter to modify
202 * \returns this object
203 */
205 {
206 this->FollowerId = newFollowerId;
207 return *this;
208 }
209
210 /**
211 * \brief Modifies the Alignment parameter and returns itself.
212 *
213 * The alignment of the differential leader and follower motors, ignoring the
214 * configured inverts.
215 *
216 * \param newAlignment Parameter to modify
217 * \returns this object
218 */
220 {
221 this->Alignment = newAlignment;
222 return *this;
223 }
224
225 /**
226 * \brief Modifies the SensorToDifferentialRatio parameter and returns itself.
227 *
228 * The ratio of sensor rotations to the differential mechanism's difference
229 * output, where a ratio greater than 1 is a reduction.
230 *
231 * When not using a separate sensor on the difference axis, the sensor is
232 * considered half of the difference between the two motor controllers'
233 * mechanism positions/velocities. As a result, this should be set to the gear
234 * ratio on the difference axis in that scenario, or any gear ratio between the
235 * sensor and the mechanism differential when using another sensor source.
236 *
237 * \param newSensorToDifferentialRatio Parameter to modify
238 * \returns this object
239 */
240 constexpr DifferentialMotorConstants<MotorConfigsT> &WithSensorToDifferentialRatio(units::dimensionless::scalar_t newSensorToDifferentialRatio)
241 {
242 this->SensorToDifferentialRatio = newSensorToDifferentialRatio;
243 return *this;
244 }
245
246 /**
247 * \brief Modifies the ClosedLoopRate parameter and returns itself.
248 *
249 * The update rate of the closed-loop controllers. This determines the update
250 * rate of the differential leader's DifferentialOutput status signal, the
251 * follower's Position and Velocity signals, and the relevant signals for any
252 * other selected differential sensor.
253 *
254 * \param newClosedLoopRate Parameter to modify
255 * \returns this object
256 */
257 constexpr DifferentialMotorConstants<MotorConfigsT> &WithClosedLoopRate(units::frequency::hertz_t newClosedLoopRate)
258 {
259 this->ClosedLoopRate = newClosedLoopRate;
260 return *this;
261 }
262
263 /**
264 * \brief Modifies the LeaderInitialConfigs parameter and returns itself.
265 *
266 * The initial configs used to configure the differential leader. The default
267 * value is the factory-default.
268 *
269 * Users may change the initial configuration as they need. Any config that's
270 * not referenced in the DifferentialMotorConstants class is available to be
271 * changed.
272 *
273 * The list of configs that will be overwritten is as follows:
274 *
275 * - configs#DifferentialSensorsConfigs (automatic based on the devices used)
276 *
277 *
278 * \param newLeaderInitialConfigs Parameter to modify
279 * \returns this object
280 */
281 constexpr DifferentialMotorConstants<MotorConfigsT> &WithLeaderInitialConfigs(const MotorConfigsT& newLeaderInitialConfigs)
282 {
283 this->LeaderInitialConfigs = newLeaderInitialConfigs;
284 return *this;
285 }
286
287 /**
288 * \brief Modifies the FollowerInitialConfigs parameter and returns itself.
289 *
290 * The initial configs used to configure the differential follower. The default
291 * value is the factory-default.
292 *
293 * Users may change the initial configuration as they need. Any config that's
294 * not referenced in the DifferentialMotorConstants class is available to be
295 * changed.
296 *
297 * The list of configs that will be overwritten is as follows:
298 *
299 * - configs#DifferentialSensorsConfigs (factory defaulted)
300 * - configs#MotorOutputConfigs#Inverted (determined from #Alignment and the
301 * #LeaderInitialConfigs invert)
302 *
303 * If #FollowerUsesCommonLeaderConfigs is set to true (default), the following
304 * configs are copied from #LeaderInitialConfigs:
305 *
306 * - configs#AudioConfigs
307 * - configs#CurrentLimitsConfigs
308 * - configs#MotorOutputConfigs (except configs#MotorOutputConfigs#Inverted)
309 * - configs#TorqueCurrentConfigs
310 * - configs#VoltageConfigs
311 *
312 *
313 * \param newFollowerInitialConfigs Parameter to modify
314 * \returns this object
315 */
316 constexpr DifferentialMotorConstants<MotorConfigsT> &WithFollowerInitialConfigs(const MotorConfigsT& newFollowerInitialConfigs)
317 {
318 this->FollowerInitialConfigs = newFollowerInitialConfigs;
319 return *this;
320 }
321
322 /**
323 * \brief Modifies the FollowerUsesCommonLeaderConfigs parameter and returns itself.
324 *
325 * Whether the follower should overwrite some of its initial configs with common
326 * configs from the #LeaderInitialConfigs, such as current limits. The list of
327 * configs that are copied is documented in #FollowerInitialConfigs.
328 *
329 * \param newFollowerUsesCommonLeaderConfigs Parameter to modify
330 * \returns this object
331 */
332 constexpr DifferentialMotorConstants<MotorConfigsT> &WithFollowerUsesCommonLeaderConfigs(bool newFollowerUsesCommonLeaderConfigs)
333 {
334 this->FollowerUsesCommonLeaderConfigs = newFollowerUsesCommonLeaderConfigs;
335 return *this;
336 }
337};
338
339}
340}
341}
DifferentialPigeon2Source
Sensor sources for a differential Pigeon 2.
Definition DifferentialConstants.hpp:19
@ Roll
Use the roll component of the Pigeon 2.
@ Pitch
Use the pitch component of the Pigeon 2.
@ Yaw
Use the yaw component of the Pigeon 2.
DifferentialCANdiSource
Sensor sources for a differential CTR Electronics' CANdi™ branded device.
Definition DifferentialConstants.hpp:38
@ PWM1
Use a pulse-width encoder remotely attached to the Sensor Input 1 (S1IN).
@ Quadrature
Use a quadrature encoder remotely attached to the two Sensor Inputs.
@ PWM2
Use a pulse-width encoder remotely attached to the Sensor Input 2 (S2IN).
Definition motor_constants.h:14
All constants for setting up the motors of a differential mechanism.
Definition DifferentialConstants.hpp:57
int FollowerId
CAN ID of the follower motor in the differential mechanism.
Definition DifferentialConstants.hpp:85
units::dimensionless::scalar_t SensorToDifferentialRatio
The ratio of sensor rotations to the differential mechanism's difference output, where a ratio greate...
Definition DifferentialConstants.hpp:101
bool FollowerUsesCommonLeaderConfigs
Whether the follower should overwrite some of its initial configs with common configs from the Leader...
Definition DifferentialConstants.hpp:153
signals::MotorAlignmentValue Alignment
The alignment of the differential leader and follower motors, ignoring the configured inverts.
Definition DifferentialConstants.hpp:90
units::frequency::hertz_t ClosedLoopRate
The update rate of the closed-loop controllers.
Definition DifferentialConstants.hpp:108
constexpr DifferentialMotorConstants< MotorConfigsT > & WithFollowerInitialConfigs(const MotorConfigsT &newFollowerInitialConfigs)
Modifies the FollowerInitialConfigs parameter and returns itself.
Definition DifferentialConstants.hpp:316
MotorConfigsT FollowerInitialConfigs
The initial configs used to configure the differential follower.
Definition DifferentialConstants.hpp:147
constexpr DifferentialMotorConstants< MotorConfigsT > & WithSensorToDifferentialRatio(units::dimensionless::scalar_t newSensorToDifferentialRatio)
Modifies the SensorToDifferentialRatio parameter and returns itself.
Definition DifferentialConstants.hpp:240
std::string_view CANBusName
Name of the CAN bus the mechanism is on.
Definition DifferentialConstants.hpp:74
constexpr DifferentialMotorConstants< MotorConfigsT > & WithClosedLoopRate(units::frequency::hertz_t newClosedLoopRate)
Modifies the ClosedLoopRate parameter and returns itself.
Definition DifferentialConstants.hpp:257
constexpr DifferentialMotorConstants< MotorConfigsT > & WithLeaderInitialConfigs(const MotorConfigsT &newLeaderInitialConfigs)
Modifies the LeaderInitialConfigs parameter and returns itself.
Definition DifferentialConstants.hpp:281
constexpr DifferentialMotorConstants< MotorConfigsT > & WithLeaderId(int newLeaderId)
Modifies the LeaderId parameter and returns itself.
Definition DifferentialConstants.hpp:189
constexpr DifferentialMotorConstants< MotorConfigsT > & WithFollowerUsesCommonLeaderConfigs(bool newFollowerUsesCommonLeaderConfigs)
Modifies the FollowerUsesCommonLeaderConfigs parameter and returns itself.
Definition DifferentialConstants.hpp:332
constexpr DifferentialMotorConstants< MotorConfigsT > & WithAlignment(signals::MotorAlignmentValue newAlignment)
Modifies the Alignment parameter and returns itself.
Definition DifferentialConstants.hpp:219
constexpr DifferentialMotorConstants< MotorConfigsT > & WithFollowerId(int newFollowerId)
Modifies the FollowerId parameter and returns itself.
Definition DifferentialConstants.hpp:204
constexpr DifferentialMotorConstants< MotorConfigsT > & WithCANBusName(std::string_view newCANBusName)
Modifies the CANBusName parameter and returns itself.
Definition DifferentialConstants.hpp:174
int LeaderId
CAN ID of the leader motor in the differential mechanism.
Definition DifferentialConstants.hpp:79
MotorConfigsT LeaderInitialConfigs
The initial configs used to configure the differential leader.
Definition DifferentialConstants.hpp:122
The relationship between two motors in a mechanism.
Definition SpnEnums.hpp:5130
static constexpr int Aligned
The two motor directions are aligned.
Definition SpnEnums.hpp:5137