Tuning a PID Loop

For kP, start using increments of 10 to figure out when the robot starts moving:
0.0001
0.001
0.01
0.1

Stop immediately when the robot starts inching or moving. If it moves very rapidly then go back a decimal place and start incrementing by the designated place (for example if the robot starts moving at 0.01):

0.01
0.02
0.03

Woah! The robot became a lot more agressive at 0.3 and continues oscillating to a very agressive degree. Let’s lower it back down:

0.02

Next we shift over and increment the precision down by one

0.021
0.022
0.023
0.024

The robot may be a bit too agressive at 0.024 so let’s decrease it by one and shift down again

0.023
0.0231
0.0232

The robot seems to iscolate around 5 times at that amount before settling but it was 3 previously so let’s go back down one:

0.0231

Now we have our kP!

Repeat process for kD, except kD is a dampener. I find that kD is traditionally much higher than kP, sometimes 3-5x the amount of kP for a drivetrain. Keep that in mind and it’s better to stop the oscillation over precision in this instance, as the next step increases the precision

for kI, I would suggest introducing another variable “kI_activation_error” or something to that nature such that abs(error) < kI_activation_error you allow accumulation of totalError, otherwise set totalError to 0.

Set kI_activation_error to a reasonable amount. If the error is in inches for the drivetrain, perhaps a good number is around 3-4 inches. For turning I would suggest around the ballpark of 25-30 degrees.

for kI, you will increase it the same way similar to kP but the goal now is to have kI “snap” the robot to the center without oscillating. You will increase kI until the robot snaps to the position without oscillating. If it does oscillate, go down one.