PID & Feed Forward Training
Prerequisites: Github, Java, Robot Code, Motor Control
Note that there are other control types other than a PID and feedforward, but once you understand how a PID and feedforward work, you can easily understand how other control types work.
What is a PID?
A PID is a control loop that uses the error between the desired value and the actual value to determine the output. The error is calculated by subtracting the actual value from the desired value. The output is then calculated by multiplying the error by the proportional, integral, and derivative constants. The output is then added to the desired value to get the final output.
This may sound complicated, but at its core, it is a simple concept. The P in a PID causes the motor to move in the direction of the error. The I in a PID causes the motor to move in the direction of the error for a longer period of time. The D in a PID causes the motor to move in the direction of the error for a shorter period of time.
The PID is a very powerful tool, but it is not perfect. It is very sensitive to noise, and it can be difficult to tune. The PID is also not very good at predicting the future. It can only react to the current error. This is where the Feed Forward comes in.
What is a Feed Forward?
A Feed Forward is a constant that is added to the output of the PID. The Feed Forward is used to predict the future. It is used to predict the future error. The Feed Forward is calculated by multiplying the desired value by the Feed Forward constant. The Feed Forward is then added to the output of the PID to get the final output.
The Feed Forward is a very powerful tool, but it is not perfect. It is very sensitive to noise, and it can be difficult to tune. The Feed Forward is also not very good at predicting the past. It can only predict the future error. This is where the PID comes in.
How do I use a PID?
A PID is used by creating a PIDController object. The PIDController object takes in the proportional, integral, and derivative constants, and the Feed Forward constant. The PIDController object also takes in the desired value, and the actual value. The PIDController object then calculates the output, and returns it.
PIDController pid = new PIDController(P_Term, I_Term, D_Term);
double output = pid.calculate(desiredValue, actualValue);
How do I use a Feed Forward?
SimpleMotorFeedForward feedForward = new SimpleMotorFeedForward(FeedForwardConstant);
feedForward.calculate(desiredValue);
How do I tune a PID & feed forward?
1) Set the P, I, and D constants to 0. Set the Feed Forward constant to 0 as well. 2) Tune the P up until the motor oscillates around the setpoint 3) Then tune the D up until the oscillations stop 4) Then tune the I up until the motor reaches the setpoint in a reasonable amount of time 1) Normally an I value should not be needed, and a P & D term is enough to reach the setpoint 5) The feed forward is tuned using a tool called SysID. See SysID Training for more information.
Training
Complete PID&FeedForwardTraining on the Github.