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