320 likes | 553 Views
CENG4480_A4 DC motor Control. Using PID (proportional-integral-derivative) control. P ID (proportional-integral-derivative) control. A more formal and precise method Used in most modern machines. Introduction. Control for better performance Use PID, choose whatever response you want.
E N D
CENG4480_A4DC motor Control Using PID (proportional-integral-derivative) control PID a1
PID (proportional-integral-derivative) control A more formal and precise method Used in most modern machines PID a1
Introduction • Control for better performance • Use PID, choose whatever response you want Too much overshoot/undershoot, not stable Motor speed (w) Good performance Criteria depends on users and applications required Response too slow time PID a1
values to evaluate a control system Steady state error overshoot Target value Typically value=10% Depends on application undershoot time 0 Settling time Rise time PID a1
control method:PID (proportional-integral-derivative) control Required speed= Wsl_speed_input (u) Motor I=integral control delta_speed dt IR wheel Speed encoder e=error term =delta_speed Amplifier K1 and Alter PWM for driver L293 P=proportional and integral control delta_speed dt ; + - sum speed (w) wsl_t_on D=derivative control d(delta_speed)/dt ; Wsl_speed_measured PID a1
control method: Theory of a feedback control system Required speed= Wsl_speed_input (u) Motor IR wheel Speed encoder e=error term B Plant: use control parameters to derive the system sum A Controller: Collect error to drive the plant + - speed (w) speed (w) PID a1
P (proportional) control of speed Required speed= Wsl_speed_input (u) Motor Set Kp=A IR wheel Speed encoder e=error term sum Kpe + - speed (w) speed (w) PID a1
PD (proportional-derivative) control of speedalternative names Pre-act or rate control Required speed= Wsl_speed_input (u) Motor A IR wheel Speed encoder e=error term sum Kpe + - speed (w) Kd*[d(e)/dt] speed (w) PID a1
PID (proportional-derivative-integral) control of speed Required speed= Wsl_speed_input (u) Motor Ki*[ (e)dt] A IR wheel Speed encoder e=error term sum Kpe + - speed (w) Kd*[d(e)/dt] speed (w) PID a1
values to evaluate a control system Steady state error overshoot Target value Typically value=10% Depends on application undershoot time 0 Settling time Rise time PID a1
Use of PIDcontrol terms are intertwinedhttp://en.wikipedia.org/wiki/PID_controller • Kp: Proportional Gain - Larger Kp typically means faster response since the larger the error, the larger the Proportional term compensation. An excessively large proportional gain will lead to process instability and oscillation. • Ki: Integral Gain - Larger Ki implies steady state errors are eliminated quicker. The trade-off is larger overshoot: any negative error integrated during transient response must be integrated away by positive error before we reach steady state. • Kd: Derivative Gain - Larger Kd decreases overshoot, but slows down transient response and may lead to instability due to signal noise amplification in the differentiation of the error. PID a1
Reason for proportional controlhttp://www.jashaw.com/pid.html • Bigger error will give more input to the plant to enable the output to reach the target faster • Improve risetime PID a1
Reason for Derivative controlor called Pre-act or rate controlhttp://www.jashaw.com/pid.html • Adjust output based on the rate of change the error • Decrease overshoot (caused by the integral term and proportional term) • But also amplifier noise, may make system unstable. • See http://www.controlguru.com/wp/p76.html PID a1
Example to show how derivative control reduces overshoothttp://www.controlguru.com/wp/p76.html • u=setpoint, • wt, motor speed measured • et=u-wt,-----(1) • If u is stable , w rises from 0 to u • Differentiate (1) we get • d(et)/dt = -d(wt)/dt ---(2) • When w is increasing, the system suppresses its growth, hence reduces overshoot speed Setpoint u w time PID a1
Example to show how derivative control reduces oscillation rock u wt-1 wt wt+1 • Stable requirement u, changing motor speed w • The robot is moving at a constant speed wu • A small rock hiders its motion, so reduces the motor speed wt, u=setpoint, • et=u-wt,-----(1), • d(et)/dt = -d(wt)/dt ---(2) • From (1) when wt decreases, e increases, so the system increases power to the motor to enable wt+1 approach u. • The reverse is also true, e.g. the robot suddenly goes downhill (or just overcome the small rock) and speed increases, the system should decease the power to the motors. • Changing requirement u, stable motor speed w • It is also true for a stable w and increasing u, since de/dt=du/dt, so power is increased to keep up with the required u. PID a1
Reason for Integral controlor called automatic resethttp://www.jashaw.com/pid.html • In proportional only control the output cannot reach the target value (setpoint) without using a bias. • Output=gain*error + bias, E.g. • w=kp*(u-w) + bias, do the following exercise • without bias u=10, Kp=100, bias=0,so w=>9.99009 • With bias u=10, Kp=100, w=10, so B=>10 • Without a computer the bias is set manually • With the computer, the bias can be calculated by the integral term • Decrease steady state error • It helps the system quickly reaches the set point • But it increases overshoot because of the cumulated term • Integral Windup problem (http://www.controlguru.com/2008/021008.html) • If error is positive/negative for too long accumulated error will saturate the system or is over the limit that the system can response to (can damage the motor, ie. when the motor is driven by an analog voltage) • Solution: Set maximum and minimum values for the integral term PID a1
Matlab code Kp=350; Ki=300; Kd=50; num=[Kd Kp Ki]; den=[1 10+Kd 20+Kp Ki]; t=0:0.01:2; step(num,den,t) Example: Step response to evaluate a system-- ask the motor to change from 0 to unit speedhttp://www.engin.umich.edu/group/ctm/PID/PID.html speed Good smooth PID control result time Matlab code to valuate the system PID a1
Kp=350; Ki=300; Kd=50; Effects (in matlab) Reduce Kp Kp=100; Ki=300; Kd=50; Kp=350; increase Ki Ki=3000; Kd=50; Too slow Settling time too long Best, near to ideal Kp=350; Ki=300; Reduce Kd Kd=10; Bad , too much overshoot high much overshoot PID a1
General tips for designing a PID controllerhttp://www.engin.umich.edu/group/ctm/PID/PID.html • When you are designing a PID controller for a given system, follow the steps shown below to obtain a desired response. • Obtain an open-loop response and determine what needs to be improved. (Step input, see output) • Add a proportional control (Kp) to improve the rise time • Add a derivative control (Kd) to improve the overshoot • Add an integral control (Ki) to eliminate the steady-state error • Adjust each of Kp, Ki, and Kd until you obtain a desired overall response. See the table in the next slide. PID a1
Effects of increasing parametershttp://en.wikipedia.org/wiki/PID_controller PID a1
PID Implementation PID a1
ISR for PID controlhttp://www.hitex.co.uk/c166/pidex.html • Main() • {derivative_gain, proportional_gain, integral_gain should be set in the main program} • Interrupt service routine ISR() // set a cycle freq , e.g. 1KHz • { • 0) measure error • 1) Calculate Proportional Term • 2) Calculate derivative term • 3) Calculate Integral Term • 4) Sum Up {Proportional+ derivative+ Integral } and use it to control the output • } PID a1
Checking overflow • Checking overflow of terms is essential to make the system reliable PID a1
1) Calculate Proportional Term (Kp=proportional_gain) http://www.hitex.co.uk/c166/pidex.html • To make sure the error term does not overflow • /*** Calculate Proportional Term ***/ • proportional_term_temp = ((long)this_error * (long)proportional_gain) ; • /*** Check For Proportional Term Out Of Range & Apply Saturation ***/if(proportional_term_temp > (long)((long)32767 * Inputs_Scale_Factor)) { proportional_term = 32767 ; } else { if(proportional_term_temp <= (long)((long)-32768 * Inputs_Scale_Factor)) { proportional_term = -32768 ; } else { proportional_term = (short)((long)proportional_term_temp/Inputs_Scale_Factor) ; } } PID a1
2) Calculate derivative term (Kd=derivative_gain) • //The derivative term is simply calculated /*** Calculate Derivative Term ***/derivative_term = ((long)(this_error - PID.last_error) * derivative_gain)/(long)Inputs_Scale_Factor ; Required speed= Wsl_speed_input (u) Motor A IR wheel Speed encoder e=error tem sum Kp + - Kd*d(e)/dt Motor speed (w) PID a1
3) Calculate Integral Term (Ki=integral_gain) • /*** Find Accumulated Error ***/ acc_error_temp = ((long)PID.accumulated_error) + (long)this_error ; /*** Check For Accumulated Error Out Of Range ***/ if(acc_error_temp > (long)32767) { // Is error > maximum value? acc_error_temp = 32767 ; // Limit to max +ve value } if(acc_error_temp < (long)-32768) { // Is error < minimum value? acc_error_temp = -32768 ; // Limit to max -ve value }PID.accumulated_error = (short) acc_error_temp ; PID a1
Calculate Integral Term -- calculate and check for overflow • /*** Calculate Integral Term ***/ integral_term_temp = ((long)PID.accumulated_error * (long)integral_gain) ; /*** Check For Integral Term Out Of Range & Apply Saturation ***/ if(integral_term_temp > (long)((long)32767 * Inputs_Scale_Factor)) { integral_term = 32767 ; } else { if(integral_term_temp <= (long)((long)-32768 * Inputs_Scale_Factor)) { integral_term = -32768 ; } else { integral_term = integral_term_temp/Inputs_Scale_Factor ; } } • Integral Windup problem • If error is positive/negative for too long accumulated error will saturate the system • Solution: Set maximum and minimum values for the integral term PID a1
4) Sum Up Control Terms • /*** Sum Up Control Terms ***/ • control_output_temp = (long) integral_term ; • control_output_temp += (long)derivative_term ; • control_output_temp += (long) proportional_term ; • /* Limit Value Of Control Term */ • if(control_output_temp > 32767) • { control_output_temp = 32767 ; } • else • { if(control_output_temp < 0) • { control_output_temp = 0 ; • } • } PID a1
PID Tuning Accepted performance Motor speed V1 (V1)/2 • Tune (adjust manually) • proportional_gain (Kp), • integral_gain (Ki) • derivative_gain (Kd), • Set constant speed V1 for a while (5 seconds) and stop at T1 • Record the speed by the computer after T1 and see if it is ok • Yes (accept Kp,Ki,Kd) • No (tune again) unstable done PID a1
Summary • Studies PID control theory and implementation PID a1