Você está na página 1de 9

Basics of PID Control

how to make the robot start and stop where you want it to
PID is an acronym for
P - proportional
I - Integral
D- Differential
Some gures from PID without a PHD , Tim Wescott
http://www.embedded.com/2000/0010/0010feat3.htm

Closed loop control system



Noise/latency

actuator

Response Characteristic

Controller

Physical System

Inertia/latency

sensor

Noise/latency

DC motor/sensor system example



Physical System
Motor Step input response

Except for brief inertial time constant


response can be consider linear,
i.e. delta(in) || delta(out) full range

System Variables

Set Point : the desired sensor value

Error: The difference between the sensor output and the set point
ERROR = (sensed_value - set_point) * gain
Gain term is optional and can be used to increase/decrease t
the sensitivity of the system

Control Value: The actuation (stimulus) value applied to the physical system
Control_Value = PID_CONTROL_FUNCTION(ERROR, Kp, Ki, Kd)
ERROR from above
Kp,Ki,Kd - tuning constants that balance the contribitions from three cooperating
control algorithms -- proportional, differential, integral

PID control components



Proportional

PID_proportonal = Kp * ERROR

Integral

PID_integral = Ki * integral(error) dt


= Ki * ( summation of error from tn-i to tn)
Differential

PID_differential = Kd * (dERROR/dt)

Kd * (ERRORi - ERRORi-1)

PID_CONTOL_FUNCTION = PID_proportional + PID_integral + PID_differential


Effect of Kp

Kp == pGain

Small pGain - response too slow
Large pGain - too fast, overshoot, oscillation

Effect of Ki

Control system using only a Ki term.. Again Ki == iGain in the gure, even for very small Ki, the system is difcult to stabilize (why?)

Kp and Ki combined

The combined Ki and Kp terms tend to improve the slower Kp responses from before but does less to improve the stability of the faster Kp responses

PID controller code


typedef struct
{
double dState;
// Last position input
double iState;
// Integrator state
double iMax, iMin;
// Maximum and minimum allowable integrator stat

double
iGain,
// integral gain

pGain,
// proportional gain

dGain;
// derivative gain
} SPid;

double UpdatePID(SPid * pid, double error, double position)
{
double pTerm, dTerm, iTerm;

pTerm = pid->pGain * error; // calculate the proportional term

// calculate the integral state with appropriate limiting
pid->iState += error;
if (pid->iState > pid->iMax) pid->iState = pid->iMax;

else if (pid->iState < pid->iMin) pid->iState = pid->iMin;

iTerm = pid->iGain * iState; // calculate the integral term
dTerm = pid->dGain * (pid->dState - position);
pid->dState = position;
return pTerm + dTerm + iTerm;
}

Example code 

from tim wescott website

Você também pode gostar