Shown here is the basic closed-loop (a complete cycle) control diagram:
The point of a control system is to get your robot actuators (or anything really) to do what you want without . . . ummmm . . . going out of control. The sensor (usually an encoder on the actuator) will determine what is changing, the program you write defines what the final result should be, and the actuator actually makes the change. Another sensor could sense the environment, giving the robot a higher-level sense of where to go.
error - The error is the amount at which your device isnt doing something right. For example, if your robot is going 3mph but you want it to go 2mph, the error is 3mph-2mph = 1mph. Or suppose your robot is located at x=5 but you want it at x=7, then the error is 2. A control system cannot do anything if there is no error - think about it, if your robot is doing what you want, it wouldnt need control!
proportional (P) - The proportional term is typically the error. This is usually the distance you want the robot to travel, or perhaps a temperature you want something to be at. The robot is at position A, but wants to be at B, so the P term is A - B.
derivative (D) - The derivative term is the change in error made over a set time period (t). For example, the error was C before and now its D, and t time has passed, then the derivative term is (C-D)/t. Use the timer on your microcontroller to determine the time passed (see timer tutorial).
integral (I) - The integral term is the accumulative error made over a set period of time (t). For example, your robot continually is on average off by a certain amount all the time, the I term will catch it. Lets say at t1 the error was A, at t2 it was B, and at t3 it was C. The integral term would be A/t1 + B/t2 + C/t3.
tweak constant (gain) - Each term (P, I, D) will need to be tweaked in your code. There are many things about a robot that is very difficult to model mathematically (ground friction, motor inductance, center of mass, ducktape holding your robot together, etc.). So often times it is better to just build the robot, implement a control equation, then tweak the equation until it works properly. A tweak constant is just a guessed number that you multiple each term with. For example, Kd is the derivative constant. Idealy you want the tweak constant high enough that your settling time is minimal but low enough so that there is no overshoot.
P*Kp + I*Ki + D*Kd
What you see in this image is typically what will happen with your PID robot. It will start with some error and the actuator output will change until the error goes away (near the final value). The time it takes for this to happen is called the settling time. Shorter settling times are almost always better. Often times you might not design the system properly and the system will change so fast that it overshoots (bad!), causing some oscillation until the system settles. And there will usually be some error band. The error band is dependent on how fine a control your design is capable of - you will have to program your robot to ignore error within the error band or it will probably oscillate. There will always be an error band, no matter how advanced the system.
ignoring acceptable error band example:
The Complete PID Equation
Actuator_Output = Kp*P + Ki*I + Kd*D
or in easy to understand terms:
Better yet, rarely will you need the integral term. Thats right, just delete and ignore it! The only time you will need this term is when acceleration plays a big factor with your robot. If your robot is really heavy, or gravity is not on it's side (such as steep hills), then you will need the integral term. But out of all the robots I have ever programmed, only two needed an integral term - and both robots were over 30 lbs with a requirement for extremely high precision (millimeter or less error band). Control without the integral term is commonly referred to as simply PD control.
There are also times when you do not require a derivative term, but usually only when the device mechanical stabalizes itself, works at very low speeds so that overshoot just doesnt happen, or you simply dont require good precision.
Sampling Rate Issues
The rule of thumb is that the sample time should be between 1/10th and 1/100th of the desired system settling time. For a typical homemade robot you want a sampling rate of about 20+/second (very reasonable with today's microcontrollers).
Has this site helped you with your robot? Give us credit -
link back, and help others in the forums!
Society of Robots copyright 2005-2014