49template <std::derived_from<hardware::traits::CommonTalon> MotorT>
108 static constexpr int kNumConfigAttempts = 2;
110 std::unique_ptr<MotorT> _diffLeaderFX;
111 std::unique_ptr<MotorT> _diffFollowerFX;
113 units::scalar_t _sensorToDiffRatio;
115 std::function<bool()> _diffLeaderFXResetChecker;
116 std::function<bool()> _diffFollowerFXResetChecker;
117 std::optional<std::function<bool()>> _diffSensorResetChecker{};
122 controls::CoastOut _coast{};
123 controls::StaticBrake _brake{};
125 std::atomic<bool> _mechanismDisabled{
false};
126 std::atomic<bool> _requiresUserAction{
false};
132 DifferentialMotorConstants<typename MotorT::Configuration>
const &constants,
133 signals::DifferentialSensorSourceValue diffSensorSource,
134 std::optional<int> diffSensorID
214 return _mechanismDisabled.load(std::memory_order_acquire);
226 return _requiresUserAction.load(std::memory_order_acquire);
256 return _disabledReason;
264 return _requiresUserReason;
282 return _diffLeaderFX->GetDifferentialAveragePosition(refresh);
300 return _diffLeaderFX->GetDifferentialAverageVelocity(refresh);
318 return _diffLeaderFX->GetDifferentialDifferencePosition(refresh);
336 return _diffLeaderFX->GetDifferentialDifferenceVelocity(refresh);
352 return _diffLeaderFX->GetClosedLoopReference(refresh);
370 return _diffLeaderFX->GetClosedLoopReferenceSlope(refresh);
387 return _diffLeaderFX->GetClosedLoopError(refresh);
403 return _diffLeaderFX->GetDifferentialClosedLoopReference(refresh);
423 return _diffLeaderFX->GetDifferentialClosedLoopReferenceSlope(refresh);
440 return _diffLeaderFX->GetDifferentialClosedLoopError(refresh);
455 auto response = _diffLeaderFX->SetPosition(avgPosition + diffPosition * _sensorToDiffRatio, timeoutSeconds);
456 if (retval.
IsOK()) retval = response;
457 response = _diffFollowerFX->SetPosition(avgPosition - diffPosition * _sensorToDiffRatio, timeoutSeconds);
458 if (retval.
IsOK()) retval = response;
473 return *_diffLeaderFX;
485 return *_diffLeaderFX;
497 return *_diffFollowerFX;
508 return *_diffFollowerFX;
Represents a status signal with data of type T, and operations available to retrieve information abou...
Definition StatusSignal.hpp:474
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:32
Class for CTR Electronics' CANdi™ branded device, a device that integrates digital signals into the e...
Definition CANdi.hpp:32
Class description for the Pigeon 2 IMU sensor that measures orientation.
Definition Pigeon2.hpp:34
Manages control of a simple two-axis differential mechanism.
Definition SimpleDifferentialMechanism.hpp:50
StatusSignal< double > & GetAverageClosedLoopReference(bool refresh=true)
Value that the average closed loop is targeting.
Definition SimpleDifferentialMechanism.hpp:350
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:254
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< double > & GetDifferentialClosedLoopReference(bool refresh=true)
Value that the differential closed loop is targeting.
Definition SimpleDifferentialMechanism.hpp:401
MechanismState GetMechanismState() const
Gets the state of the mechanism.
Definition SimpleDifferentialMechanism.hpp:234
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:262
StatusSignal< units::turn_t > & GetAveragePosition(bool refresh=true)
Average component of the mechanism position.
Definition SimpleDifferentialMechanism.hpp:280
ctre::phoenix::StatusCode SetPosition(units::turn_t avgPosition, units::turn_t diffPosition=0_tr, units::time::second_t timeoutSeconds=0.100_s)
Sets the position of the mechanism in rotations.
Definition SimpleDifferentialMechanism.hpp:451
DisabledReasonValue
Possible reasons for the mechanism to disable.
Definition SimpleDifferentialMechanism.hpp:55
@ 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.
StatusSignal< units::turn_t > & GetDifferentialPosition(bool refresh=true)
Differential component of the mechanism position.
Definition SimpleDifferentialMechanism.hpp:316
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.
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:224
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:471
RequiresUserReasonValue
Possible reasons for the mechanism to require user action to resume control.
Definition SimpleDifferentialMechanism.hpp:87
void ClearUserRequirement()
Indicate to the mechanism that the user has performed the required action to resume mechanism control...
ctre::phoenix::StatusCode ConfigNeutralMode(signals::NeutralModeValue neutralMode, units::second_t timeoutSeconds=100_ms)
Configures the neutral mode to use for both motors in the mechanism.
bool IsDisabled() const
Get whether the mechanism is currently disabled due to an issue.
Definition SimpleDifferentialMechanism.hpp:212
StatusSignal< units::turns_per_second_t > & GetAverageVelocity(bool refresh=true)
Average component of the mechanism velocity.
Definition SimpleDifferentialMechanism.hpp:298
MotorT const & GetFollower() const
Get the Talon FX that is differential follower.
Definition SimpleDifferentialMechanism.hpp:506
MotorT const & GetLeader() const
Get the Talon FX that is differential leader.
Definition SimpleDifferentialMechanism.hpp:483
ctre::phoenix::StatusCode SetControl(controls::DifferentialMotionMagicDutyCycle const &diffLeaderFXRequest)
Sets the control request for this mechanism.
StatusSignal< double > & GetAverageClosedLoopReferenceSlope(bool refresh=true)
Derivative of the target that the average closed loop is targeting.
Definition SimpleDifferentialMechanism.hpp:368
StatusSignal< double > & GetAverageClosedLoopError(bool refresh=true)
The difference between target average reference and current measurement.
Definition SimpleDifferentialMechanism.hpp:385
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:438
ctre::phoenix::StatusCode SetControl(controls::DifferentialVelocityVoltage const &diffLeaderFXRequest)
Sets the control request for this mechanism.
StatusSignal< units::turns_per_second_t > & GetDifferentialVelocity(bool refresh=true)
Differential component of the mechanism velocity.
Definition SimpleDifferentialMechanism.hpp:334
StatusSignal< double > & GetDifferentialClosedLoopReferenceSlope(bool refresh=true)
Derivative of the target that the differential closed loop is targeting.
Definition SimpleDifferentialMechanism.hpp:421
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:495
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:858
DifferentialPigeon2Source
Sensor sources for a differential Pigeon 2.
Definition DifferentialConstants.hpp:19
DifferentialCANdiSource
Sensor sources for a differential CTR Electronics' CANdi™ branded device.
Definition DifferentialConstants.hpp:38
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 motor_constants.h:14
All constants for setting up the motors of a differential mechanism.
Definition DifferentialConstants.hpp:57
The state of the motor controller bridge when output is neutral or disabled.
Definition SpnEnums.hpp:1603