In Robotics, we use PID Control in all kinds of situations where we need to get some moving part to a certain position fast and accurate. PID control is a closed-loop control. It means it employs some sort of sensor to give it feedback on the current position so it can compute the force it needs to apply to the moving part to get it to the target position. Ideally, the farther away from the target position, the larger the force is applied so that we will move the part as fast as we could initially and will slow down when we approach to the target position.

PID Control stands for Proportional, Integral and Derivative. It means the control has three separate components. The difference between the target position and the current position is called error. The following equations is the core of PID control.

error = target - current
output = Kp*error + Ki*(integral of error over time) + Kd*(derivative of error over time)

The three constants (Kp, Ki and Kd) determine how important each term is contributing to the output.

Conceptually, Proportional control states that the force (output) applied to the moving part shall be proportional to the error. The larger the error, the bigger the output. The Proportional term by itself is good enough for a majority of situations. However, if the situation requires more accuracy, we may need to use the Integral and the Derivative terms (non-zero Ki and Kd). With Proportional term alone (Ki and Kd are set to zero), it is possible that as the object approaches the target, the error will be diminishing and therefore reduces the output so small such that it is no longer strong enough to reach the target. This remaining error that doesn't go away is called Steady State Error. To minimize Steady State Error, we introduce the Integral term. The Integral term simply means that as time goes on, if the error is non-zero, the magnitude of the Integral term will grow bigger (integrated over time). So if the object slows down to a point where it cannot reach target and if you wait long enough, time will grow this term and give it strength to complete the journey. However when the object starts moving again because of the Integral term, as long as there is still an error, the Integral term will grow even bigger. Therefore, we will get to a situation where the object will accelerate pass the target, then the error becomes negative and it will start to bring down the Integral term (i.e. slowing the object down) which means it is still going pass the target more but just slower. Eventually, the negative error will caused the Integral term to go to zero and the output will go negative meaning the object will go in reverse. The end result is that by introducing the Integral term, it will likely make the object oscillating around the target position. Hopefully, the oscillation will die down and the object will rest at the target position. To counteract the oscillation, we then introduce the Derivative term.

[Place holder for a more formal paper]

There has been a lot of discussions on the C++ forum on how to do PID control on speed. The good news is, after some experimentation, I think I found an algorithm that will give us stable PID controlled speed. The built-in PID control for speed on Jaguar doesn't work. It caused violent oscillation or if you tune the PID carefully, you will get half the target speed at the most. The people on the forum confirmed it. So we are using the PID control in our own library with a minor modification. I tried it on the NanoBot and ran up to 400 rpm which is almost the top speed of the NanoBot (NanoBot top speed is about 420 rpm with no load) and it was very stable. So one problem down and few more to go....

Programmers, we will discuss the details of this algorithm on our next meeting. In the mean time, please give this problem some thoughts. Here is the problem: PID control is based on the theory that if we set a target (e.g. 10 ft from current position), we should drive as fast as possible towards the target until we are close to it, then we slow down. Therefore, the power we sent to the motor should be proportional to the error (target position - current position). So the bigger the error (farther away from the target), the bigger the power. But as we are closing onto the target, error becomes smaller and so is the power of the motor. So ideally, we slow down and will hit the target right on and stop. PID control does very well on position control. But for speed control, let's say we set our speed target to 60 rpm. Initially, we are at 0 rpm. So the error is 60 - 0 = 60. So we will spin the motor full speed. But once the motor start spinning, the speed is increasing. Let's say it is now 20 rpm, so target - current = 60 - 20 = 40. With error 40, the motor power has decreased (compare to the previous error 60), so the motor is slowing down already. So there is an equilibrium point where (speed < 60) that will produce an error large enough to sustain the speed but it will never reach 60. Empirically, this euilibrium speed is at the most half of the target speed. If it had reached 60 rpm, the error became (60 - 60 = 0) which meant the motor power would become zero. The motor would stop. But then the error would be 60 again and caused the motor to start up again. This is called oscillation, the speed will go from 0 to over 60 then back to 0 and back and forth very violently. This is because PID control is designed to do position control where if we reached target, we stop. But for speed, when we reached target, we need to maintain power to keep it there. Based on this information, please think of an algorithm that will achieve constant speed control.

Jim,

Thanks for the paper. Regarding using the I and D terms of the PID controller for speed control, the people on the forum have discussed it. http://chiefdelphi.com/forums/showthread.php?t=100135

The conclusion was that the built-in PID control of the Jaguar has an Integral unwinding mechanism that prevents a successful tune of PID for speed control. I have also experimented it myself and failed to come up with a stable controller. In general, tuning PID, especially speed control PID, is very touchy with 3 variables involved. I've spent quite a bit of time to tune I and D but none worked. They all resulted in violent oscillation. It is true that a graph would help. That's why one of the punchlist items I have is to implement a logging facility that will allow us to log the speed data and plot them on Excel. Regardless, adding a simple "bias" to the PID controller is something very simple to do and resulted in an easy to tune and stable speed controller. That's why I prefer doing it that way.

If you look at it from mathematical point of view, speed is a derivative of position. That's why people were suggesting to treat I as P and D as I. So essentially, we integrated the PID controller to produce a "bias". And that's what I was doing in my algorithm and it worked.

PIDControl (last edited 2012-01-27 03:36:56 by MikeTsang)