Hello,
I made a post while ago about followers not working. Our team implemented the changes in the post, such as setting the control of the follower motor in the constructor and not setting any control in moving the motor. In our code, we currently use the same TalonFX config for the leader motor as the follower motor. We have also tried using a completely new TalonFX configuration for the follower motor (with the same setup and also with zero setup) but that did not work (not shown here).
public class PivotSubsystem extends SubsystemBase {
private final CANcoder pivotEncoder;
private final TalonFX leaderPivotMotor;
private final TalonFX followerPivotMotor;
private final Follower follower;
public PivotSubsystem() {
leaderPivotMotor = new TalonFX(PivotConstants.LEADER_PIVOT_MOTOR_ID);
followerPivotMotor = new TalonFX(PivotConstants.FOLLOWER_PIVOT_MOTOR_ID);
mmRequest = new MotionMagicVoltage(0);
follower = new Follower(leaderPivotMotor.getDeviceID(), true);
speakerAngleLookupValues = new SingleLinearInterpolator(PivotConstants.SPEAKER_PIVOT_POSITION);
TalonFXConfiguration pivotConfig = new TalonFXConfiguration();
pivotConfig.Slot0.kP = PivotConstants.PIVOT_P;
pivotConfig.Slot0.kI = PivotConstants.PIVOT_I;
pivotConfig.Slot0.kD = PivotConstants.PIVOT_D;
pivotConfig.Slot0.kG = PivotConstants.PIVOT_G;
pivotConfig.MotionMagic.MotionMagicAcceleration = 4;
pivotConfig.MotionMagic.MotionMagicCruiseVelocity = 10;
pivotConfig.MotorOutput.NeutralMode = NeutralModeValue.Brake;
pivotConfig.MotorOutput.Inverted = InvertedValue.Clockwise_Positive;
pivotConfig.MotorOutput.DutyCycleNeutralDeadband = HardwareConstants.MIN_FALCON_DEADBAND;
pivotConfig.Feedback.FeedbackSensorSource = FeedbackSensorSourceValue.RemoteCANcoder;
// pivotConfig.Feedback.FeedbackRemoteSensorID = pivotEncoder.getDeviceID();
pivotConfig.SoftwareLimitSwitch.ForwardSoftLimitThreshold = PivotConstants.MAX_ANGLE;
pivotConfig.SoftwareLimitSwitch.ReverseSoftLimitThreshold = PivotConstants.MIN_ANGLE;
pivotConfig.SoftwareLimitSwitch.ForwardSoftLimitEnable = true;
pivotConfig.SoftwareLimitSwitch.ReverseSoftLimitEnable = true;
leaderPivotMotor.getConfigurator().apply(pivotConfig, HardwareConstants.TIMEOUT_S);
followerPivotMotor.getConfigurator().apply(pivotConfig, HardwareConstants.TIMEOUT_S);
followerPivotMotor.setControl(follower);
}
public void setPivot(double angle) {
leaderPivotMotor.setControl(mmRequest.withPosition(angle));
}