We are using VersaPlanetary Integrated Encoder and we have wired them up straight to the talon.
I have been trying for a while yet I can’t grab any data from the encoder. Another thing, I don’t know if it is important but I can’t see the encoders on the Phoenix Tuner. The encoders’ lights are on.
Here’s my code
public class Elevator extends Subsystem {
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
private WPI_TalonSRX elevatorMotor;
private Encoder elevatorEncoder;
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
private double encoderMax = 100;
public Elevator() {
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
elevatorMotor = new WPI_TalonSRX(1);
elevatorEncoder = new Encoder(0, 1, false, EncodingType.k4X);
addChild("ElevatorEncoder",elevatorEncoder);
elevatorEncoder.setDistancePerPulse(1.0);
elevatorEncoder.setPIDSourceType(PIDSourceType.kDisplacement);
elevatorMotor.set(ControlMode.Position, 0);
elevatorMotor.configSelectedFeedbackSensor(FeedbackDevice.QuadEncoder, 0,10);
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
}
It looks like you have an Encoder in the code being initialized, that doesn’t do anything. Because you have it wired directly to the talon, you won’t be using elevatorEncoder.
Assuming you have your quad encoder set up correctly, you can configure the elevatorMotor PID values and then, when the robot is enabled, you can call elevatorMotor.set(ControlMode.Position, desiredPositionInQuadEncoderCounts). Calling that when the robot is disabled should do nothing.
If you want to re-zero the encoder counts, you do not use elevatorMotor.set, you use elevatorMotor.setSelectedSensorPosition(position) and would probably put 0 in for position.
For the elevatorMotor.set(ControlMode.Position, desiredPosition) to work, you need to configure the PID values of elevatorMotor. You can do this by calling elevatorMotor.config_k* methods.
Also, as a suggestion, I recommend calling elevatorMotor.configFactoryDefault(). This makes sure there aren’t any settings that you don’t know about on there.
Basically, run the PID on the Talon, instead of within WPIlib using their PID classes. More info on that is available in the Talon SRX Software Manual.
You can follow along our Github if you’d like for examples.
We have our encoders plugged directly into the Talons, and we’re using MotionMagic for the PID controls (which I highly recommend).
Our Command class we’re using is called DriveMM where we use MotionMagic to drive to a distance with our encoders.
You’ll need to use your own kF, kP, kI, and kD calculations, and our calculations are based off of using a Grayhill 63R128 encoder (128/rot) so you’d need to substitute in those as well. Once you have the PID values tuned and set in the Talon the motion magic is easy-peasy.