So we can properly adjust the speed of a motor using encoder feedback when everything except that one motor and its corresponding encoder and PIDController is commented out. We can get the left front motor and left back motor to work separately, but when we try to get them to work together, both motors alternate running full speed forward and full speed backward, no matter what the joystick input is.
How can we get both motors to work simultaneously with PID?
(Yes, I know it’s strange to operate to operate two motors on the same side with two different joysticks, but we’re just trying to test the encoders.)
public class Mechanum
private final Encoder frontLeft = new Encoder(6,7); private final Encoder backLeft = new Encoder(8,9); private final double Kp = 1.0; private final double Ki = 0.0; private final double Kd = 0.0; private PIDController leftFrontPID; private PIDController leftBackPID;
frontLeftMotor = new Jaguar(1);
rearLeftMotor = new Jaguar(2);
frontLeft.setDistancePerPulse(0.067631); backLeft.setDistancePerPulse(0.067631); frontLeft.start(); backLeft.start();
leftFrontPID = new PIDController(Kp, Ki, Kd, frontLeft, frontLeftMotor);
leftBackPID = new PIDController(Kp, Ki, Kd, backLeft, rearLeftMotor);
leftFrontPID.enable(); leftBackPID.enable(); leftFrontPID.setInputRange(-1.0, 1.0); leftBackPID.setInputRange(-1.0, 1.0);
public void driveWithEncoders()