CTRE Phoenix 6 C++ 24.3.0
DifferentialMechanism.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
13#include <atomic>
14#include <optional>
15
16namespace ctre {
17namespace phoenix6 {
18namespace mechanisms {
19
20/**
21 * \brief Manages control of a two-axis differential mechanism.
22 *
23 * This mechanism requires the devices to be Pro licensed and
24 * connected to a CAN FD bus. Unlicensed users and users on a
25 * CAN 2.0 bus can use the \c SimpleDifferentialMechanism instead
26 * with limited functionality.
27 */
29public:
30 /**
31 * \brief Sensor sources for a differential Pigeon 2.
32 */
34 Yaw,
35 Pitch,
36 Roll
37 };
38
39 /**
40 * \brief Possible reasons for the mechanism to disable.
41 */
42 enum class DisabledReason {
43 /**
44 * \brief No reason given.
45 */
46 None,
47 /**
48 * \brief A remote sensor is not present on CAN Bus.
49 */
50 MissingRemoteSensor,
51 /**
52 * \brief The remote Talon FX used for differential
53 * control is not present on CAN Bus.
54 */
55 MissingDifferentialFX,
56 /**
57 * \brief A remote sensor position has overflowed. Because of the
58 * nature of remote sensors, it is possible for a remote sensor
59 * position to overflow beyond what is supported by the status signal
60 * frame. However, this is rare and cannot occur over the course of an
61 * FRC match under normal use.
62 */
63 RemoteSensorPosOverflow,
64 /**
65 * \brief A device or remote sensor has reset.
66 */
67 DeviceHasReset,
68 };
69
70 /**
71 * \brief Possible reasons for the mechanism to require
72 * user action to resume control.
73 */
74 enum class RequiresUserReason {
75 /**
76 * \brief No reason given.
77 */
78 None,
79 /**
80 * \brief A remote sensor position has overflowed. Because of the
81 * nature of remote sensors, it is possible for a remote sensor
82 * position to overflow beyond what is supported by the status signal
83 * frame. However, this is rare and cannot occur over the course of an
84 * FRC match under normal use.
85 */
86 RemoteSensorPosOverflow,
87 /**
88 * \brief A device or remote sensor has reset.
89 */
90 DeviceHasReset,
91 };
92
93private:
94 hardware::TalonFX *_diffAddFX;
95 hardware::TalonFX *_diffSubFX;
96 std::optional<hardware::Pigeon2 *> _pigeon2;
97 DifferentialPigeon2Source _pigeonSource;
98 std::optional<hardware::CANcoder *> _cancoder;
99
101
102 controls::NeutralOut _neutral{};
103 controls::CoastOut _coast{};
104 controls::StaticBrake _brake{};
105
106 std::function<bool()> _diffAddFXResetChecker;
107 std::function<bool()> _diffSubFXResetChecker;
108 std::optional<std::function<bool()>> _pigeon2ResetChecker;
109 std::optional<std::function<bool()>> _cancoderResetChecker;
110
111 bool _hasAppliedConfigs{false};
112 ctre::phoenix::StatusCode BeforeControl();
113
114 std::atomic<bool> _mechanismDisabled{false};
115 std::atomic<bool> _requiresUserAction{false};
116
117 DisabledReason _disabledReason{DisabledReason::None};
118 RequiresUserReason _requiresUserReason{RequiresUserReason::None};
119
120public:
121 /**
122 * \brief The default number of retries for config applies.
123 */
124 static constexpr int kDefaultConfigRetries = 5;
125
126 /**
127 * \brief Creates a new differential mechanism using the given two hardware#TalonFX devices.
128 * The mechanism will use the average of the two Talon FX sensors on the primary axis,
129 * and the difference between the two Talon FX sensors on the differential axis.
130 *
131 * This mechanism requires the devices to be Pro licensed and connected to a CAN FD bus.
132 * Unlicensed users and users on a CAN 2.0 bus can use the \c SimpleDifferentialMechanism
133 * instead with limited functionality.
134 *
135 * \param differentialAddFX The Talon FX that will have the differential output added to its regular output.
136 * \param differentialSubFX The Talon FX that will have the differential output subtracted from its regular output.
137 * \param motorDirectionsAlign Whether the differential motors' directions are aligned.
138 */
139 DifferentialMechanism(hardware::TalonFX &differentialAddFX, hardware::TalonFX &differentialSubFX, bool motorDirectionsAlign) :
140 _diffAddFX{&differentialAddFX},
141 _diffSubFX{&differentialSubFX},
142 _pigeon2{std::nullopt},
143 _pigeonSource{},
144 _cancoder{std::nullopt},
145 _diffFollow{_diffAddFX->GetDeviceID(), !motorDirectionsAlign},
146 _diffAddFXResetChecker{_diffAddFX->GetResetOccurredChecker()},
147 _diffSubFXResetChecker{_diffSubFX->GetResetOccurredChecker()},
148 _pigeon2ResetChecker{std::nullopt},
149 _cancoderResetChecker{std::nullopt}
150 {}
151
152 /**
153 * \brief Creates a new differential mechanism using the given two hardware#TalonFX devices and
154 * a hardware#Pigeon2. The mechanism will use the average of the two Talon FX sensors on the primary
155 * axis, and the selected Pigeon 2 sensor source on the differential axis.
156 *
157 * This mechanism requires the devices to be Pro licensed and connected to a CAN FD bus.
158 * Unlicensed users and users on a CAN 2.0 bus can use the \c SimpleDifferentialMechanism
159 * instead with limited functionality.
160 *
161 * \param differentialAddFX The Talon FX that will have the differential output added to its regular output.
162 * \param differentialSubFX The Talon FX that will have the differential output subtracted from its regular output.
163 * \param motorDirectionsAlign Whether the differential motors' directions are aligned.
164 * \param pigeon2 The Pigeon 2 to use for the differential axis.
165 * \param pigeonSource The sensor source to use for the Pigeon 2 (Yaw, Pitch, or Roll).
166 */
167 DifferentialMechanism(hardware::TalonFX &differentialAddFX, hardware::TalonFX &differentialSubFX, bool motorDirectionsAlign, hardware::Pigeon2 &pigeon2, DifferentialPigeon2Source pigeonSource) :
168 _diffAddFX{&differentialAddFX},
169 _diffSubFX{&differentialSubFX},
170 _pigeon2{&pigeon2},
171 _pigeonSource{pigeonSource},
172 _cancoder{std::nullopt},
173 _diffFollow{_diffAddFX->GetDeviceID(), !motorDirectionsAlign},
174 _diffAddFXResetChecker{_diffAddFX->GetResetOccurredChecker()},
175 _diffSubFXResetChecker{_diffSubFX->GetResetOccurredChecker()},
176 _pigeon2ResetChecker{(*_pigeon2)->GetResetOccurredChecker()},
177 _cancoderResetChecker{std::nullopt}
178 {}
179
180 /**
181 * \brief Creates a new differential mechanism using the given two hardware#TalonFX devices and
182 * a hardware#CANcoder. The mechanism will use the average of the two Talon FX sensors on the primary
183 * axis, and the CANcoder position/velocity on the differential axis.
184 *
185 * This mechanism requires the devices to be Pro licensed and connected to a CAN FD bus.
186 * Unlicensed users and users on a CAN 2.0 bus can use the \c SimpleDifferentialMechanism
187 * instead with limited functionality.
188 *
189 * \param differentialAddFX The Talon FX that will have the differential output added to its regular output.
190 * \param differentialSubFX The Talon FX that will have the differential output subtracted from its regular output.
191 * \param motorDirectionsAlign Whether the differential motors' directions are aligned.
192 * \param cancoder The CANcoder to use for the differential axis.
193 */
194 DifferentialMechanism(hardware::TalonFX &differentialAddFX, hardware::TalonFX &differentialSubFX, bool motorDirectionsAlign, hardware::CANcoder &cancoder) :
195 _diffAddFX{&differentialAddFX},
196 _diffSubFX{&differentialSubFX},
197 _pigeon2{std::nullopt},
198 _pigeonSource{},
199 _cancoder{&cancoder},
200 _diffFollow{_diffAddFX->GetDeviceID(), !motorDirectionsAlign},
201 _diffAddFXResetChecker{_diffAddFX->GetResetOccurredChecker()},
202 _diffSubFXResetChecker{_diffSubFX->GetResetOccurredChecker()},
203 _pigeon2ResetChecker{std::nullopt},
204 _cancoderResetChecker{(*_cancoder)->GetResetOccurredChecker()}
205 {}
206
207 /**
208 * \brief Get the Talon FX that is differential leader. The differential
209 * leader calculates the output for the differential follower. The differential
210 * leader is also used for fault detection, and it reports status signals for
211 * the differential controller.
212 *
213 * \returns Differential leader Talon FX
214 */
216 {
217 return *_diffAddFX;
218 }
219 /**
220 * \brief Get the Talon FX that is differential leader. The differential
221 * leader calculates the output for the differential follower. The differential
222 * leader is also useful for fault detection, and it reports status signals for
223 * the differential controller.
224 *
225 * \returns Differential leader Talon FX
226 */
228 {
229 return *_diffAddFX;
230 }
231
232 /**
233 * \brief Get the Talon FX that is differential follower. The differential
234 * follower's position and velocity are used by the differential leader
235 * for the differential controller.
236 *
237 * \returns Differential follower Talon FX
238 */
240 {
241 return *_diffSubFX;
242 }
243 /**
244 * \brief Get the Talon FX that is differential follower. The differential
245 * follower's position and velocity are used by the differential leader
246 * for the differential controller.
247 *
248 * \returns Differential follower Talon FX
249 */
251 {
252 return *_diffSubFX;
253 }
254
255 /**
256 * \brief Apply the mechanism configs to the devices. This should be
257 * called after applying all other configs to the devices.
258 *
259 * \details If the user does not call this function by the time SetControl
260 * is called, SetControl will apply the configs once.
261 *
262 * \param numRetries Number of retries when applying the configs
263 * \returns Status Code of the config applies.
264 */
265 ctre::phoenix::StatusCode ApplyConfigs(int numRetries = kDefaultConfigRetries);
266
267 /**
268 * \brief Call this method periodically to keep the mechanism state updated.
269 */
270 void Periodic();
271
272 /**
273 * \brief Get whether the mechanism is currently disabled due to an issue.
274 *
275 * \returns true if the mechanism is temporarily disabled
276 */
277 bool IsDisabled() const
278 {
279 return _mechanismDisabled.load(std::memory_order_acquire);
280 }
281
282 /**
283 * \brief Get whether the mechanism is currently disabled and requires
284 * user action to re-enable mechanism control.
285 *
286 * \returns true if the mechanism is disabled and the user must manually
287 * perform an action
288 */
290 {
291 return _requiresUserAction.load(std::memory_order_acquire);
292 }
293
294 /**
295 * \brief Gets the state of the mechanism.
296 *
297 * \returns MechanismState representing the state of the mechanism
298 */
300 {
301 if (RequiresUserAction()) {
303 } else if (IsDisabled()) {
305 } else {
306 return MechanismState::OK;
307 }
308 }
309
310 /**
311 * \brief Indicate to the mechanism that the user has performed the required
312 * action to resume mechanism control.
313 */
315
316 /**
317 * \returns The reason for the mechanism being disabled
318 */
320 {
321 return _disabledReason;
322 }
323 /**
324 * \returns The reason for the mechanism requiring user
325 * action to resume control
326 */
328 {
329 return _requiresUserReason;
330 }
331
332 /**
333 * \brief Request neutral output of mechanism. The applied brake type
334 * is determined by the NeutralMode configuration of each device.
335 *
336 * \details Since the NeutralMode configuration of devices may not align, users
337 * may prefer to use the \c SetCoastOut() or \c SetStaticBrake() method.
338 *
339 * \returns Status Code of the request.
340 */
341 ctre::phoenix::StatusCode SetNeutralOut();
342
343 /**
344 * \brief Request coast neutral output of mechanism. The bridge is
345 * disabled and the rotor is allowed to coast.
346 *
347 * \returns Status Code of the request.
348 */
349 ctre::phoenix::StatusCode SetCoastOut();
350
351 /**
352 * \brief Applies full neutral-brake on the mechanism by shorting
353 * motor leads together.
354 *
355 * \returns Status Code of the request.
356 */
357 ctre::phoenix::StatusCode SetStaticBrake();
358
359
360private:
361 std::unique_ptr<controls::ControlRequest> _diffAddFX_req{};
362
363public:
364 /**
365 * \brief Sets the control request for this mechanism.
366 *
367 * \param AverageRequest Average DutyCycleOut request of the mechanism.
368 * \param DifferentialRequest Differential PositionDutyCycle request of the
369 * mechanism. Note: The UpdateFreqHz parameter for
370 * this control request will be ignored by the
371 * control frame.
372 * \returns Status Code of the request.
373 */
374 ctre::phoenix::StatusCode SetControl(controls::DutyCycleOut AverageRequest, controls::PositionDutyCycle DifferentialRequest);
375 /**
376 * \brief Sets the control request for this mechanism.
377 *
378 * \param AverageRequest Average PositionDutyCycle request of the mechanism.
379 * \param DifferentialRequest Differential PositionDutyCycle request of the
380 * mechanism. Note: The UpdateFreqHz parameter for
381 * this control request will be ignored by the
382 * control frame.
383 * \returns Status Code of the request.
384 */
385 ctre::phoenix::StatusCode SetControl(controls::PositionDutyCycle AverageRequest, controls::PositionDutyCycle DifferentialRequest);
386 /**
387 * \brief Sets the control request for this mechanism.
388 *
389 * \param AverageRequest Average VelocityDutyCYcle request of the mechanism.
390 * \param DifferentialRequest Differential PositionDutyCycle request of the
391 * mechanism. Note: The UpdateFreqHz parameter for
392 * this control request will be ignored by the
393 * control frame.
394 * \returns Status Code of the request.
395 */
396 ctre::phoenix::StatusCode SetControl(controls::VelocityDutyCycle AverageRequest, controls::PositionDutyCycle DifferentialRequest);
397 /**
398 * \brief Sets the control request for this mechanism.
399 *
400 * \param AverageRequest Average MotionMagicDutyCycle request of the
401 * mechanism.
402 * \param DifferentialRequest Differential PositionDutyCycle request of the
403 * mechanism. Note: The UpdateFreqHz parameter for
404 * this control request will be ignored by the
405 * control frame.
406 * \returns Status Code of the request.
407 */
408 ctre::phoenix::StatusCode SetControl(controls::MotionMagicDutyCycle AverageRequest, controls::PositionDutyCycle DifferentialRequest);
409 /**
410 * \brief Sets the control request for this mechanism.
411 *
412 * \param AverageRequest Average DutyCycleOut request of the mechanism.
413 * \param DifferentialRequest Differential VelocityDutyCycle request of the
414 * mechanism. Note: The UpdateFreqHz parameter for
415 * this control request will be ignored by the
416 * control frame.
417 * \returns Status Code of the request.
418 */
419 ctre::phoenix::StatusCode SetControl(controls::DutyCycleOut AverageRequest, controls::VelocityDutyCycle DifferentialRequest);
420 /**
421 * \brief Sets the control request for this mechanism.
422 *
423 * \param AverageRequest Average PositionDutyCycle request of the mechanism.
424 * \param DifferentialRequest Differential VelocityDutyCycle request of the
425 * mechanism. Note: The UpdateFreqHz parameter for
426 * this control request will be ignored by the
427 * control frame.
428 * \returns Status Code of the request.
429 */
430 ctre::phoenix::StatusCode SetControl(controls::PositionDutyCycle AverageRequest, controls::VelocityDutyCycle DifferentialRequest);
431 /**
432 * \brief Sets the control request for this mechanism.
433 *
434 * \param AverageRequest Average VelocityDutyCycle request of the mechanism.
435 * \param DifferentialRequest Differential VelocityDutyCycle request of the
436 * mechanism. Note: The UpdateFreqHz parameter for
437 * this control request will be ignored by the
438 * control frame.
439 * \returns Status Code of the request.
440 */
441 ctre::phoenix::StatusCode SetControl(controls::VelocityDutyCycle AverageRequest, controls::VelocityDutyCycle DifferentialRequest);
442 /**
443 * \brief Sets the control request for this mechanism.
444 *
445 * \param AverageRequest Average MotionMagicDutyCycle request of the
446 * mechanism.
447 * \param DifferentialRequest Differential VelocityDutyCycle request of the
448 * mechanism. Note: The UpdateFreqHz parameter for
449 * this control request will be ignored by the
450 * control frame.
451 * \returns Status Code of the request.
452 */
453 ctre::phoenix::StatusCode SetControl(controls::MotionMagicDutyCycle AverageRequest, controls::VelocityDutyCycle DifferentialRequest);
454 /**
455 * \brief Sets the control request for this mechanism.
456 *
457 * \param AverageRequest Average VoltageOut request of the mechanism.
458 * \param DifferentialRequest Differential PositionVoltage request of the
459 * mechanism. Note: The UpdateFreqHz parameter for
460 * this control request will be ignored by the
461 * control frame.
462 * \returns Status Code of the request.
463 */
464 ctre::phoenix::StatusCode SetControl(controls::VoltageOut AverageRequest, controls::PositionVoltage DifferentialRequest);
465 /**
466 * \brief Sets the control request for this mechanism.
467 *
468 * \param AverageRequest Average PositionVoltage request of the mechanism.
469 * \param DifferentialRequest Differential PositionVoltage request of the
470 * mechanism. Note: The UpdateFreqHz parameter for
471 * this control request will be ignored by the
472 * control frame.
473 * \returns Status Code of the request.
474 */
475 ctre::phoenix::StatusCode SetControl(controls::PositionVoltage AverageRequest, controls::PositionVoltage DifferentialRequest);
476 /**
477 * \brief Sets the control request for this mechanism.
478 *
479 * \param AverageRequest Average VelocityVoltage request of the mechanism.
480 * \param DifferentialRequest Differential PositionVoltage request of the
481 * mechanism. Note: The UpdateFreqHz parameter for
482 * this control request will be ignored by the
483 * control frame.
484 * \returns Status Code of the request.
485 */
486 ctre::phoenix::StatusCode SetControl(controls::VelocityVoltage AverageRequest, controls::PositionVoltage DifferentialRequest);
487 /**
488 * \brief Sets the control request for this mechanism.
489 *
490 * \param AverageRequest Average MotionMagicVoltage request of the mechanism.
491 * \param DifferentialRequest Differential PositionVoltage request of the
492 * mechanism. Note: The UpdateFreqHz parameter for
493 * this control request will be ignored by the
494 * control frame.
495 * \returns Status Code of the request.
496 */
497 ctre::phoenix::StatusCode SetControl(controls::MotionMagicVoltage AverageRequest, controls::PositionVoltage DifferentialRequest);
498 /**
499 * \brief Sets the control request for this mechanism.
500 *
501 * \param AverageRequest Average VoltageOut request of the mechanism.
502 * \param DifferentialRequest Differential VelocityVoltage request of the
503 * mechanism. Note: The UpdateFreqHz parameter for
504 * this control request will be ignored by the
505 * control frame.
506 * \returns Status Code of the request.
507 */
508 ctre::phoenix::StatusCode SetControl(controls::VoltageOut AverageRequest, controls::VelocityVoltage DifferentialRequest);
509 /**
510 * \brief Sets the control request for this mechanism.
511 *
512 * \param AverageRequest Average PositionVoltage request of the mechanism.
513 * \param DifferentialRequest Differential VelocityVoltage request of the
514 * mechanism. Note: The UpdateFreqHz parameter for
515 * this control request will be ignored by the
516 * control frame.
517 * \returns Status Code of the request.
518 */
519 ctre::phoenix::StatusCode SetControl(controls::PositionVoltage AverageRequest, controls::VelocityVoltage DifferentialRequest);
520 /**
521 * \brief Sets the control request for this mechanism.
522 *
523 * \param AverageRequest Average VelocityVoltage request of the mechanism.
524 * \param DifferentialRequest Differential VelocityVoltage request of the
525 * mechanism. Note: The UpdateFreqHz parameter for
526 * this control request will be ignored by the
527 * control frame.
528 * \returns Status Code of the request.
529 */
530 ctre::phoenix::StatusCode SetControl(controls::VelocityVoltage AverageRequest, controls::VelocityVoltage DifferentialRequest);
531 /**
532 * \brief Sets the control request for this mechanism.
533 *
534 * \param AverageRequest Average MotionMagicVoltage request of the mechanism.
535 * \param DifferentialRequest Differential VelocityVoltage request of the
536 * mechanism. Note: The UpdateFreqHz parameter for
537 * this control request will be ignored by the
538 * control frame.
539 * \returns Status Code of the request.
540 */
541 ctre::phoenix::StatusCode SetControl(controls::MotionMagicVoltage AverageRequest, controls::VelocityVoltage DifferentialRequest);
542 /**
543 * \brief Sets the control request for this mechanism.
544 *
545 * \param AverageRequest Average TorqueCurrentFOC request of the mechanism.
546 * \param DifferentialRequest Differential PositionTorqueCurrentFOC request
547 * of the mechanism. Note: The UpdateFreqHz
548 * parameter for this control request will be
549 * ignored by the control frame.
550 * \returns Status Code of the request.
551 */
552 ctre::phoenix::StatusCode SetControl(controls::TorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC DifferentialRequest);
553 /**
554 * \brief Sets the control request for this mechanism.
555 *
556 * \param AverageRequest Average PositionTorqueCurrentFOC request of the
557 * mechanism.
558 * \param DifferentialRequest Differential PositionTorqueCurrentFOC request
559 * of the mechanism. Note: The UpdateFreqHz
560 * parameter for this control request will be
561 * ignored by the control frame.
562 * \returns Status Code of the request.
563 */
564 ctre::phoenix::StatusCode SetControl(controls::PositionTorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC DifferentialRequest);
565 /**
566 * \brief Sets the control request for this mechanism.
567 *
568 * \param AverageRequest Average VelocityTorqueCurrentFOC request of the
569 * mechanism.
570 * \param DifferentialRequest Differential PositionTorqueCurrentFOC request
571 * of the mechanism. Note: The UpdateFreqHz
572 * parameter for this control request will be
573 * ignored by the control frame.
574 * \returns Status Code of the request.
575 */
576 ctre::phoenix::StatusCode SetControl(controls::VelocityTorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC DifferentialRequest);
577 /**
578 * \brief Sets the control request for this mechanism.
579 *
580 * \param AverageRequest Average MotionMagicTorqueCurrentFOC request of the
581 * mechanism.
582 * \param DifferentialRequest Differential PositionTorqueCurrentFOC request
583 * of the mechanism. Note: The UpdateFreqHz
584 * parameter for this control request will be
585 * ignored by the control frame.
586 * \returns Status Code of the request.
587 */
588 ctre::phoenix::StatusCode SetControl(controls::MotionMagicTorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC DifferentialRequest);
589 /**
590 * \brief Sets the control request for this mechanism.
591 *
592 * \param AverageRequest Average TorqueCurrentFOC request of the mechanism.
593 * \param DifferentialRequest Differential VelocityTorqueCurrentFOC request
594 * of the mechanism. Note: The UpdateFreqHz
595 * parameter for this control request will be
596 * ignored by the control frame.
597 * \returns Status Code of the request.
598 */
599 ctre::phoenix::StatusCode SetControl(controls::TorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest);
600 /**
601 * \brief Sets the control request for this mechanism.
602 *
603 * \param AverageRequest Average PositionTorqueCurrentFOC request of the
604 * mechanism.
605 * \param DifferentialRequest Differential VelocityTorqueCurrentFOC request
606 * of the mechanism. Note: The UpdateFreqHz
607 * parameter for this control request will be
608 * ignored by the control frame.
609 * \returns Status Code of the request.
610 */
611 ctre::phoenix::StatusCode SetControl(controls::PositionTorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest);
612 /**
613 * \brief Sets the control request for this mechanism.
614 *
615 * \param AverageRequest Average VelocityTorqueCurrentFOC request of the
616 * mechanism.
617 * \param DifferentialRequest Differential VelocityTorqueCurrentFOC request
618 * of the mechanism. Note: The UpdateFreqHz
619 * parameter for this control request will be
620 * ignored by the control frame.
621 * \returns Status Code of the request.
622 */
623 ctre::phoenix::StatusCode SetControl(controls::VelocityTorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest);
624 /**
625 * \brief Sets the control request for this mechanism.
626 *
627 * \param AverageRequest Average MotionMagicTorqueCurrentFOC request of the
628 * mechanism.
629 * \param DifferentialRequest Differential VelocityTorqueCurrentFOC request
630 * of the mechanism. Note: The UpdateFreqHz
631 * parameter for this control request will be
632 * ignored by the control frame.
633 * \returns Status Code of the request.
634 */
635 ctre::phoenix::StatusCode SetControl(controls::MotionMagicTorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest);
636};
637
638}
639}
640}
Request coast neutral output of actuator.
Definition: CoastOut.hpp:27
Follow the differential motor output of another Talon.
Definition: DifferentialFollower.hpp:30
Request a specified motor duty cycle.
Definition: DutyCycleOut.hpp:28
Requests Motion Magic® to target a final position using a motion profile.
Definition: MotionMagicDutyCycle.hpp:34
Requires Phoenix Pro; Requests Motion Magic® to target a final position using a motion profile.
Definition: MotionMagicTorqueCurrentFOC.hpp:35
Requests Motion Magic® to target a final position using a motion profile.
Definition: MotionMagicVoltage.hpp:34
Request neutral output of actuator.
Definition: NeutralOut.hpp:27
Request PID to target position with duty cycle feedforward.
Definition: PositionDutyCycle.hpp:31
Requires Phoenix Pro; Request PID to target position with torque current feedforward.
Definition: PositionTorqueCurrentFOC.hpp:32
Request PID to target position with voltage feedforward.
Definition: PositionVoltage.hpp:31
Requires Phoenix Pro; Request a specified motor current (field oriented control).
Definition: TorqueCurrentFOC.hpp:32
Request PID to target velocity with duty cycle feedforward.
Definition: VelocityDutyCycle.hpp:31
Requires Phoenix Pro; Request PID to target velocity with torque current feedforward.
Definition: VelocityTorqueCurrentFOC.hpp:32
Request PID to target velocity with voltage feedforward.
Definition: VelocityVoltage.hpp:31
Request a specified voltage.
Definition: VoltageOut.hpp:29
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition: CANcoder.hpp:27
Class description for the Pigeon 2 IMU sensor that measures orientation.
Definition: Pigeon2.hpp:29
Class description for the Talon FX integrated motor controller.
Definition: TalonFX.hpp:32
Manages control of a two-axis differential mechanism.
Definition: DifferentialMechanism.hpp:28
ctre::phoenix::StatusCode SetControl(controls::PositionVoltage AverageRequest, controls::VelocityVoltage DifferentialRequest)
Sets the control request for this mechanism.
RequiresUserReason
Possible reasons for the mechanism to require user action to resume control.
Definition: DifferentialMechanism.hpp:74
ctre::phoenix::StatusCode SetControl(controls::TorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
hardware::TalonFX & GetDifferentialFollower()
Get the Talon FX that is differential follower.
Definition: DifferentialMechanism.hpp:239
ctre::phoenix::StatusCode SetControl(controls::VelocityTorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::VelocityTorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
bool IsDisabled() const
Get whether the mechanism is currently disabled due to an issue.
Definition: DifferentialMechanism.hpp:277
ctre::phoenix::StatusCode SetControl(controls::MotionMagicTorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
DifferentialMechanism(hardware::TalonFX &differentialAddFX, hardware::TalonFX &differentialSubFX, bool motorDirectionsAlign, hardware::CANcoder &cancoder)
Creates a new differential mechanism using the given two hardware::TalonFX devices and a hardware::CA...
Definition: DifferentialMechanism.hpp:194
ctre::phoenix::StatusCode SetControl(controls::DutyCycleOut AverageRequest, controls::VelocityDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::PositionTorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::DutyCycleOut AverageRequest, controls::PositionDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetCoastOut()
Request coast neutral output of mechanism.
ctre::phoenix::StatusCode SetControl(controls::VelocityDutyCycle AverageRequest, controls::VelocityDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
DifferentialMechanism(hardware::TalonFX &differentialAddFX, hardware::TalonFX &differentialSubFX, bool motorDirectionsAlign, hardware::Pigeon2 &pigeon2, DifferentialPigeon2Source pigeonSource)
Creates a new differential mechanism using the given two hardware::TalonFX devices and a hardware::Pi...
Definition: DifferentialMechanism.hpp:167
RequiresUserReason GetRequiresUserReason() const
Definition: DifferentialMechanism.hpp:327
DisabledReason
Possible reasons for the mechanism to disable.
Definition: DifferentialMechanism.hpp:42
ctre::phoenix::StatusCode SetControl(controls::VelocityVoltage AverageRequest, controls::PositionVoltage DifferentialRequest)
Sets the control request for this mechanism.
DisabledReason GetDisabledReason() const
Definition: DifferentialMechanism.hpp:319
ctre::phoenix::StatusCode SetControl(controls::PositionVoltage AverageRequest, controls::PositionVoltage DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::VoltageOut AverageRequest, controls::PositionVoltage DifferentialRequest)
Sets the control request for this mechanism.
DifferentialPigeon2Source
Sensor sources for a differential Pigeon 2.
Definition: DifferentialMechanism.hpp:33
ctre::phoenix::StatusCode SetControl(controls::VoltageOut AverageRequest, controls::VelocityVoltage DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetStaticBrake()
Applies full neutral-brake on the mechanism by shorting motor leads together.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicDutyCycle AverageRequest, controls::VelocityDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetNeutralOut()
Request neutral output of mechanism.
ctre::phoenix::StatusCode SetControl(controls::VelocityDutyCycle AverageRequest, controls::PositionDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::PositionDutyCycle AverageRequest, controls::PositionDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicVoltage AverageRequest, controls::PositionVoltage DifferentialRequest)
Sets the control request for this mechanism.
void Periodic()
Call this method periodically to keep the mechanism state updated.
void ClearUserRequirement()
Indicate to the mechanism that the user has performed the required action to resume mechanism control...
ctre::phoenix::StatusCode SetControl(controls::VelocityVoltage AverageRequest, controls::VelocityVoltage DifferentialRequest)
Sets the control request for this mechanism.
hardware::TalonFX const & GetDifferentialFollower() const
Get the Talon FX that is differential follower.
Definition: DifferentialMechanism.hpp:250
ctre::phoenix::StatusCode SetControl(controls::PositionTorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
MechanismState GetMechanismState() const
Gets the state of the mechanism.
Definition: DifferentialMechanism.hpp:299
DifferentialMechanism(hardware::TalonFX &differentialAddFX, hardware::TalonFX &differentialSubFX, bool motorDirectionsAlign)
Creates a new differential mechanism using the given two hardware::TalonFX devices.
Definition: DifferentialMechanism.hpp:139
hardware::TalonFX const & GetDifferentialLeader() const
Get the Talon FX that is differential leader.
Definition: DifferentialMechanism.hpp:227
ctre::phoenix::StatusCode SetControl(controls::MotionMagicTorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicDutyCycle AverageRequest, controls::PositionDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
static constexpr int kDefaultConfigRetries
The default number of retries for config applies.
Definition: DifferentialMechanism.hpp:124
ctre::phoenix::StatusCode ApplyConfigs(int numRetries=kDefaultConfigRetries)
Apply the mechanism configs to the devices.
ctre::phoenix::StatusCode SetControl(controls::TorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::PositionDutyCycle AverageRequest, controls::VelocityDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicVoltage AverageRequest, controls::VelocityVoltage DifferentialRequest)
Sets the control request for this mechanism.
hardware::TalonFX & GetDifferentialLeader()
Get the Talon FX that is differential leader.
Definition: DifferentialMechanism.hpp:215
bool RequiresUserAction() const
Get whether the mechanism is currently disabled and requires user action to re-enable mechanism contr...
Definition: DifferentialMechanism.hpp:289
MechanismState
Possible states of a mechanism.
Definition: MechanismState.hpp:15
@ RequiresUserAction
The mechanism is disabled and requires user action.
@ Disabled
The mechanism is temporarily disabled due to an issue.
@ OK
The mechanism is running normally.
Definition: string_util.hpp:15