Problem With Talon SRX PID Control

Hey CD,
Right now I’m working on a PID control using the TalonSRX built in closed loop controls and nothing is working.
I try to use the Speed control mode (TalonControlMode.Speed), I set everything just as they did in the examples that CTRE provided and either nothing is happening or it goes full speed even though I try and set it to 30 RPM.
Using the SRX Magnetic Encoder

Here is the code:


package org.usfirst.frc.team5951.robot;

import com.ctre.CANTalon;
import com.ctre.CANTalon.FeedbackDevice;
import com.ctre.CANTalon.TalonControlMode;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the IterativeRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Robot extends IterativeRobot {

	private CANTalon flywheelMotor;
	private XboxController controller;
	
	/**
	 * This function is run when the robot is first started up and should be
	 * used for any initialization code.
	 */
	@Override
	public void robotInit() {
		this.flywheelMotor = new CANTalon(8);
		this.flywheelMotor.changeControlMode(TalonControlMode.Speed);
        this.flywheelMotor.setFeedbackDevice(FeedbackDevice.CtreMagEncoder_Relative);
        this.flywheelMotor.reverseSensor(true);
        this.flywheelMotor.setInverted(true);
        this.flywheelMotor.configNominalOutputVoltage(0.0f, -0.0f);
        this.flywheelMotor.configPeakOutputVoltage(+12.0f, -12.0f);
        this.flywheelMotor.setPosition(0);
        this.flywheelMotor.setProfile(0);
        this.flywheelMotor.setF(0);
        this.flywheelMotor.setP(0.2);
        this.flywheelMotor.setI(0.00);
		
		this.controller = new XboxController(0);
	}

	/**
	 * This autonomous (along with the chooser code above) shows how to select
	 * between different autonomous modes using the dashboard. The sendable
	 * chooser code works with the Java SmartDashboard. If you prefer the
	 * LabVIEW Dashboard, remove all of the chooser code and uncomment the
	 * getString line to get the auto name from the text box below the Gyro
	 *
	 * You can add additional auto modes by adding additional comparisons to the
	 * switch structure below with additional strings. If using the
	 * SendableChooser make sure to add them to the chooser code above as well.
	 */
	@Override
	public void autonomousInit() {
	}

	/**
	 * This function is called periodically during autonomous
	 */
	@Override
	public void autonomousPeriodic() {
	}

	/**
	 * This function is called periodically during operator control
	 */
	@Override
	public void teleopPeriodic() {
		if(this.controller.getAButton()) {
			this.flywheelMotor.set(40);
		} else if(this.controller.getYButton()) {
			this.flywheelMotor.set(0);
		}
		SmartDashboard.putNumber("Speed: ", this.flywheelMotor.getPosition());
		SmartDashboard.putNumber("Error: ", this.flywheelMotor.getError());
	}

	/**
	 * This function is called periodically during test mode
	 */
	@Override
	public void testPeriodic() {
	}
}


What am I missing?

The first thing I always suspect on a runaway is that the encoder is backwards or not working.
What are the outputs of your dashboard printouts (Speed and Error)? How do they change over time?

When something does move (and usually goes full speed), the speed goes up and the error gets negative because the error is negative.

Try also printing the speed. Does the speed ever reach the set point (40)? - note that you are doing a getPosition(), not a getSpeed(), even though you are logging it to the dashboard as Speed…

Right now I’m suspecting it’s a talon fault. The PID works on another talon, will update soon

Sent from my Redmi Note 4 using Tapatalk

Make sure the talons have the latest firmware installed. That often fixes problems where code works on one talon but not an another.