51template <std::derived_from<hardware::traits::CommonTalon> MotorT>
110 static constexpr int kNumConfigAttempts = 2;
112 std::unique_ptr<MotorT> _diffLeaderFX;
113 std::unique_ptr<MotorT> _diffFollowerFX;
115 wpi::units::scalar_t _sensorToDiffRatio;
117 std::function<bool()> _diffLeaderFXResetChecker;
118 std::function<bool()> _diffFollowerFXResetChecker;
119 std::optional<std::function<bool()>> _diffSensorResetChecker{};
124 controls::CoastOut _coast{};
125 controls::StaticBrake _brake{};
127 std::atomic<bool> _mechanismDisabled{
false};
128 std::atomic<bool> _requiresUserAction{
false};
134 DifferentialMotorConstants<typename MotorT::Configuration>
const &constants,
135 signals::DifferentialSensorSourceValue diffSensorSource,
136 std::optional<int> diffSensorID
138 ctre::phoenix::StatusCode BeforeControl();
216 return _mechanismDisabled.load(std::memory_order_acquire);
228 return _requiresUserAction.load(std::memory_order_acquire);
258 return _disabledReason;
266 return _requiresUserReason;
284 return _diffLeaderFX->GetDifferentialAveragePosition(refresh);
302 return _diffLeaderFX->GetDifferentialAverageVelocity(refresh);
320 return _diffLeaderFX->GetDifferentialDifferencePosition(refresh);
338 return _diffLeaderFX->GetDifferentialDifferenceVelocity(refresh);
354 return _diffLeaderFX->GetClosedLoopReference(refresh);
372 return _diffLeaderFX->GetClosedLoopReferenceSlope(refresh);
389 return _diffLeaderFX->GetClosedLoopError(refresh);
405 return _diffLeaderFX->GetDifferentialClosedLoopReference(refresh);
425 return _diffLeaderFX->GetDifferentialClosedLoopReferenceSlope(refresh);
442 return _diffLeaderFX->GetDifferentialClosedLoopError(refresh);
457 auto response = _diffLeaderFX->SetPosition(avgPosition + diffPosition * _sensorToDiffRatio, timeoutSeconds);
458 if (retval.
IsOK()) retval = response;
459 response = _diffFollowerFX->SetPosition(avgPosition - diffPosition * _sensorToDiffRatio, timeoutSeconds);
460 if (retval.
IsOK()) retval = response;
475 return *_diffLeaderFX;
487 return *_diffLeaderFX;
499 return *_diffFollowerFX;
510 return *_diffFollowerFX;
Represents a status signal with data of type T, and operations available to retrieve information abou...
Definition StatusSignal.hpp:523
Request a specified motor duty cycle with a differential position closed-loop.
Definition DifferentialDutyCycle.hpp:26
Follow the differential motor output of another Talon.
Definition DifferentialFollower.hpp:29
Requests Motion Magic® to target a final position using a motion profile, and PID to a differential p...
Definition DifferentialMotionMagicDutyCycle.hpp:30
Requests Motion Magic® to target a final position using an exponential motion profile,...
Definition DifferentialMotionMagicExpoDutyCycle.hpp:33
Requests Motion Magic® to target a final position using an exponential motion profile,...
Definition DifferentialMotionMagicExpoVoltage.hpp:32
Requests Motion Magic® to target a final velocity using a motion profile, and PID to a differential p...
Definition DifferentialMotionMagicVelocityDutyCycle.hpp:35
Requests Motion Magic® to target a final velocity using a motion profile, and PID to a differential p...
Definition DifferentialMotionMagicVelocityVoltage.hpp:34
Requests Motion Magic® to target a final position using a motion profile, and PID to a differential p...
Definition DifferentialMotionMagicVoltage.hpp:29
Request PID to target position with a differential position setpoint.
Definition DifferentialPositionDutyCycle.hpp:24
Request PID to target position with a differential position setpoint.
Definition DifferentialPositionVoltage.hpp:24
Request PID to target velocity with a differential position setpoint.
Definition DifferentialVelocityDutyCycle.hpp:25
Request PID to target velocity with a differential position setpoint.
Definition DifferentialVelocityVoltage.hpp:25
Request a specified voltage with a differential position closed-loop.
Definition DifferentialVoltage.hpp:26
Request neutral output of actuator.
Definition NeutralOut.hpp:21
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition CANcoder.hpp:27
Class for CTR Electronics' CANdi™ branded device, a device that integrates digital signals into the e...
Definition CANdi.hpp:26
Class description for the Pigeon 2 IMU sensor that measures orientation.
Definition Pigeon2.hpp:28
StatusSignal< double > & GetAverageClosedLoopReference(bool refresh=true)
Value that the average closed loop is targeting.
Definition SimpleDifferentialMechanism.hpp:352
SimpleDifferentialMechanism(DifferentialMotorConstants< typename MotorT::Configuration > const &constants, hardware::CANcoder &cancoder)
Creates a new simple differential mechanism using two hardware::traits::CommonTalon devices and a har...
DisabledReasonValue GetDisabledReason() const
Definition SimpleDifferentialMechanism.hpp:256
ctre::phoenix::StatusCode SetControl(controls::DifferentialMotionMagicExpoVoltage const &diffLeaderFXRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::DifferentialMotionMagicVoltage const &diffLeaderFXRequest)
Sets the control request for this mechanism.
StatusSignal< wpi::units::turn_t > & GetAveragePosition(bool refresh=true)
Average component of the mechanism position.
Definition SimpleDifferentialMechanism.hpp:282
ctre::phoenix::StatusCode SetPosition(wpi::units::turn_t avgPosition, wpi::units::turn_t diffPosition=0_tr, wpi::units::second_t timeoutSeconds=0.100_s)
Sets the position of the mechanism in rotations.
Definition SimpleDifferentialMechanism.hpp:453
StatusSignal< double > & GetDifferentialClosedLoopReference(bool refresh=true)
Value that the differential closed loop is targeting.
Definition SimpleDifferentialMechanism.hpp:403
MechanismState GetMechanismState() const
Gets the state of the mechanism.
Definition SimpleDifferentialMechanism.hpp:236
ctre::phoenix::StatusCode SetControl(controls::DifferentialPositionDutyCycle const &diffLeaderFXRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::DifferentialMotionMagicExpoDutyCycle const &diffLeaderFXRequest)
Sets the control request for this mechanism.
SimpleDifferentialMechanism(DifferentialMotorConstants< typename MotorT::Configuration > const &constants)
Creates a new simple differential mechanism using two hardware::traits::CommonTalon devices.
ctre::phoenix::StatusCode SetControl(controls::DifferentialVoltage const &diffLeaderFXRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::DifferentialMotionMagicVelocityDutyCycle const &diffLeaderFXRequest)
Sets the control request for this mechanism.
SimpleDifferentialMechanism(DifferentialMotorConstants< typename MotorT::Configuration > const &constants, hardware::Pigeon2 &pigeon2, DifferentialPigeon2Source pigeonSource)
Creates a new simple differential mechanism using two hardware::traits::CommonTalon devices and a har...
ctre::phoenix::StatusCode SetStaticBrake()
Applies full neutral-brake on the mechanism by shorting motor leads together.
RequiresUserReasonValue GetRequiresUserReason() const
Definition SimpleDifferentialMechanism.hpp:264
DisabledReasonValue
Possible reasons for the mechanism to disable.
Definition SimpleDifferentialMechanism.hpp:57
@ RemoteSensorPosOverflow
A remote sensor position has overflowed.
Definition SimpleDifferentialMechanism.hpp:78
@ None
No reason given.
Definition SimpleDifferentialMechanism.hpp:61
@ MissingDifferentialFX
The remote Talon FX used for differential control is not present on CAN Bus.
Definition SimpleDifferentialMechanism.hpp:70
@ DeviceHasReset
A device or remote sensor has reset.
Definition SimpleDifferentialMechanism.hpp:82
@ MissingRemoteSensor
A remote sensor is not present on CAN Bus.
Definition SimpleDifferentialMechanism.hpp:65
ctre::phoenix::StatusCode SetCoastOut()
Request coast neutral output of mechanism.
ctre::phoenix::StatusCode SetControl(controls::DifferentialPositionVoltage const &diffLeaderFXRequest)
Sets the control request for this mechanism.
StatusSignal< wpi::units::turn_t > & GetDifferentialPosition(bool refresh=true)
Differential component of the mechanism position.
Definition SimpleDifferentialMechanism.hpp:318
ctre::phoenix::StatusCode SetControl(controls::DifferentialMotionMagicVelocityVoltage const &diffLeaderFXRequest)
Sets the control request for this mechanism.
bool RequiresUserAction() const
Get whether the mechanism is currently disabled and requires user action to re-enable mechanism contr...
Definition SimpleDifferentialMechanism.hpp:226
ctre::phoenix::StatusCode SetControl(controls::DifferentialDutyCycle const &diffLeaderFXRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::DifferentialVelocityDutyCycle const &diffLeaderFXRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetNeutralOut()
Request neutral output of mechanism.
MotorT & GetLeader()
Get the Talon FX that is differential leader.
Definition SimpleDifferentialMechanism.hpp:473
RequiresUserReasonValue
Possible reasons for the mechanism to require user action to resume control.
Definition SimpleDifferentialMechanism.hpp:89
@ None
No reason given.
Definition SimpleDifferentialMechanism.hpp:93
void ClearUserRequirement()
Indicate to the mechanism that the user has performed the required action to resume mechanism control...
bool IsDisabled() const
Get whether the mechanism is currently disabled due to an issue.
Definition SimpleDifferentialMechanism.hpp:214
MotorT const & GetFollower() const
Get the Talon FX that is differential follower.
Definition SimpleDifferentialMechanism.hpp:508
MotorT const & GetLeader() const
Get the Talon FX that is differential leader.
Definition SimpleDifferentialMechanism.hpp:485
ctre::phoenix::StatusCode SetControl(controls::DifferentialMotionMagicDutyCycle const &diffLeaderFXRequest)
Sets the control request for this mechanism.
StatusSignal< wpi::units::turns_per_second_t > & GetDifferentialVelocity(bool refresh=true)
Differential component of the mechanism velocity.
Definition SimpleDifferentialMechanism.hpp:336
StatusSignal< double > & GetAverageClosedLoopReferenceSlope(bool refresh=true)
Derivative of the target that the average closed loop is targeting.
Definition SimpleDifferentialMechanism.hpp:370
StatusSignal< double > & GetAverageClosedLoopError(bool refresh=true)
The difference between target average reference and current measurement.
Definition SimpleDifferentialMechanism.hpp:387
void Periodic()
Call this method periodically to automatically protect against dangerous fault conditions and keep Ge...
StatusSignal< double > & GetDifferentialClosedLoopError(bool refresh=true)
The difference between target differential reference and current measurement.
Definition SimpleDifferentialMechanism.hpp:440
StatusSignal< wpi::units::turns_per_second_t > & GetAverageVelocity(bool refresh=true)
Average component of the mechanism velocity.
Definition SimpleDifferentialMechanism.hpp:300
ctre::phoenix::StatusCode ConfigNeutralMode(signals::NeutralModeValue neutralMode, wpi::units::second_t timeoutSeconds=100_ms)
Configures the neutral mode to use for both motors in the mechanism.
ctre::phoenix::StatusCode SetControl(controls::DifferentialVelocityVoltage const &diffLeaderFXRequest)
Sets the control request for this mechanism.
StatusSignal< double > & GetDifferentialClosedLoopReferenceSlope(bool refresh=true)
Derivative of the target that the differential closed loop is targeting.
Definition SimpleDifferentialMechanism.hpp:423
SimpleDifferentialMechanism(DifferentialMotorConstants< typename MotorT::Configuration > const &constants, hardware::CANdi &candi, DifferentialCANdiSource candiSource)
Creates a new simple differential mechanism using two hardware::traits::CommonTalon devices and a har...
MotorT & GetFollower()
Get the Talon FX that is differential follower.
Definition SimpleDifferentialMechanism.hpp:497
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
static constexpr int OK
No Error.
Definition StatusCodes.h:35
constexpr bool IsOK() const
Definition StatusCodes.h:860
Definition ExternalFeedbackConfigs.hpp:17
Definition SimpleDifferentialMechanism.hpp:24
DifferentialPigeon2Source
Sensor sources for a differential Pigeon 2.
Definition DifferentialConstants.hpp:20
DifferentialCANdiSource
Sensor sources for a differential CTR Electronics' CANdi™ branded device.
Definition DifferentialConstants.hpp:39
Definition ExternalFeedbackConfigs.hpp:16
MechanismState
Possible states of a mechanism.
Definition MechanismState.hpp:15
@ RequiresUserAction
The mechanism is disabled and requires user action.
Definition MechanismState.hpp:27
@ Disabled
The mechanism is temporarily disabled due to an issue.
Definition MechanismState.hpp:23
@ OK
The mechanism is running normally.
Definition MechanismState.hpp:19
Definition motor_constants.h:14
All constants for setting up the motors of a differential mechanism.
Definition DifferentialConstants.hpp:58
The state of the motor controller bridge when output is neutral or disabled.
Definition SpnEnums.hpp:1499