TalonSRX Control Position Not Setting Elevator Position

talonsrx

#1

Hi all,

I’m trying to implement a setPosition() command that sets our elevatorSubsystem to a specific height. After some testing, it was found that the command was being called, however, the SRX wasn’t setting the height to the value. Check out the code below. Thanks in advance!

Robot.java:
manipulatorGamepad.buttonPressed(BionicF310.A, new SetElevatorPosition(-27220,1));

ElevatorSubsytem.java:

public class ElevatorSubsystem extends Subsystem{
WPI_VictorSPX leftSPX, rightSPX1, rightSPX2;
WPI_TalonSRX leftSRX;

public int holdingPosition;

public ElevatorSubsystem() {

    //Lift
    leftSRX = new WPI_TalonSRX(RobotMap.elevatorSRXID);  //master SRX
    leftSPX = new WPI_VictorSPX(RobotMap.elevatorSPX1ID); //slave SPX 1
    rightSPX1 = new WPI_VictorSPX(RobotMap.elevatorSPX2ID); //slave SPX 2
    rightSPX2 = new WPI_VictorSPX(RobotMap.elevatorSPX3ID); //slave SPX 3

    

    leftSPX.follow(leftSRX);  //All slaves will output the same value as the master SRX
    rightSPX1.follow(leftSRX);  
    rightSPX2.follow(leftSRX);
    
    rightSPX1.setInverted(true);
    rightSPX2.setInverted(true);
    leftSRX.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative);
    leftSRX.config_kP(1, 0.6, 0);
    leftSPX.config_kI(1, 0);
    leftSPX.config_kD(1, 0);
    
}

public void setPosition(int position){
leftSRX.set(ControlMode.Position, position);
}
}

Command:

public class SetElevatorPosition extends InstantCommand {
private int setpoint, threshold;

public SetElevatorPosition(int setpoint, int threshold) {
    this.setpoint = setpoint;  
    this.threshold = threshold;     
    requires(Robot.elevatorSubsystem);
}

@Override
public void initialize() {
    Robot.elevatorSubsystem.setPosition(setpoint);

}

@Override
protected boolean isFinished() {
    return false;  //done for testing purposes
}

}


#2

What are the symptoms of it not going to the position? Does it move at all, does it stop short, does it oscillate around the position without settling?

There are a number of things that could be going wrong, but helping you diagnose it will require a lot more information.

For example, in the code you posted the command never returns. That doesn’t affect the Talon closed loop, but it certainly messes with the rest of the robot interaction with that command.


#3

The elevator doesn’t move at all when we click A.


#4

I believe you’re loading your talon gains into profile slot 1 with leftSRX.config_kP(1, 0.6, 0); and you may need to select that with .selectProfileSlot(1, 0); (I believe it defaults to 0, @ozrien could clarify)

You also are setting your I and D gains on the leftSPX instead of the left SRX, which without a remote sensor isn’t affecting anything (also with 0 values are not affecting anything).


#5

Yeah, just noticed the SPX/SRX mixup. I added the .selectProfileSlot(1,0) line and will test that shortly. I’ll update this thread after. Thank you all!


#6

+1

But the bigger problem seems like you are skipping steps.
Do your sensor bring-up first so you know the sensor is worth using. This is necessary for kF calcs, sensor-phasing, and general testing of the sensor so you don’t waste time chasing your tail.
https://phoenix-documentation.readthedocs.io/en/latest/ch14_MCSensor.html

Then closed-loop.
https://phoenix-documentation.readthedocs.io/en/latest/ch16_ClosedLoop.html

Grab an already tested example that is close to what you need to save time.


… use it out-of-box first with minor tweaks, then integrate it into your project.


#7

Did using " .selectProfileSlot(1,0)" work for you? We’re running into this same issue and don’t see that method being used anywhere in the Phoenix-Languages examples.


#8

Yes. Make sure that you are configuring the PID values to the correct slot and choosing that slot using .selectProfileSlot() as well. We also recommend calling .super() and .configureFactoryDefault() as well prior.