CANTalon PIDF close loop error is offset by a wide margin

Hey everyone!

My team is trying to tune our robot’s shooter velocity with TalonSRX’s built-in PIDF closed loop. However, when running the shooter motors the closed loop error is significantly below its expected value. This makes the motor controller think that the shooter motor is always below the target speed, even when that isn’t the case.

We’re using Talon SRX’s with a Versaplanetary encoder stage from Vexpro. They are running two 775 motors in parallel at the same time. We’re using the two motors in a master-follower setup.

Here are two graphs we recorded on SmartDashboard during testing. The graph on the left is the recorded motor speed while the graph on the right is the closed loop error calculated by the Talon motor controller.

https://lh4.googleusercontent.com/aBBzXg__SpZmygrm4V8pw3BdI8ZIKIcCQc8KvzqPdy4Cshr8uqHbgSQnyuWVi8WDfcOAe_DEp2XnQik=w1366-h700-rw

The recorded speed values are accurate, and every number input in the picture is used in our closed loop.

We’ve tried many different approaches to fixing the problem, including reversing the motor sensors, updating the Java SRX libraries and the firmware on each Talon (both currently at the latest firmware version), and have searched through the Talon SRX software reference manual

Here are screenshots from the Rio Motor Controller Web Server:

Master Motor:
https://lh3.googleusercontent.com/S2EuA6FCL0_7B7WlOisWcRKErjkac4fM6gBLGUihxhvFx5sYZwN5oJkzGrc9O9SBP7xZB1E5KB-JcF4=w1366-h651-rw

Follower/Slave Motor:
https://lh4.googleusercontent.com/r8ezK_PrRWTwNcJX6iD9zA0OWT-0iY3UUagPZz0iRreNJ5zggAAcaQpvtzpPyf3udSxdFg2ie18G5Pk=w1366-h651-rw

(Note, These motors were updated with a Closed Loop P value of 0.1, not 0.6 as seen in the graphs.)

Here is the Java source code we used for our tests:


public class Robot extends IterativeRobot {

    CANTalon shooterMotorA, shooterMotorB;

    @Override
    public void robotInit() {
        shooterMotorA = new CANTalon(0);
        shooterMotorB = new CANTalon(5);

        shooterMotorA.enableBrakeMode(false);
        shooterMotorB.enableBrakeMode(false);

        shooterMotorA.setInverted(true);
        shooterMotorB.setInverted(true);

        shooterMotorA.setFeedbackDevice(FeedbackDevice.CtreMagEncoder_Relative);
        shooterMotorB.setFeedbackDevice(FeedbackDevice.CtreMagEncoder_Relative);

        shooterMotorA.changeControlMode(TalonControlMode.Speed);
        shooterMotorB.changeControlMode(TalonControlMode.Follower);

        shooterMotorB.set(shooterMotorA.getDeviceID());

        shooterMotorA.configEncoderCodesPerRev(1024);

        shooterMotorA.reverseSensor(true);

        // Initialize Smart Dashboard values
        SmartDashboard.putNumber("Shooter Target Speed", 0.0);
        SmartDashboard.putNumber("P ShooterAccelerate", 0.0);
        SmartDashboard.putNumber("I ShooterAccelerate", 0.0);
        SmartDashboard.putNumber("D ShooterAccelerate", 0.0);
        SmartDashboard.putNumber("F ShooterAccelerate", 0.0);
    }

 
    @Override
    public void teleopPeriodic() {
        shooterMotorA.setPID(
                SmartDashboard.getNumber("P ShooterAccelerate", 0.0),
                SmartDashboard.getNumber("I ShooterAccelerate", 0.0),
                SmartDashboard.getNumber("D ShooterAccelerate", 0.0)
                );
        shooterMotorA.setF(SmartDashboard.getNumber("F ShooterAccelerate", 0.0));

        shooterMotorA.set(SmartDashboard.getNumber("Shooter Target Speed", 0.0));

        // Logs and Feedback
        SmartDashboard.putNumber("PID ShooterAccelerate OUTPUT", 
                shooterMotorA.getEncVelocity());
        SmartDashboard.putNumber("PID ShooterAccelerate ERROR",
                shooterMotorA.getClosedLoopError());
    }

}