We’re using two talon SRX to drive two motors that have the REV through bore encoder attached. Using the encoders and doing a standard Encoder + PIDController from WPILib works only OK (even after looking at this PSA, so we wanted to try running the encoders and PIDs from the Talons.
Wired them up with a JTAG breakout board and I can see activity in Phoenix Tuner. With PID=0 we figured out an F that gets it pretty close. As soon as we add some P everything goes wild.
At P=0.01 it doesn’t look like the error ever gets smaller. At P=0.05 the motor goes to full speed. On values lower than that I see the motor barely turning, or it turns backwards (from the graphs, looks like it starts spinning the right way then quickly reverses).
The code is basically:
WPI_TalonSRX _talon = new WPI_TalonSRX(port);
_talon.configFactoryDefault(0);
_talon.setNeutralMode(NeutralMode.Coast);
_talon.configSelectedFeedbackSensor(FeedbackDevice.QuadEncoder, Constants.kPIDLoopIdx, Constants.kTimeoutMs);
_talon.setSensorPhase(false);
/* Config the peak and nominal outputs */
_talon.configNominalOutputForward(0, Constants.kTimeoutMs);
_talon.configNominalOutputReverse(0, Constants.kTimeoutMs);
_talon.configPeakOutputForward(1, Constants.kTimeoutMs);
_talon.configPeakOutputReverse(-1, Constants.kTimeoutMs);
/* Config the Velocity closed loop gains in slot0 */
_talon.config_kF(Constants.kPIDLoopIdx, ShooterConstants.kF, Constants.kTimeoutMs);
_talon.config_kP(Constants.kPIDLoopIdx, ShooterConstants.kP, Constants.kTimeoutMs);
_talon.config_kI(Constants.kPIDLoopIdx, ShooterConstants.kI, Constants.kTimeoutMs);
_talon.config_kD(Constants.kPIDLoopIdx, ShooterConstants.kD, Constants.kTimeoutMs);
_talon.configClosedLoopPeriod(Constants.kPIDLoopIdx, Constants.kPIDLoopTimeMs, Constants.kTimeoutMs); // 1ms loop
and then to shoot:
_talon.set(ControlMode.Velocity, ticksPer100ms);
I’m lost as to what to look at next. I’ve been looking at the CTRE docs and was trying to do the tuning entirely in Phoenix Tuner to rule out code problems but I can’t get around that FRC lock even after uploading a dummy project and resetting everything.
I should also mention we’re using velocity control with the CTRE mag encoder on our drive train and it works beautifully. Other than the sensor phase and using quadrature instead of CTRE_Mag it’s the same code.
Any guidance would be appreciated, thanks!
Sean