Quote:
Originally Posted by curtis0gj
Just curious about the set distance per pulse function. Is this function the ratio between how far each pulse will take the robot?
For example if I were to calculate the circumference of the wheel (in inches). Then divide the circumference of the wheel by the number of pulses in a full revolution (which is 1440 I think if I am using x4 encoding). Then set the distance per pulse to the circumference/number of pulses in one revolution would it make one full revolution move the robot one inch?
Sorry if this is not clear enough I can try to clarify if it makes zero sense.
|
That's the right process. However, wpilib normalizes pulses, so it won't change by decoding type. You should use 360 pulses in a full revolution, but it will increment in 1/4 increments in 4x mode. In addition, you'll want to take into account any gearing between the encoder and the wheel.
Code:
//Encoder Distance Constants
public static final double wheelDiameter = 6;
public static final double pulsePerRevolution = 360;
public static final double encoderGearRatio = 3;
public static final double gearRatio = 64.0/20.0;
public static final double Fudgefactor = 1.0;
final double distanceperpulse = Math.PI*wheelDiameter/pulsePerRevolution /
encoderGearRatio/gearRatio * Fudgefactor;
driveTrainEncoderL.setDistancePerPulse(distanceperpulse);