Presentation is loading. Please wait.

Presentation is loading. Please wait.

PID a11 CENG4480_A4 DC motor Control Using PID (proportional-integral-derivative) control.

Similar presentations


Presentation on theme: "PID a11 CENG4480_A4 DC motor Control Using PID (proportional-integral-derivative) control."— Presentation transcript:

1 PID a11 CENG4480_A4 DC motor Control Using PID (proportional-integral-derivative) control

2 PID a12 PID (proportional-integral-derivative) control A more formal and precise method Used in most modern machines

3 PID a13 Introduction Control for better performance Use PID, choose whatever response you want Good performance Criteria depends on users and applications Too much overshoot/undershoot, not stable Response too slow time Motor speed (w) required

4 PID a14 values to evaluate a control system Typically value=10% Depends on application Rise time Settling time0 time Target value overshoot Steady state error undershoot

5 PID a15 control method: PID (proportional-integral-derivative) control Required speed= Wsl_speed_input (u) IR wheel Speed encoder Wsl_speed_measured + - speed (w) Motor Amplifier K1 and Alter PWM for driver L293 wsl_t_on I=integral control delta_speed dt P=proportional and integral control delta_speed dt ; D=derivative control d(delta_speed)/dt ; sum e=error term =delta_speed

6 PID a16 control method: Theory of a feedback control system Required speed= Wsl_speed_input (u) IR wheel Speed encoder + - speed (w) Motor sum A Controller: Collect error to drive the plant e=error term speed (w) B Plant: use control parameters to derive the system

7 PID a17 P (proportional) control of speed Required speed= Wsl_speed_input (u) IR wheel Speed encoder + - speed (w) Motor KpeKpe sum speed (w) Set K p =A e=error term

8 PID a18 PD (proportional-derivative) control of speed alternative names Pre-act or rate control Required speed= Wsl_speed_input (u) IR wheel Speed encoder + - speed (w) Motor KpeKpe sum K d *[d(e)/dt] A speed (w) e=error term

9 PID a19 PID (proportional-derivative-integral) control of speed Required speed= Wsl_speed_input (u) IR wheel Speed encoder + - speed (w) Motor KpeKpe sum A K i *[ (e)dt] K d *[d(e)/dt] speed (w) e=error term

10 PID a110 values to evaluate a control system Typically value=10% Depends on application Rise time Settling time0 time Target value overshoot Steady state error undershoot

11 PID a111 Use of PID control terms are intertwined http://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.

12 PID a112 Reason for proportional control http://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

13 PID a113 Reason for Derivative control or called Pre-act or rate control http://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

14 PID a114 Example to show how derivative control reduces overshoot http://www.controlguru.com/wp/p76.html u=setpoint, w t, motor speed measured e t =u-w t, -----(1) If u is stable, w rises from 0 to u Differentiate (1) we get d(e t )/dt = -d(w t )/dt ---(2) When w is increasing, the system suppresses its growth, hence reduces overshoot Setpoint u time w speed

15 PID a115 Example to show how derivative control reduces oscillation Stable requirement u, changing motor speed w –The robot is moving at a constant speed w  u –A small rock hiders its motion, so reduces the motor speed w t, u=setpoint, –e t =u-w t, -----(1), –d(e t )/dt = -d(w t )/dt ---(2) –From (1) when w t decreases, e increases, so the system increases power to the motor to enable w t+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. w t-1 w t w t+1 u rock

16 PID a116 Reason for Integral control or called automatic reset http://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=k p *(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

17 PID a117 Example: Step response to evaluate a system-- ask the motor to change from 0 to unit speed http://www.engin.umich.edu/group/ctm/PID/PID.html 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) Matlab code to valuate the system time speed Good smooth PID control result

18 PID a118 Effects (in matlab) Reduce Kp Kp=100; Ki=300; Kd=50; Kp=350; increase Ki Ki=3000; Kd=50; Kp=350; Ki=300; Kd=50; Kp=350; Ki=300; Reduce Kd Kd=10; Bad, too much overshoot Too slow Settling time too long high much overshoot Best, near to ideal

19 PID a119 General tips for designing a PID controller http://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.

20 PID a120 Effects of increasing parameters http://en.wikipedia.org/wiki/PID_controller ParameterRise TimeOvershootSettling Time Steady state error KpDecrease step1 IncreaseSmall Change Decrease KiDecreaseIncrease Eliminate step3 KdSmall Change Decrease step2 DecreaseSmall Change

21 PID a121 PID Implementation

22 PID a122 ISR for PID control http://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 }

23 PID a123 Checking overflow Checking overflow of terms is essential to make the system reliable

24 PID a124 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) ; } }

25 PID a125 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 ; Motor Required speed= Wsl_speed_input (u) IR wheel Speed encoder + - speed (w) Motor KpKp sum K d *d(e)/dt A e=error tem

26 PID a126 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 ;

27 PID a127 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

28 PID a128 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 ; }

29 PID a129 PID Tuning 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) Motor speed V1 (V1)/2 Accepted performance unstable done

30 PID a130 Summary Studies PID control theory and implementation


Download ppt "PID a11 CENG4480_A4 DC motor Control Using PID (proportional-integral-derivative) control."

Similar presentations


Ads by Google