95 std::optional<hardware::Pigeon2 *> _pigeon2;
97 std::optional<hardware::CANcoder *> _cancoder;
103 controls::StaticBrake _brake{};
105 std::function<bool()> _diffAddFXResetChecker;
106 std::function<bool()> _diffSubFXResetChecker;
107 std::optional<std::function<bool()>> _pigeon2ResetChecker;
108 std::optional<std::function<bool()>> _cancoderResetChecker;
110 bool _hasAppliedConfigs{
false};
113 std::atomic<bool> _mechanismDisabled{
false};
114 std::atomic<bool> _requiresUserAction{
false};
138 _diffAddFX{&differentialAddFX},
139 _diffSubFX{&differentialSubFX},
140 _pigeon2{
std::nullopt},
142 _cancoder{
std::nullopt},
143 _diffFollow{_diffAddFX->GetDeviceID(), !motorDirectionsAlign},
144 _diffAddFXResetChecker{_diffAddFX->GetResetOccurredChecker()},
145 _diffSubFXResetChecker{_diffSubFX->GetResetOccurredChecker()},
146 _pigeon2ResetChecker{
std::nullopt},
147 _cancoderResetChecker{
std::nullopt}
165 _diffAddFX{&differentialAddFX},
166 _diffSubFX{&differentialSubFX},
168 _pigeonSource{pigeonSource},
169 _cancoder{
std::nullopt},
170 _diffFollow{_diffAddFX->GetDeviceID(), !motorDirectionsAlign},
171 _diffAddFXResetChecker{_diffAddFX->GetResetOccurredChecker()},
172 _diffSubFXResetChecker{_diffSubFX->GetResetOccurredChecker()},
173 _pigeon2ResetChecker{(*_pigeon2)->GetResetOccurredChecker()},
174 _cancoderResetChecker{
std::nullopt}
191 _diffAddFX{&differentialAddFX},
192 _diffSubFX{&differentialSubFX},
193 _pigeon2{
std::nullopt},
195 _cancoder{&cancoder},
196 _diffFollow{_diffAddFX->GetDeviceID(), !motorDirectionsAlign},
197 _diffAddFXResetChecker{_diffAddFX->GetResetOccurredChecker()},
198 _diffSubFXResetChecker{_diffSubFX->GetResetOccurredChecker()},
199 _pigeon2ResetChecker{
std::nullopt},
200 _cancoderResetChecker{(*_cancoder)->GetResetOccurredChecker()}
275 return _mechanismDisabled.load(std::memory_order_acquire);
287 return _requiresUserAction.load(std::memory_order_acquire);
317 return _disabledReason;
325 return _requiresUserReason;
Request coast neutral output of actuator.
Definition CoastOut.hpp:27
Request a specified motor duty cycle with a differential position closed-loop.
Definition DifferentialDutyCycle.hpp:31
Follow the differential motor output of another Talon.
Definition DifferentialFollower.hpp:30
Requests Motion Magic® to target a final position using a motion profile, and PID to a differential p...
Definition DifferentialMotionMagicDutyCycle.hpp:35
Requests Motion Magic® to target a final position using a motion profile, and PID to a differential p...
Definition DifferentialMotionMagicVoltage.hpp:34
Request PID to target position with a differential position setpoint.
Definition DifferentialPositionDutyCycle.hpp:29
Request PID to target position with a differential position setpoint.
Definition DifferentialPositionVoltage.hpp:29
Request PID to target velocity with a differential position setpoint.
Definition DifferentialVelocityDutyCycle.hpp:30
Request PID to target velocity with a differential position setpoint.
Definition DifferentialVelocityVoltage.hpp:30
Request a specified voltage with a differential position closed-loop.
Definition DifferentialVoltage.hpp:31
Request neutral output of actuator.
Definition NeutralOut.hpp:27
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:30
Manages control of a simple two-axis differential mechanism.
Definition SimpleDifferentialMechanism.hpp:27
hardware::TalonFX const & GetDifferentialLeader() const
Get the Talon FX that is differential leader.
Definition SimpleDifferentialMechanism.hpp:223
ctre::phoenix::StatusCode SetControl(controls::DifferentialPositionVoltage _diffAddFXRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::DifferentialPositionDutyCycle _diffAddFXRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetCoastOut()
Request coast neutral output of mechanism.
hardware::TalonFX const & GetDifferentialFollower() const
Get the Talon FX that is differential follower.
Definition SimpleDifferentialMechanism.hpp:246
hardware::TalonFX & GetDifferentialFollower()
Get the Talon FX that is differential follower.
Definition SimpleDifferentialMechanism.hpp:235
void ClearUserRequirement()
Indicate to the mechanism that the user has performed the required action to resume mechanism control...
ctre::phoenix::StatusCode SetStaticBrake()
Applies full neutral-brake on the mechanism by shorting motor leads together.
bool IsDisabled() const
Get whether the mechanism is currently disabled due to an issue.
Definition SimpleDifferentialMechanism.hpp:273
ctre::phoenix::StatusCode SetControl(controls::DifferentialVoltage _diffAddFXRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetNeutralOut()
Request neutral output of mechanism.
static constexpr int kDefaultConfigRetries
The default number of retries for config applies.
Definition SimpleDifferentialMechanism.hpp:123
ctre::phoenix::StatusCode SetControl(controls::DifferentialMotionMagicDutyCycle _diffAddFXRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::DifferentialVelocityVoltage _diffAddFXRequest)
Sets the control request for this mechanism.
SimpleDifferentialMechanism(hardware::TalonFX &differentialAddFX, hardware::TalonFX &differentialSubFX, bool motorDirectionsAlign, hardware::CANcoder &cancoder)
Creates a new simple differential mechanism using the given two hardware::TalonFX devices and a hardw...
Definition SimpleDifferentialMechanism.hpp:190
DisabledReason GetDisabledReason() const
Definition SimpleDifferentialMechanism.hpp:315
MechanismState GetMechanismState() const
Gets the state of the mechanism.
Definition SimpleDifferentialMechanism.hpp:295
ctre::phoenix::StatusCode SetControl(controls::DifferentialMotionMagicVoltage _diffAddFXRequest)
Sets the control request for this mechanism.
RequiresUserReason GetRequiresUserReason() const
Definition SimpleDifferentialMechanism.hpp:323
void Periodic()
Call this method periodically to keep the mechanism state updated.
bool RequiresUserAction() const
Get whether the mechanism is currently disabled and requires user action to re-enable mechanism contr...
Definition SimpleDifferentialMechanism.hpp:285
DisabledReason
Possible reasons for the mechanism to disable.
Definition SimpleDifferentialMechanism.hpp:41
@ RemoteSensorPosOverflow
A remote sensor position has overflowed.
@ MissingDifferentialFX
The remote Talon FX used for differential control is not present on CAN Bus.
@ DeviceHasReset
A device or remote sensor has reset.
@ MissingRemoteSensor
A remote sensor is not present on CAN Bus.
SimpleDifferentialMechanism(hardware::TalonFX &differentialAddFX, hardware::TalonFX &differentialSubFX, bool motorDirectionsAlign)
Creates a new simple differential mechanism using the given two hardware::TalonFX devices.
Definition SimpleDifferentialMechanism.hpp:137
SimpleDifferentialMechanism(hardware::TalonFX &differentialAddFX, hardware::TalonFX &differentialSubFX, bool motorDirectionsAlign, hardware::Pigeon2 &pigeon2, DifferentialPigeon2Source pigeonSource)
Creates a new simple differential mechanism using the given two hardware::TalonFX devices and a hardw...
Definition SimpleDifferentialMechanism.hpp:164
hardware::TalonFX & GetDifferentialLeader()
Get the Talon FX that is differential leader.
Definition SimpleDifferentialMechanism.hpp:211
ctre::phoenix::StatusCode SetControl(controls::DifferentialDutyCycle _diffAddFXRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode ApplyConfigs(int numRetries=kDefaultConfigRetries)
Apply the mechanism configs to the devices.
ctre::phoenix::StatusCode SetControl(controls::DifferentialVelocityDutyCycle _diffAddFXRequest)
Sets the control request for this mechanism.
RequiresUserReason
Possible reasons for the mechanism to require user action to resume control.
Definition SimpleDifferentialMechanism.hpp:73
DifferentialPigeon2Source
Sensor sources for a differential Pigeon 2.
Definition SimpleDifferentialMechanism.hpp:32
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
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 StatusCodes.h:18