Chapter 6 of 11
55%
What is PID Control?
PID stands for Proportional, Integral, and Derivative, each of which is a component of the control algorithm part of the method used in robotics for precise control of motor output. PID control is a control loop feedback mechanism commonly used in industrial control systems. A PID controller continuously calculates an error value as the difference between a desired setpoint and a measured process variable and applies a correction based on proportional, integral, and derivative terms.
Proportional Term (P)
The proportional term produces an output value that is proportional to the current error value. The proportional response can be adjusted by multiplying the error by a constant KP, called the proportional gain.
output = kP * error;Integral Term (I)
The integral term is concerned with the accumulation of past errors. If the error has been present for a long time, the integral term will increase the output to eliminate the error. This can help to reduce steady-state error.
integral += error;
output += kI * integral;Derivative Term (D)
The derivative term is a prediction of future error, based on its rate of change. It provides a dampening effect, reducing the likelihood of overshoot and oscillations.
derivative = error - previousError;
output += kD * derivative;Combining P, I, and D
The final PID control output is the sum of the proportional, integral, and derivative terms:
double PID(double target, double measured_value, double& integral, double previous_error, double kP, double kI, double kD) {
double error = target - measured_value;
integral += error * deltaTime; // integral will be a global variable
double derivative = error - previous_error;
double output = kP * error + kI * integral + kD * derivative;
previous_error = error;
return output;
}Implementing PID in Robotics
To implement PID control in a robot, you need to continuously calculate the control output and adjust the motor speeds accordingly. In VEX Robotics, we've found that the integral term doesn't provide much value to the overall system. The P and D terms are almost always enough to make your robots movements very accurate.
Which term of the PID controller is responsible for predicting future error based on its rate of change?
Tuning PID
To tune your kP and kD values, the following website has a very good flowchart on it: PID Tuning (Lemlib)
Implement a PD (no integral) loop for the robot to drive straight x amount of inches, if the error is smaller than 1 inch, your robot can stop. Tune the kP and kD values for your robot.
Implement a PD (no integral) loop for the robot to turn and FACE x degrees, if the error is smaller than 3 degrees, your robot can stop. Tune the kP and kD values for your robot. BONUS: Make your robot travel the shortest distance to the desired angle.