View Single Post
  #17   Spotlight this post!  
Unread 24-11-2015, 22:27
riftware riftware is offline
Parent Mentor
AKA: Andrew Chandler
FRC #0031
Team Role: Mentor
 
Join Date: Dec 2013
Rookie Year: 2011
Location: Tulsa
Posts: 27
riftware is an unknown quantity at this point
Re: Using encoder with talon SRX

Ok - I seem to have gotten it working. Understanding is coming slowly. By calling set or setPosition (either seems to work?) I am basically telling the system the encoder current position is 9158 away from a 0 error state, at which point the PID system works to try and correct that. These values seem to work for me, not really sure why (placebo effect maybe?) but the longer version of setPid really seemed to cut down on the overshoot issue. The following code isn't pretty and I'm definitely cleaning it up but it gives me repeatable results. If anyone has any comments or wants to help me know why the values I've chosen seem to work well I'll be happy but I'm no longer banging my head against the wall. Thank you to everyone who patiently helped out. I'm excited that we may have a more intelligent autonomous mode than previous years (drive forward 4 seconds to get into next zone).
Code:
    protected void execute() {
    	if(busy) {return;}
    	busy = true;
    	finished = false;
    	System.out.println("Start of Execute");
    	RobotDrive drive = RobotMap.driveSystemdrive;
    	CANTalon talon =  RobotMap.driveSystemCANTalon2;
    	talon.changeControlMode(ControlMode.Position); //Change control mode of talon, default is PercentVbus (-1.0 to 1.0)
    	talon.setFeedbackDevice(FeedbackDevice.QuadEncoder); //Set the feedback device that is hooked up to the talon
    
    	talon.setPID(0.5, 0.001, 0.00, 0.00, 360, 36, 0); //Set the PID constants (p, i, d)
    	
    	talon.enableControl(); //Enable PID control on the talon
    	int currentPosition = talon.getEncPosition();
    	System.out.println(currentPosition);
    	talon.setPosition( 9158); 
    }

// Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
    	if(RobotMap.driveSystemCANTalon2.getPosition() < 80){
    		finished = true;
    		busy = false;
    	}
        return finished;
    }
Reply With Quote