Pairing an absolute CANcoder directly with a Talon FX motor controller enables high-speed, 1 kHz onboard closed-loop control referenced to the true mechanism output shaft. Offloading the sensor loop to the motor controller eliminates roboRIO loop jitter, CAN communication delays, and backlash discrepancies between the motor rotor and final driven joint.
Feedback Sensor Coupling Modes
Section titled “Feedback Sensor Coupling Modes”| Feedback Mode | Mechanism Layout | Behavior |
|---|---|---|
| RemoteCANcoder | CANcoder mounted on output shaft | Closed loop controls position purely from CANcoder readings over CAN. |
| FusedCANcoder | CANcoder on output shaft, motor rotor coupled | Fuses high-speed rotor velocity with absolute CANcoder position to eliminate gear lash. |
| SyncCANcoder | Multi-turn mechanisms with backlash | Synchronizes rotor position with CANcoder absolute angle on power-up and runs on rotor encoder. |
Production Implementation
Section titled “Production Implementation”The following example configures a Talon FX paired directly with a remote CANcoder mounted to an arm or turret output shaft using Phoenix 6 FusedCANcoder mode.
package frc.robot.subsystems;
import com.ctre.phoenix6.configs.CANcoderConfiguration;import com.ctre.phoenix6.configs.TalonFXConfiguration;import com.ctre.phoenix6.controls.MotionMagicVoltage;import com.ctre.phoenix6.hardware.CANcoder;import com.ctre.phoenix6.hardware.TalonFX;import com.ctre.phoenix6.signals.FeedbackSensorSourceValue;import com.ctre.phoenix6.signals.NeutralModeValue;import com.ctre.phoenix6.signals.SensorDirectionValue;
import edu.wpi.first.units.measure.Angle;import static edu.wpi.first.units.Units.*;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;import edu.wpi.first.wpilibj2.command.Command;import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class RemoteSensorPivotSubsystem extends SubsystemBase { private static final int MOTOR_ID = 21; private static final int CANCODER_ID = 31; private static final String CAN_BUS = "rio";
// 50:1 gear reduction between motor rotor and CANcoder output shaft private static final double GEAR_RATIO = 50.0;
private final TalonFX m_motor = new TalonFX(MOTOR_ID, CAN_BUS); private final CANcoder m_cancoder = new CANcoder(CANCODER_ID, CAN_BUS); private final MotionMagicVoltage m_motionMagic = new MotionMagicVoltage(0).withSlot(0);
public RemoteSensorPivotSubsystem() { configureSensorsAndMotor(); }
private void configureSensorsAndMotor() { // 1. Configure the remote absolute CANcoder CANcoderConfiguration encoderConfig = new CANcoderConfiguration(); encoderConfig.MagnetSensor.SensorDirection = SensorDirectionValue.CounterClockwise_Positive; encoderConfig.MagnetSensor.MagnetOffset = 0.145; // Calibrated magnet offset in rotations m_cancoder.getConfigurator().apply(encoderConfig);
// 2. Configure the Talon FX to track the CANcoder directly TalonFXConfiguration motorConfig = new TalonFXConfiguration(); motorConfig.MotorOutput.NeutralMode = NeutralModeValue.Brake;
// Current limits to protect gearbox and motor motorConfig.CurrentLimits.StatorCurrentLimitEnable = true; motorConfig.CurrentLimits.StatorCurrentLimit = 40.0; // 40 Amps stator limit
// Set feedback source to remote CANcoder motorConfig.Feedback.FeedbackSensorSource = FeedbackSensorSourceValue.RemoteCANcoder; motorConfig.Feedback.FeedbackRemoteSensorID = CANCODER_ID;
// SensorToMechanismRatio defines mechanism rotations per sensor rotation (1:1 on shaft) motorConfig.Feedback.SensorToMechanismRatio = 1.0; // RotorToSensorRatio accounts for the reduction between motor and CANcoder motorConfig.Feedback.RotorToSensorRatio = GEAR_RATIO;
// Slot 0 PID Gains (tuned in mechanism rotations) motorConfig.Slot0.kP = 28.0; motorConfig.Slot0.kI = 0.0; motorConfig.Slot0.kD = 1.2; motorConfig.Slot0.kV = 0.12;
// Motion Magic Profile constraints in mechanism rotations/sec motorConfig.MotionMagic.MotionMagicCruiseVelocity = 0.75; // 0.75 rot/s (270 deg/s) motorConfig.MotionMagic.MotionMagicAcceleration = 1.50; // 1.5 rot/s^2
m_motor.getConfigurator().apply(motorConfig); }
@Override public void periodic() { SmartDashboard.putNumber("Pivot/MotorPosition_Rot", m_motor.getPosition().getValueAsDouble()); SmartDashboard.putNumber("Pivot/CANcoderPosition_Rot", m_cancoder.getPosition().getValueAsDouble()); SmartDashboard.putNumber("Pivot/Current_A", m_motor.getStatorCurrent().getValueAsDouble()); }
public Command moveToAngleCommand(Angle targetAngle) { double targetMechanismRotations = targetAngle.in(Rotations); return run(() -> m_motor.setControl(m_motionMagic.withPosition(targetMechanismRotations))) .until(() -> isAtAngle(targetAngle)) .withName("MoveToAngle"); }
public boolean isAtAngle(Angle targetAngle) { double currentAngleDeg = m_motor.getPosition().getValueAsDouble() * 360.0; return Math.abs(currentAngleDeg - targetAngle.in(Degrees)) < 2.0; }}Key Failure Modes and Common Traps
Section titled “Key Failure Modes and Common Traps”- Inverted Sensor Feedback Runaway: If the motor drives forward but the CANcoder counts backward, the controller interprets the motion as negative error and increases forward voltage to maximum until hardware breaks. Always verify direction before engaging closed loop.
- Mismatched CAN Bus Names: If the Talon FX is on a CANivore (“rio” vs “canivore-name”) while the CANcoder is on the default roboRIO CAN bus, the motor controller cannot read the sensor frames. Remote sensors must share the same physical CAN bus.
- Unset Rotor-to-Sensor Ratio: When using
RemoteCANcoderorFusedCANcoder, failing to setRotorToSensorRatiocauses rapid oscillation because the controller expects 1 motor turn per sensor turn. - Magnet Distance and Green LED Status: The CANcoder magnet must sit between 0.75 mm and 1.5 mm from the sensor casing. A yellow or red status LED indicates magnet misalignment and causes non-linear feedback errors.
Before running closed loop on any remote sensor mechanism, physically rotate the mechanism by hand in the positive mechanical direction. Verify that both m_motor.getPosition() and m_cancoder.getPosition() increase positively in Phoenix Tuner X.
Bench Verification Checklist
Section titled “Bench Verification Checklist”- Verify Shared CAN Bus: Confirm in Phoenix Tuner X that both the motor controller and CANcoder reside on the identical CAN bus with green health status indicators.
- Confirm Magnet Alignment: Check the physical CANcoder status LED while sweeping the mechanism through its full range of motion. Verify the LED stays solid green across all travel.
- Validate Open-Loop Sensor Tracking: Command 1.0V forward in open-loop control. Confirm both the rotor velocity and the CANcoder velocity register positive numbers in Tuner X graphs.
- Step-Response Test at 20% Travel: Set a small position step target (for example, 0.1 rotations). Confirm the motor smoothly settles without hunting or high-frequency buzzing.
Verified Sources & Standards
- CTRE Phoenix 6 - Talon FX Remote Sensorsv6.docs.ctr-electronics.comHardware Vendor
- WPILib Sensors and Feedback Systemsdocs.wpilib.orgWPILib Standard