50template <std::derived_from<hardware::traits::CommonTalon> MotorT>
109 static constexpr int kNumConfigAttempts = 2;
111 std::unique_ptr<MotorT> _diffLeaderFX;
112 std::unique_ptr<MotorT> _diffFollowerFX;
114 units::scalar_t _sensorToDiffRatio;
116 std::function<bool()> _diffLeaderFXResetChecker;
117 std::function<bool()> _diffFollowerFXResetChecker;
118 std::optional<std::function<bool()>> _diffSensorResetChecker{};
123 controls::CoastOut _coast{};
124 controls::StaticBrake _brake{};
126 std::atomic<bool> _mechanismDisabled{
false};
127 std::atomic<bool> _requiresUserAction{
false};
133 DifferentialMotorConstants<typename MotorT::Configuration>
const &constants,
134 signals::DifferentialSensorSourceValue diffSensorSource,
135 std::optional<int> diffSensorID
219 return _mechanismDisabled.load(std::memory_order_acquire);
231 return _requiresUserAction.load(std::memory_order_acquire);
261 return _disabledReason;
269 return _requiresUserReason;
287 return _diffLeaderFX->GetDifferentialAveragePosition(refresh);
305 return _diffLeaderFX->GetDifferentialAverageVelocity(refresh);
323 return _diffLeaderFX->GetDifferentialDifferencePosition(refresh);
341 return _diffLeaderFX->GetDifferentialDifferenceVelocity(refresh);
357 return _diffLeaderFX->GetClosedLoopReference(refresh);
375 return _diffLeaderFX->GetClosedLoopReferenceSlope(refresh);
392 return _diffLeaderFX->GetClosedLoopError(refresh);
408 return _diffLeaderFX->GetDifferentialClosedLoopReference(refresh);
428 return _diffLeaderFX->GetDifferentialClosedLoopReferenceSlope(refresh);
445 return _diffLeaderFX->GetDifferentialClosedLoopError(refresh);
460 auto response = _diffLeaderFX->SetPosition(avgPosition + diffPosition * _sensorToDiffRatio, timeoutSeconds);
461 if (retval.
IsOK()) retval = response;
462 response = _diffFollowerFX->SetPosition(avgPosition - diffPosition * _sensorToDiffRatio, timeoutSeconds);
463 if (retval.
IsOK()) retval = response;
478 return *_diffLeaderFX;
490 return *_diffLeaderFX;
502 return *_diffFollowerFX;
513 return *_diffFollowerFX;
Represents a status signal with data of type T, and operations available to retrieve information abou...
Definition StatusSignal.hpp:474
Follow the differential motor output of another Talon.
Definition DifferentialFollower.hpp:29
Request a specified motor duty cycle.
Definition DutyCycleOut.hpp:23
Requests Motion Magic® to target a final position using a motion profile.
Definition MotionMagicDutyCycle.hpp:31
Requests Motion Magic® to target a final position using an exponential motion profile.
Definition MotionMagicExpoDutyCycle.hpp:34
Requires Phoenix Pro; Requests Motion Magic® to target a final position using an exponential motion p...
Definition MotionMagicExpoTorqueCurrentFOC.hpp:34
Requests Motion Magic® to target a final position using an exponential motion profile.
Definition MotionMagicExpoVoltage.hpp:33
Requires Phoenix Pro; Requests Motion Magic® to target a final position using a motion profile.
Definition MotionMagicTorqueCurrentFOC.hpp:31
Requests Motion Magic® to target a final velocity using a motion profile.
Definition MotionMagicVelocityDutyCycle.hpp:38
Requests Motion Magic® to target a final velocity using a motion profile.
Definition MotionMagicVelocityTorqueCurrentFOC.hpp:38
Requests Motion Magic® to target a final velocity using a motion profile.
Definition MotionMagicVelocityVoltage.hpp:37
Requests Motion Magic® to target a final position using a motion profile.
Definition MotionMagicVoltage.hpp:30
Request neutral output of actuator.
Definition NeutralOut.hpp:21
Request PID to target position with duty cycle feedforward.
Definition PositionDutyCycle.hpp:26
Requires Phoenix Pro; Request PID to target position with torque current feedforward.
Definition PositionTorqueCurrentFOC.hpp:27
Request PID to target position with voltage feedforward.
Definition PositionVoltage.hpp:26
Requires Phoenix Pro; Request a specified motor current (field oriented control).
Definition TorqueCurrentFOC.hpp:27
Request PID to target velocity with duty cycle feedforward.
Definition VelocityDutyCycle.hpp:26
Requires Phoenix Pro; Request PID to target velocity with torque current feedforward.
Definition VelocityTorqueCurrentFOC.hpp:27
Request PID to target velocity with voltage feedforward.
Definition VelocityVoltage.hpp:26
Request a specified voltage.
Definition VoltageOut.hpp:24
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 two-axis differential mechanism.
Definition DifferentialMechanism.hpp:51
ctre::phoenix::StatusCode SetControl(controls::PositionVoltage AverageRequest, controls::PositionVoltage DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::PositionTorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::VelocityVoltage AverageRequest, controls::VoltageOut DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::PositionVoltage AverageRequest, controls::VoltageOut DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::DutyCycleOut AverageRequest, controls::DutyCycleOut DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicVelocityVoltage AverageRequest, controls::VoltageOut 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.
StatusSignal< double > & GetDifferentialClosedLoopReference(bool refresh=true)
Value that the differential closed loop is targeting.
Definition DifferentialMechanism.hpp:406
DisabledReasonValue
Possible reasons for the mechanism to disable.
Definition DifferentialMechanism.hpp:56
@ 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.
DifferentialMechanism(DifferentialMotorConstants< typename MotorT::Configuration > const &constants)
Creates a new differential mechanism using two hardware::traits::CommonTalon devices.
ctre::phoenix::StatusCode SetControl(controls::DutyCycleOut AverageRequest, controls::VelocityDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
RequiresUserReasonValue GetRequiresUserReason() const
Definition DifferentialMechanism.hpp:267
ctre::phoenix::StatusCode SetControl(controls::VoltageOut AverageRequest, controls::PositionVoltage DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicExpoVoltage AverageRequest, controls::PositionVoltage DifferentialRequest)
Sets the control request for this mechanism.
void ClearUserRequirement()
Indicate to the mechanism that the user has performed the required action to resume mechanism control...
ctre::phoenix::StatusCode SetControl(controls::VoltageOut AverageRequest, controls::VelocityVoltage DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicTorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
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.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicExpoVoltage AverageRequest, controls::VoltageOut DifferentialRequest)
Sets the control request for this mechanism.
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 DifferentialMechanism.hpp:456
ctre::phoenix::StatusCode SetControl(controls::MotionMagicExpoTorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::TorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicVelocityDutyCycle AverageRequest, controls::VelocityDutyCycle 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:217
ctre::phoenix::StatusCode SetControl(controls::TorqueCurrentFOC AverageRequest, controls::TorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::PositionTorqueCurrentFOC AverageRequest, controls::TorqueCurrentFOC 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.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicTorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
DisabledReasonValue GetDisabledReason() const
Definition DifferentialMechanism.hpp:259
MotorT const & GetFollower() const
Get the Talon FX that is differential follower.
Definition DifferentialMechanism.hpp:511
ctre::phoenix::StatusCode SetControl(controls::MotionMagicVelocityDutyCycle AverageRequest, controls::DutyCycleOut DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicExpoTorqueCurrentFOC AverageRequest, controls::TorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetNeutralOut()
Request neutral output of mechanism.
ctre::phoenix::StatusCode SetControl(controls::PositionTorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicVelocityDutyCycle AverageRequest, controls::PositionDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::TorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest)
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 DifferentialMechanism.hpp:426
ctre::phoenix::StatusCode SetControl(controls::VelocityTorqueCurrentFOC AverageRequest, controls::TorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::VelocityVoltage AverageRequest, controls::PositionVoltage DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicVelocityTorqueCurrentFOC AverageRequest, controls::PositionTorqueCurrentFOC 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.
MechanismState GetMechanismState() const
Gets the state of the mechanism.
Definition DifferentialMechanism.hpp:239
ctre::phoenix::StatusCode SetControl(controls::PositionDutyCycle AverageRequest, controls::PositionDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicVelocityVoltage AverageRequest, controls::VelocityVoltage DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicVelocityVoltage AverageRequest, controls::PositionVoltage DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicVelocityTorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicVoltage AverageRequest, controls::VoltageOut DifferentialRequest)
Sets the control request for this mechanism.
void Periodic()
Call this method periodically to automatically protect against dangerous fault conditions and keep Ge...
StatusSignal< units::turns_per_second_t > & GetDifferentialVelocity(bool refresh=true)
Differential component of the mechanism velocity.
Definition DifferentialMechanism.hpp:339
ctre::phoenix::StatusCode SetControl(controls::PositionDutyCycle AverageRequest, controls::VelocityDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::PositionVoltage AverageRequest, controls::VelocityVoltage DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::VelocityDutyCycle AverageRequest, controls::DutyCycleOut DifferentialRequest)
Sets the control request for this mechanism.
StatusSignal< double > & GetAverageClosedLoopReference(bool refresh=true)
Value that the average closed loop is targeting.
Definition DifferentialMechanism.hpp:355
RequiresUserReasonValue
Possible reasons for the mechanism to require user action to resume control.
Definition DifferentialMechanism.hpp:88
ctre::phoenix::StatusCode SetControl(controls::MotionMagicExpoDutyCycle AverageRequest, controls::VelocityDutyCycle 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.
StatusSignal< units::turn_t > & GetDifferentialPosition(bool refresh=true)
Differential component of the mechanism position.
Definition DifferentialMechanism.hpp:321
ctre::phoenix::StatusCode SetControl(controls::MotionMagicTorqueCurrentFOC AverageRequest, controls::TorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
MotorT & GetFollower()
Get the Talon FX that is differential follower.
Definition DifferentialMechanism.hpp:500
ctre::phoenix::StatusCode SetCoastOut()
Request coast neutral output of mechanism.
ctre::phoenix::StatusCode SetControl(controls::VelocityVoltage AverageRequest, controls::VelocityVoltage DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::PositionDutyCycle AverageRequest, controls::DutyCycleOut 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::MotionMagicExpoDutyCycle AverageRequest, controls::PositionDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
StatusSignal< units::turns_per_second_t > & GetAverageVelocity(bool refresh=true)
Average component of the mechanism velocity.
Definition DifferentialMechanism.hpp:303
DifferentialMechanism(DifferentialMotorConstants< typename MotorT::Configuration > const &constants, hardware::CANcoder &cancoder)
Creates a new differential mechanism using two hardware::traits::CommonTalon devices and a hardware::...
bool RequiresUserAction() const
Get whether the mechanism is currently disabled and requires user action to re-enable mechanism contr...
Definition DifferentialMechanism.hpp:229
ctre::phoenix::StatusCode SetControl(controls::VelocityTorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::VelocityDutyCycle AverageRequest, controls::PositionDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
DifferentialMechanism(DifferentialMotorConstants< typename MotorT::Configuration > const &constants, hardware::Pigeon2 &pigeon2, DifferentialPigeon2Source pigeonSource)
Creates a new differential mechanism using two hardware::traits::CommonTalon devices and a hardware::...
ctre::phoenix::StatusCode SetControl(controls::MotionMagicVelocityTorqueCurrentFOC AverageRequest, controls::TorqueCurrentFOC 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.
DifferentialMechanism(DifferentialMotorConstants< typename MotorT::Configuration > const &constants, hardware::CANdi &candi, DifferentialCANdiSource candiSource)
Creates a new differential mechanism using two hardware::traits::CommonTalon devices and a hardware::...
MotorT & GetLeader()
Get the Talon FX that is differential leader.
Definition DifferentialMechanism.hpp:476
MotorT const & GetLeader() const
Get the Talon FX that is differential leader.
Definition DifferentialMechanism.hpp:488
StatusSignal< units::turn_t > & GetAveragePosition(bool refresh=true)
Average component of the mechanism position.
Definition DifferentialMechanism.hpp:285
ctre::phoenix::StatusCode SetControl(controls::MotionMagicDutyCycle AverageRequest, controls::VelocityDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicExpoTorqueCurrentFOC AverageRequest, controls::VelocityTorqueCurrentFOC DifferentialRequest)
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 DifferentialMechanism.hpp:373
ctre::phoenix::StatusCode SetControl(controls::VelocityDutyCycle AverageRequest, controls::VelocityDutyCycle DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicExpoDutyCycle AverageRequest, controls::DutyCycleOut DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::MotionMagicExpoVoltage AverageRequest, controls::VelocityVoltage DifferentialRequest)
Sets the control request for this mechanism.
StatusSignal< double > & GetDifferentialClosedLoopError(bool refresh=true)
The difference between target differential reference and current measurement.
Definition DifferentialMechanism.hpp:443
StatusSignal< double > & GetAverageClosedLoopError(bool refresh=true)
The difference between target average reference and current measurement.
Definition DifferentialMechanism.hpp:390
ctre::phoenix::StatusCode SetControl(controls::MotionMagicDutyCycle AverageRequest, controls::DutyCycleOut DifferentialRequest)
Sets the control request for this mechanism.
ctre::phoenix::StatusCode SetControl(controls::VoltageOut AverageRequest, controls::VoltageOut DifferentialRequest)
Sets the control request for this mechanism.
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