I’m having trouble getting the Encoder to increment any counts on the AM-0180 using the 2015 Java API Encoder Class. getDistance() always returns 0 when stopped or -0.5 when the motor is running, getRate() always returns 0, getStopped() always returns true.
I verified the wiring is correct (orange power, brown ground, blue DIO0 signal, yellow DIO1 signal). Opening the cover, the LED transmitter is illuminated and the encoder does spin with the shaft.
Code is below. Any ideas? Could this encoder be defective? Or are others having trouble with the new API?
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
public class TestEncoder {
Encoder encoder;
public TestEncoder(int source1, int source2) {
encoder = new Encoder(source1, source2);
encoder.setDistancePerPulse(2);
encoder.reset();
}
public void printStatus() {
double rotations;
rotations=encoder.getDistance();
SmartDashboard.putNumber("Rotations", rotations);
SmartDashboard.putNumber("Rate", encoder.getRate());
SmartDashboard.putBoolean("Stopped", encoder.getStopped());
}
}