🎸Tuning PIDs
Perseverance makes perfect
Last updated
Was this helpful?
Perseverance makes perfect
Last updated
Was this helpful?
At this point, you should have coded the PIDs fully. Now, you have to tune those three constants to make the PID work well on your specific robot. Here's a quick recap of each constant:
Proportional (kP): if the robot is far from the target, set the motor power high so the robot gets there faster. If the robot is close, set the motor power low so the robot doesn't overshoot.
Integral (kI): if the robot is close to the target, but not quite there, increase the motor power over time so the robot doesn't stall.
Derivative (kD): if the robot is rapidly approaching the target, apply the brakes so the robot doesn't go too far.
Remember, everything on the robot--drivetrain friction, gear ratio, weight distribution, center of gravity--influence the optimal PID values for the robot. That is, you might have to re-adjust the PID values if something major changes on the robot.
Let's say we're tuning the drive PID (the process is the same for the turn PID). We started with these values. Try out the drive PID. How well does it work?
If the robot barely moves, try increasing kP--this increases the motor power applied. If the robot jerks forward and goes too far, try decreasing kP.
Your goal should be the green line in the graph below, where the robot reached the setpoint (target) quickly and stays there. The graphs represent's the robot's current distance, compared to the target; this applies to both turn PIDs and drive PIDs.
If your robot acts like the orange line on the graph above, where the robot goes past the target and reverses direction, consider adding in the kD term. As a starting point, set this term to 5 times the value of the kP term. Adding in the integral term (start at about 1/10th the value of kP) may also help.
If your robot acts like the blue line on the graph above, where the robot takes a while to reach the target, increase kP or decrease kD.
These rest of PID tuning comes down to trial and error; it's your job to find the set of values that works best for your specific robot.
If you want a more mathematical approach to estimating kP, kI, and kD from the start, take a look at this page:
🔢Ziegler-Nichols Method