For PIDController(Kp, Ki, Kd, PIDSource, PIDOutput); how are you supposed to implement the parameter PIDOutput if whenever you put something in it there is always an error with the whole initialization.
What do you mean by “error”, compile error? Can you provide samples of your code?
This will completely depend on your code. Do you have runtime errors, or compilation issues?
Here’s some basic Java code that my team has used in the past to use the PIDController class from WPILib:
MyPIDOutput myPID = new MyPIDOutput();
PIDController pidDriving = new PIDController(kP, kI, kD, left_encoder, myPID);
Which requires that you (we) have also created a class called MyPIDOutput that implements the PIDOutput interface that WPILIb requires:
import edu.wpi.first.wpilibj.PIDOutput;
public class MyPIDOutput implements PIDOutput {
private double pidOutput = 0.0;
@Override
public void pidWrite(double output) {
pidOutput = output;
}
public void reset() {
pidOutput = 0.0;
}
public double get() {
return pidOutput;
}
}
You can get our entire source code for when we used the WPI PID classes from our 2017 public github:
You can then see how we used the PID driving classes to drive certain distances, turn with Gyro, etc.
@NewtonCrosby
Oh I didn’t know that the class had to implement PIDOutput.
And thanks for the explanation.
@cnc4
Here’s what I’m getting
The error I’m getting:
The constructor PIDController(int, int, int, int, PIDOutput) is undefinedJava(134217858)
What I put:
PIDController pidController = new PIDController(1, 1, 1, 1, pidOutput);
(pidOutput is just a reference variable of PIDOutput)
It looks like you need to add a PIDSource to the constructor, so it would end up like this:
PIDController pidController = new PIDController(1, 1, 1, 1, pidSource, pidOutput);
@Bag
As @jdao said, you need to give the PIDController your source - the sensor that you are using.
Read the docs for more info on using the PIDController - https://wpilib.screenstepslive.com/s/currentCS/m/java/l/599721-operating-the-robot-with-feedback-from-sensors-pid-control