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();
}
}