TalonSRX Position Control Mode Not Stopping

I am trying to implement the TalonSRX positional control mode on our elevator subsystem this year, however when I go to run the method which activates the elevator, it begins to ramp up, but quickly speeds up past the target position I passed to the method and does not stop. I tried to drastically lower all my PID values, but I could not find any working combination. I also tried to simplify my code, but I had no success. I am in Command-Based Java.

Thanks for any Help.

Subsystem:

public void setPIDValues() {
elevatorA.config_kP(0, 0.005);
elevatorA.config_kI(0, 0.05);
elevatorA.config_kD(0, 0.001);
}

public void setElevatorPID(double targetPosition) {
//PID Values
setPIDValues();

//Elevator Direction
if(targetPosition > getPosition()) {
  isRaising = true;
  isLowering = false;
}
else if(targetPosition < getPosition()) {
  isRaising = false;
  isLowering = true;
}
else {
  isRaising = false;
  isLowering = false;
}

//Cargo or Hatch Levels?
if(isCargoMode) {
  low = Constants.cargoLow;
  mid = Constants.cargoMid;
  high = Constants.cargoHigh;
}
else {
  low = Constants.hatchLow;
  mid = Constants.hatchMid;
  high = Constants.hatchHigh;
}

//Powering Elevator
if(!getLimit()) {
  elevatorA.set(ControlMode.Position, targetPosition);
  elevatorB.follow(elevatorA);  
}
else {
  elevatorA.set(ControlMode.PercentOutput, 0);
  elevatorB.follow(elevatorA);
}

elevatorA.setNeutralMode(NeutralMode.Brake);
elevatorB.setNeutralMode(NeutralMode.Brake);

}

public void setupEncoder() {
elevatorA.configSelectedFeedbackSensor(FeedbackDevice.QuadEncoder);
}

Command:

public class SetElevatorPID extends Command {
double targetPosition;

public SetElevatorPID(double targetPosition) {
this.targetPosition = targetPosition;
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
}

// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.elevator.setupEncoder();
}

// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
Robot.elevator.setElevatorPID(targetPosition);
}

// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return false;
}

// Called once after isFinished returns true
@Override
protected void end() {
Robot.elevator.stopElevator();
}

// Called when another command which requires one or more of the same
// subsystems is scheduled to run
@Override
protected void interrupted() {
Robot.elevator.stopElevator();
}
}

There are two likely possibilities:

  1. Your units are wrong, and your target position is not where you think it is. You can check this by putting the relevant values on smartdashboard and watching them in real-time.

  2. Your integral gain is causing you to overshoot the setpoint. You can check this by setting your integral gain to zero (really, you should only use proportional gain until the thing is behaving roughly in the manner you expect of it, and integral gain is often a bad idea overall).

2 Likes

Thanks I figured it’d be something like that, I’ll check when I get back to the shop

I don’t see a call to setSensorPhase. This is the most common cause of closed-loops running away. This is also why the sensor bring-up section is before the closed-loop section.

Do this first…
https://phoenix-documentation.readthedocs.io/en/latest/ch14_MCSensor.html
… before closed-looping…
https://phoenix-documentation.readthedocs.io/en/latest/ch16_ClosedLoop.html

ahhh, thanks

If anyone has this same issue for future reference, it was the phase issue that was giving me trouble as soon as I flipped it it was working

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.