So what is a linear control system, and why do I want one on my robot?
Thats a great question, I'm so grad I asked myself ;). When you build your first robot ($50 robot etc.) your code is usually boolean based. What I mean by that is, a behavior is executed on the basis on true or false. In the case of the $50 robot there are two photoresistors. If the right one sees little or no light the robot turns left, and the opposite for the left sensor. This behavior is boolean because the robot either turns or it doesn't based off a simple logic equation of if and else statements. In the case of a linear control system the behavior is a function of the sensor values. This means that the robot's turning rate would vary by light intensity on the sensors (we are still talking $50 robot example). Linear controls are desireable because they improve the robustness of your control, and the robot looks more professional, because it no longer jitters through behaviors.
The simplest control system (as far as I know) consists of an input a plant and an output. The input is the control signal, which is converted to an output signal via the plant.
You have a DC motor being made into a servo. Your input is a potentiometer. depending on which way you turn the pot, and by how much, the motor will change directions and rpm respectively.
y = output (duty cycle)
m = plant
x = input (rpm)
mx = y
in graphical form
Now lets take he next step. Lets add feedback to the system. The control system from example0 is what we call open loop. This means that the controller cannot tell if the output is acctually what it should be. In a real world system there will always be what is called disturbances. These disturbances can influence the output of the system and cause it to get out of whack. Feedback allows the system to correct itself dynamically, so that disturbances can be compensated for.
lets have the same goal as example1, but this time lets add feedback.
y = output (duty cycle)
m = plant (rpm to duty cycle)
n = conversion(encoder to rpm)
x = input (rpm)
y = (x*m)/(1 + n*m)
In this sytem you can implement position control. The input is the desired position, and the feedback is the actual position. The output is motor speed. The X on the left portion of the diagram is a summing block. At this point the actual position is subracted from the desired position. The resulting value is pumped through the plant to generate an apropriat PWM value.
What is PID?
PID is a specific type of linear control system. P, PI, and PD controllers also exist. PID just utilizes all three control elements. These elements are Proportional, Integral, and derivative. Each element serves a different purpose.
Proportional = The instantaneous error of the system.
Integral = The sum of the instantaneous erros of the system
Derivative = The rate of chnge of the error
There are aslo 3 gains in a PID control system, Kp, KI, and KD. These gaines are multipled by their respective errors.
psuedo code for PID
read feedback (actual)
Perror = input - actual; //input is specified by algorith or hard coded
Ierror += Perror;
Derror = Perror - prev_Perror;
prev_Perror = Perror;
PWM_value = Perror*kp + Ierror*ki + Derror*kd;
if(PWM_value < -100) move motor backward full;
else if (PWM_value > 100) move motor foward full;
else if (PWM_value < 0) move motor backward at abs(PWM_value) duty cycle.
else move motor forward at (PWM_value) duty cycle.
I have a PID controller. Now how do I make it work?
Those coefficients Kp, Ki, and Kd are used for tuning the system.
Role of Propotional gain kp-
The propotional term is mainly resposible for how responsive a system is. The higher kp the faster the system will try to correct itself. The issue is if you increase kp too much then the system will overshoot, and possibly oscillate out of control.
Role of Integral gain ki-
The integral term both increases reposiveness, and eliminates steady state error. Rule of thumb says to keep ki low because the integral term is very oscillatory. Its quite easy to create a system that will blow up very quickly and violently.
Role of the Derivative gain kd-
The derivative term essentially dampens the system. This prevents too much jery ro jittery movements. The derivative term can therfore be used to decrease overshoot, and eliminate any small oscillation at steady state.