I’ve been scratching my head this whole week about this issue. I have 2 methods to drive the robot, one is direct tank drive and one is tank drive with a pid loop. Here’s the code:
public void drive(double left, double right) {
// Probably too low
double kP = .02;
m1.set(pControl(left, kP, m1.getSpeed()));
m2.set(pControl(right, kP, m2.getSpeed()));
m3.set(pControl(left, kP, m3.getSpeed()));
m4.set(pControl(right, kP, m4.getSpeed()));
}
public double pControl(double setPoint, double kP, double cur) {
double error = setPoint - cur;
return cur + (error * kP);
}
public void setSpeed(double left, double right) {
m1.set(left);
m2.set(right);
m3.set(left);
m4.set(right);
}
The setSpeed method works perfectly, but the drive method only turns the right side wheels. There’s no issue with the speed controllers or joystick because setSpeed works fine and I even put the getSpeed values to the smart dashboard which seem correct. In the pControl method, I printed the values to the smart dashboard and error, setpoint, and kP all appear correct but the return value is always 0. Anyone know why this is happening?