Currently, I have a drivetrain that uses Cimcoders. The encoder works well and is plugged into the DIO port. However, when I program more than one encoder for the robot; it reports a problem saying that it cannot initialize the robot. How can I add multiple encoders without getting errors? Example is below.
//Declaring encoder
Encoder encoder = new Encoder(0, 1, false, Encoder.EncodingType.k2X);
//Setting dpp
encoder.setDistancePerPulse(4.0/256.0);
//Calling it in smarthdashboard
double dist = encoder.getDistance():
Smartdashboard.putNumber(“Encoder”, dist);
P.S. after running this it works fine until I add another encoder with different port numbers
What is the code that doesn’t work?
Are you declaring the second encoder as a different encoder? As in…
//Declaring encoder 1
Encoder encoder1 = new Encoder(0, 1, false, Encoder.EncodingType.k2X);
//Here now it needs to have a new name and new pins
Encoder encoder2 = new Encoder(2, 3, false, Encoder.EncodingType.k2X);
//Setting dpp for both
encoder1.setDistancePerPulse(4.0/256.0);
encoder2.setDistancePerPulse(4.0/256.0);
//Calling it in smarthdashboard
double dist1 = encoder1.getDistance():
Smartdashboard.putNumber(“Encoder1”, dist1);
double dist2 = encoder2.getDistance():
Smartdashboard.putNumber(“Encoder2”, dist2);
Or did you just redeclare it with new pins but still encoder?
Yes, I’m declaring and running the encoders exactly like that.