View Single Post
  #9   Spotlight this post!  
Unread 24-11-2015, 00:13
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 - so I got my hardware setup. I have 2 talon srx's setup with 2 of the optical encoders from andymark. I created a test button and added the following to the execute on the command for the button. It starts and stops the motor but I'm not sure it is really doing what I want. Basically I'm working towards a command that will cause the robot to travel forward x inches to be used in autonomous mode. The code below is what I used...the position on the encoder doesn't seem to wind up anywhere close to where I expect it to be also I think I'd have better results if it was running slower or there was a load on the wheel. The output from the print statements is before the code for ease of following. Obviously I'm totally overlooking something so any guidance is appreciated.


Start of Execute
-264
-264


Code:
    	System.out.println("Start of Execute");
    	RobotDrive drive = RobotMap.driveSystemdrive;
    	CANTalon talon =  RobotMap.driveSystemCANTalon1;
    	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.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.set(5000); //Tells the talon to go to 5000 encoder counts, using the preset PID parameters.
    	System.out.println(talon.getEncPosition());
    	finished = true;
Reply With Quote