+ All Categories
Home > Documents > PID a11 CENG4480_A4 DC motor Control Using PID (proportional-integral-derivative) control.

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

Date post: 15-Jan-2016
Category:
Upload: aron-brooks
View: 235 times
Download: 0 times
Share this document with a friend
Popular Tags:
30
PID a1 1 CENG4480_A4 DC motor Control Using PID (proportional-integral-derivative) control
Transcript
Page 1: PID a11 CENG4480_A4 DC motor Control Using PID (proportional-integral-derivative) control.

PID a1 1

CENG4480_A4DC motor Control

Using PID

(proportional-integral-derivative) control

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

PID a1 2

PID (proportional-integral-derivative) control

A more formal and precise method

Used in most modern machines

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

PID a1 3

Introduction• Control for better performance

• Use PID, choose whatever response you want

Good performanceCriteria depends on users and applications

Too much overshoot/undershoot, not stable

Response too slow

time

Motor speed (w)

required

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

PID a1 4

values to evaluate a control system

Typicallyvalue=10%Depends on application

Rise time Settling time0 time

Target value

overshoot

Steady state error

undershoot

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

PID a1 5

control method:PID (proportional-integral-derivative) control

Required speed=

Wsl_speed_input (u)

IR wheelSpeedencoder

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

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

PID a1 6

control method: Theory of a feedback control system

2 10 20p

p

K

s s K

Required speed=

Wsl_speed_input (u)

IR wheelSpeedencoder

+

-speed(w)

Motor

sumAController:Collect errorto drive the plant

( )

1

1

1

u w AB w

w wAB

u u

wAB AB

uw AB

u AB

e=error term

speed(w)

BPlant: use control parameters to derive the system

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

PID a1 7

( )

p

u w AB w

K e w

P (proportional) control of speed

2 10 20p

p

K

s s K

Required speed=

Wsl_speed_input (u)

IR wheelSpeedencoder

+

- speed(w)

Motor

Kpe sum

1B

speed(w)

Set Kp=A

e=error term

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

PID a1 8

PD (proportional-derivative) control of speedalternative names Pre-act or rate control

2 10 20p

p

K

s s K

Required speed=

Wsl_speed_input (u)

IR wheelSpeedencoder

+

- speed(w)

Motor

Kpe sum

Kd*[d(e)/dt]

1B

A

p d

deK e K w

dt

speed(w)

e=error term

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

PID a1 9

PID (proportional-derivative-integral) control of speed

2 10 20p

p

K

s s K

Required speed=

Wsl_speed_input (u)

IR wheelSpeedencoder

+

- speed(w)

Motor

Kpe sum

1B

AKi*[ (e)dt]

Kd*[d(e)/dt]

( )p d i

deK e K K e dt w

dt

speed(w)

e=error term

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

PID a1 10

values to evaluate a control system

Typicallyvalue=10%Depends on application

Rise time Settling time0 time

Target value

overshoot

Steady state error

undershoot

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

PID a1 11

Use of PIDcontrol 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.

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

PID a1 12

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

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

PID a1 13

Reason for Derivative controlor 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

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

PID a1 14

Example to show how derivative control reduces overshoot

http://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

p d

p d

deK e K w

dtdw

K e K wdt

Setpointu

time

w

speed

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

PID a1 15

Example to show how derivative control reduces oscillation

• 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.

p d

deK e K w

dt

wt-1 wt wt+1

u

rock

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

PID a1 16

Reason for Integral controlor 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=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

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

PID a1 17

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

• 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 systemtime

speed

Good smooth PIDcontrol result

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

PID a1 18

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 KdKd=10;Bad ,

too much overshoot

Too slowSettling time too long

high much overshoot

Best, near to ideal

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

PID a1 19

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.

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

PID a1 20

Effects of increasing parametershttp://en.wikipedia.org/wiki/PID_controller

Parameter Rise Time Overshoot Settling Time

Steady state error

Kp Decrease

step1

Increase Small Change

Decrease

Ki Decrease Increase Increase Eliminate

step3

Kd Small Change

Decrease

step2

Decrease Small Change

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

PID a1 21

PID

Implementation

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

PID a1 22

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• }

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

PID a1 23

Checking overflow

• Checking overflow of terms is essential to make the system reliable

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

PID a1 24

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) ; }

}

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

PID a1 25

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 ;

Motor2 10 20

p

p

K

s s K

Required speed=

Wsl_speed_input (u)

IR wheelSpeedencoder

+

- speed(w)

Motor

Kp sum

Kd*d(e)/dt 1B

A

e=error tem

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

PID a1 26

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 ;

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

PID a1 27

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 problemIf error is positive/negative for too long accumulated error will saturate the system

Solution: Set maximum and minimum values for the integral term

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

PID a1 28

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 ; • } • }

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

PID a1 29

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

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

PID a1 30

Summary

• Studies PID control theory and implementation


Recommended