-
Notifications
You must be signed in to change notification settings - Fork 1
PID Controller Calibration
The following information is from PID Controller For Lego Mindstorms Robots.
Parameter | Rise time | Overshoot | Settling time | Error at equilibrium |
---|---|---|---|---|
Kp | Decrease | Increase | Small change | Decrease |
Ki | Decrease | Increase | Increase | Eliminate |
Kd | Indefinite (small decrease or increase) |
Decrease | Decrease | None |
To tune your PID controller you follow these steps:
-
Set the Ki and Kd values to zero, which turns those terms off and makes the controller act like a simple P controller.
-
Set the Tp term to a smallish one.
-
Set the Kp term to a "reasonable" value. What is "reasonable"?
- I just take the maximum value we want to send to the motor's power control and divide by the maximum usable error value.
- Or, just set Kp to 1 and see what happens.
-
Run the robot and watch what it does. If it can't follow the line and wanders off then increase Kp. If it oscillates wildly then decrease Kp. Keep changing the Kp value until you find one that follows the line and gives noticeable oscillation but not really wild ones. We will call this Kp value "Kc" ("critical gain" in the PID literature).
-
Using the Kc value as Kp, run the robot along the line and try to determine how fast it is oscillating. This can be tricky but fortunately the measurement doesn't have to be all that accurate. The oscillation period (Pc) is how long it takes the robot to swing from one side of the line to the other then back to the side where it started.
-
You also need to know how fast the robot cycles through it's control loop. I just set the loop to a fixed number of steps (like 10,000) and time how long the robot takes to finish (or have the robot do the timing and display the result.) The time per loop (dT) is the measured time divided by the number of loops.
-
Use the table below to calculate a set of Kp, Ki, and Kc values. If you just want a P controller then use the line in the table marked P to calculate the "correct" Kp (Ki' and Kd' are both zero). If you want a PI controller then use the next line. The full PID controller is the bottom line.
-
Run the robot and see how it behaves.
-
Tweak the Kp, Ki and Kd values to get the best performance you can. You can start with fairly big tweaks, say 30% then try smaller tweaks to get the optimal (or at least acceptable) performance.
-
Once you have a good set of K's try to boost the Tp value, which controls the robot's straight speed.
-
Re-tweak the K's or perhaps even go back to step 1 and repeat the entire process for the new Tp value.
-
Keep repeating until the robot's behavior is acceptable.
(loop times considered to be constant and equal to dT)
Control Type | Kp | Ki' | Kd' |
---|---|---|---|
P | 0.50Kc | 0 | 0 |
PI | 0.45Kc | 1.2KpdT/ Pc | 0 |
PD | 0.80Kc | 0 | KpPc /(8dT) |
PID | 0.60Kc | 2KpdT / Pc | KpPc / (8dT) |