I implement different drive odometry for a robot. Trying to implement (proportional–integral–derivative controller) PID-based coordinate movements x, y, theta:
public void getX(double dt) {x += Math.cos(theta) * robotV() * dt;}
public void getY(double dt) {y += Math.sin(theta) * robotV() * dt;}
public void getTheta(double dt) {
theta += ((rightLenV()-leftLenV()) / Constants.transmission_width)*dt;
theta = adduction(theta);
}
public double adduction(double a){
while (a > Math.PI) {a = a-2*Math.PI;}
while (a < -Math.PI) {a = a+2*Math.PI;}
return a;
}
my implement pid controller (bad working)
pidControllerVelocity = new PIDController(10, 0, 5);
public void velocity(double x_W, double y_W) {
x_D = x_W - x;
y_D = y_W - y;
dS = Math.sqrt((Math.pow(x_D, 2) + Math.pow(y_D, 2)));
u = Math.atan2(y_D, x_D);
pidControllerVelocity.setSetpoint(adduction(u));
double PD_velocity = pidControllerVelocity.calculate(theta);
if (dS < 0.015) {
leftMotor.set(0);
rightMotor.set(0);
} else {
leftMotor.set(0.1+PD_velocity);
rightMotor.set(0.1-PD_velocity);
}
}
I'm working with Java library wpilib.